|
1 | 1 | import { D2ManifestDefinitions } from 'app/destiny2/d2-definitions'; |
2 | 2 | import { ItemCreationContext } from 'app/inventory/store/d2-item-factory'; |
3 | | -import { VENDORS } from 'app/search/d2-known-values'; |
| 3 | +import { VENDORS, silverItemHash } from 'app/search/d2-known-values'; |
4 | 4 | import { ItemFilter } from 'app/search/filter-types'; |
5 | 5 | import { compareBy } from 'app/utils/comparators'; |
6 | 6 | import { filterMap } from 'app/utils/util'; |
@@ -189,46 +189,64 @@ function getVendorItems( |
189 | 189 | } |
190 | 190 | } |
191 | 191 |
|
192 | | -export function filterVendorGroupsToUnacquired( |
| 192 | +function filterVendorGroups( |
193 | 193 | vendorGroups: readonly D2VendorGroup[], |
194 | | - ownedItemHashes: Set<number> |
| 194 | + predicate: (item: VendorItem, vendor: D2Vendor) => boolean | null | undefined |
195 | 195 | ) { |
196 | 196 | return vendorGroups |
197 | 197 | .map((group) => ({ |
198 | 198 | ...group, |
199 | 199 | vendors: group.vendors |
200 | 200 | .map((vendor) => ({ |
201 | 201 | ...vendor, |
202 | | - items: vendor.items.filter( |
203 | | - ({ item, collectibleState }) => |
204 | | - item && |
205 | | - (collectibleState !== undefined |
206 | | - ? collectibleState & DestinyCollectibleState.NotAcquired |
207 | | - : item.itemCategoryHashes.includes(ItemCategoryHashes.Mods_Mod) && |
208 | | - !ownedItemHashes.has(item.hash)) |
209 | | - ), |
| 202 | + items: vendor.items.filter((item) => predicate(item, vendor)), |
210 | 203 | })) |
211 | 204 | .filter((v) => v.items.length), |
212 | 205 | })) |
213 | 206 | .filter((g) => g.vendors.length); |
214 | 207 | } |
215 | 208 |
|
| 209 | +export function filterVendorGroupsToUnacquired( |
| 210 | + vendorGroups: readonly D2VendorGroup[], |
| 211 | + ownedItemHashes: Set<number> |
| 212 | +) { |
| 213 | + return filterVendorGroups( |
| 214 | + vendorGroups, |
| 215 | + ({ item, collectibleState }) => |
| 216 | + item && |
| 217 | + (collectibleState !== undefined |
| 218 | + ? (collectibleState & DestinyCollectibleState.NotAcquired) !== 0 |
| 219 | + : item.itemCategoryHashes.includes(ItemCategoryHashes.Mods_Mod) && |
| 220 | + !ownedItemHashes.has(item.hash)) |
| 221 | + ); |
| 222 | +} |
| 223 | + |
| 224 | +export function filterVendorGroupsToNoSilver(vendorGroups: readonly D2VendorGroup[]) { |
| 225 | + return filterVendorGroups(vendorGroups, ({ costs, displayCategoryIndex }, vendor) => { |
| 226 | + if (costs.some((c) => c.itemHash === silverItemHash)) { |
| 227 | + return false; |
| 228 | + } |
| 229 | + const categoryIdentifier = |
| 230 | + displayCategoryIndex !== undefined && |
| 231 | + displayCategoryIndex >= 0 && |
| 232 | + vendor.def.displayCategories[displayCategoryIndex].identifier; |
| 233 | + return !( |
| 234 | + categoryIdentifier && |
| 235 | + (categoryIdentifier.startsWith('categories.campaigns') || |
| 236 | + categoryIdentifier.startsWith('categories.featured.carousel')) |
| 237 | + ); |
| 238 | + }); |
| 239 | +} |
| 240 | + |
216 | 241 | export function filterVendorGroupsToSearch( |
217 | 242 | vendorGroups: readonly D2VendorGroup[], |
218 | 243 | searchQuery: string, |
219 | 244 | filterItems: ItemFilter |
220 | 245 | ) { |
221 | | - return vendorGroups |
222 | | - .map((group) => ({ |
223 | | - ...group, |
224 | | - vendors: group.vendors |
225 | | - .map((vendor) => ({ |
226 | | - ...vendor, |
227 | | - items: vendor.def.displayProperties.name.toLowerCase().includes(searchQuery.toLowerCase()) |
228 | | - ? vendor.items |
229 | | - : vendor.items.filter(({ item }) => item && filterItems(item)), |
230 | | - })) |
231 | | - .filter((v) => v.items.length), |
232 | | - })) |
233 | | - .filter((g) => g.vendors.length); |
| 246 | + return filterVendorGroups( |
| 247 | + vendorGroups, |
| 248 | + ({ item }, vendor) => |
| 249 | + vendor.def.displayProperties.name.toLowerCase().includes(searchQuery.toLowerCase()) || |
| 250 | + (item && filterItems(item)) |
| 251 | + ); |
234 | 252 | } |
0 commit comments