Skip to content

Commit

Permalink
Merge pull request #10840 from DestinyItemManager/vendor-wishlist
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis authored Dec 11, 2024
2 parents 7de69b5 + 7bf4765 commit 47b22fb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/app/inventory/item-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ export interface DimSockets {
allSockets: DimSocket[];
/** Sockets grouped by category. */
categories: DimSocketCategory[];
/** Were these built from definitions, or from live data? */
fromDefinitions: boolean;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/app/inventory/store/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function buildInstancedSockets(
itemDef.inventory?.bucketTypeHash === BucketHashes.Subclass
? categories.sort(compareBy((c) => c.category?.index))
: categories, // Sockets organized by category
fromDefinitions: false,
};
}

Expand Down Expand Up @@ -215,6 +216,7 @@ function buildDefinedSockets(
itemDef.inventory?.bucketTypeHash === BucketHashes.Subclass
? categories.sort(compareBy((c) => c.category?.index))
: categories, // Sockets organized by category
fromDefinitions: true,
};
}

Expand Down
13 changes: 10 additions & 3 deletions src/app/vendors/d2-vendors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ export function toVendor(
return undefined;
}

const vendorItems = getVendorItems(context, vendorDef, characterId, sales);
const vendorItems = getVendorItems(
context,
vendorDef,
characterId,
sales,
vendor?.nextRefreshDate,
);
vendorItems.sort(
chainComparator(
compareBy(
Expand Down Expand Up @@ -178,18 +184,19 @@ function getVendorItems(
[key: string]: DestinyVendorSaleItemComponent;
}
| undefined,
nextRefreshDate?: string,
): VendorItem[] {
if (sales) {
const components = Object.values(sales);
return components.map((component) =>
vendorItemForSaleItem(context, vendorDef, component, characterId),
vendorItemForSaleItem(context, vendorDef, component, characterId, nextRefreshDate),
);
} else if (vendorDef.returnWithVendorRequest) {
// If the sales should come from the server, don't show anything until we have them
return [];
} else {
return vendorDef.itemList.map((i, index) =>
vendorItemForDefinitionItem(context, i, characterId, index),
vendorItemForDefinitionItem(context, i, characterId, index, nextRefreshDate),
);
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/app/vendors/vendor-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function makeVendorItem(
characterId: string,
// the index in the vendor's items array
vendorItemIndex: number,
nextRefreshDate?: string,
): VendorItem {
const { defs, profileResponse } = context;

Expand Down Expand Up @@ -118,7 +119,7 @@ function makeVendorItem(

// override the DimItem.id for vendor items, so they are each unique enough to identify
// (otherwise they'd get their vendor index as an id, which is only unique per-vendor)
vendorItem.item.id = `${vendorHash}-${vendorItem.vendorItemIndex}`;
vendorItem.item.id = `${vendorHash}-${vendorItem.vendorItemIndex}-${nextRefreshDate ?? '0'}`;
vendorItem.item.index = vendorItem.item.id;
vendorItem.item.instanced = false;
// These would normally be false already, but certain rules like "finishers
Expand Down Expand Up @@ -156,6 +157,7 @@ export function vendorItemForSaleItem(
saleItem: DestinyVendorSaleItemComponent,
/** all DIM vendor calls are character-specific. any sale item should have an associated character. */
characterId: string,
nextRefreshDate?: string,
): VendorItem {
const vendorItemDef = vendorDef.itemList[saleItem.vendorItemIndex];
const failureStrings =
Expand All @@ -172,6 +174,7 @@ export function vendorItemForSaleItem(
saleItem,
characterId,
saleItem.vendorItemIndex,
nextRefreshDate,
);
}

Expand All @@ -185,6 +188,7 @@ export function vendorItemForDefinitionItem(
characterId: string,
// the index in the vendor's items array
vendorItemIndex: number,
nextRefreshDate?: string,
): VendorItem {
const item = makeVendorItem(
context,
Expand All @@ -195,12 +199,7 @@ export function vendorItemForDefinitionItem(
undefined,
characterId,
vendorItemIndex,
nextRefreshDate,
);
// items from vendors must have a unique ID, which causes makeItem
// to think there's gotta be socket info, but there's not for vendors
// set up statically through defs
if (item.item) {
item.item.missingSockets = false;
}
return item;
}
6 changes: 5 additions & 1 deletion src/app/wishlists/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const wishListFunctionSelector = createSelector(
// Cache of inventory item id to roll. For this to work, make sure vendor/collections rolls have unique ids.
const cache = new Map<string, InventoryWishListRoll | null>();
return (item: DimItem) => {
if (!($featureFlags.wishLists && wishlists && item.wishListEnabled)) {
if (
!($featureFlags.wishLists && wishlists && item.wishListEnabled) ||
!item.sockets ||
item.sockets.fromDefinitions
) {
return undefined;
}
const cachedRoll = cache.get(item.id);
Expand Down

0 comments on commit 47b22fb

Please sign in to comment.