diff --git a/src/app/armory/Armory.tsx b/src/app/armory/Armory.tsx index 319c1b97fa..4c28fc72f7 100644 --- a/src/app/armory/Armory.tsx +++ b/src/app/armory/Armory.tsx @@ -6,7 +6,7 @@ import { DestinyTooltipText } from 'app/dim-ui/DestinyTooltipText'; import ElementIcon from 'app/dim-ui/ElementIcon'; import { t } from 'app/i18next-t'; import ItemIcon from 'app/inventory/ItemIcon'; -import { allItemsSelector, bucketsSelector } from 'app/inventory/selectors'; +import { allItemsSelector, createItemContextSelector } from 'app/inventory/selectors'; import { makeFakeItem } from 'app/inventory/store/d2-item-factory'; import { applySocketOverrides, @@ -51,14 +51,14 @@ export default function Armory({ }) { const dispatch = useThunkDispatch(); const defs = useD2Definitions()!; - const buckets = useSelector(bucketsSelector)!; const allItems = useSelector(allItemsSelector); const isPhonePortrait = useIsPhonePortrait(); const [socketOverrides, onPlugClicked] = useSocketOverrides(); + const createItemContext = useSelector(createItemContextSelector); const itemDef = defs.InventoryItem.get(itemHash); - const itemWithoutSockets = makeFakeItem(defs, buckets, undefined, itemHash); + const itemWithoutSockets = makeFakeItem(createItemContext, itemHash); if (!itemWithoutSockets) { return ( @@ -68,12 +68,12 @@ export default function Armory({ ); } - // We apply socket overrides *twice* - once to set the original sockets, then to apply the user's chosen overrides - const item = applySocketOverrides( - defs, - applySocketOverrides(defs, itemWithoutSockets, realItemSockets), - socketOverrides - ); + const item = applySocketOverrides(createItemContext, itemWithoutSockets, { + // Start with the item's current sockets + ...realItemSockets, + // Then apply whatever the user chose in the Armory UI + ...socketOverrides, + }); const storeItems = allItems.filter((i) => i.hash === itemHash); @@ -208,7 +208,7 @@ export default function Armory({ {itemDef.setData?.itemList && (
    {itemDef.setData.itemList.map((h) => { - const stepItem = makeFakeItem(defs, buckets, undefined, h.itemHash); + const stepItem = makeFakeItem(createItemContext, h.itemHash); return ( stepItem && (
  1. { let items = rawCompareItems; - if (defs) { - if (doAssumeWeaponMasterworks) { - items = items.map((i) => { - const y2MasterworkSocket = i.sockets?.allSockets.find( - (socket) => socket.socketDefinition.socketTypeHash === weaponMasterworkY2SocketTypeHash + if (doAssumeWeaponMasterworks) { + items = items.map((i) => { + const y2MasterworkSocket = i.sockets?.allSockets.find( + (socket) => socket.socketDefinition.socketTypeHash === weaponMasterworkY2SocketTypeHash + ); + const plugSet = y2MasterworkSocket?.plugSet; + const plugged = y2MasterworkSocket?.plugged; + if (plugSet && plugged) { + const fullMasterworkPlug = _.maxBy( + plugSet.plugs.filter( + (p) => p.plugDef.plug.plugCategoryHash === plugged.plugDef.plug.plugCategoryHash + ), + (plugOption) => plugOption.plugDef.investmentStats[0]?.value ); - const plugSet = y2MasterworkSocket?.plugSet; - const plugged = y2MasterworkSocket?.plugged; - if (plugSet && plugged) { - const fullMasterworkPlug = _.maxBy( - plugSet.plugs.filter( - (p) => p.plugDef.plug.plugCategoryHash === plugged.plugDef.plug.plugCategoryHash - ), - (plugOption) => plugOption.plugDef.investmentStats[0]?.value - ); - if (fullMasterworkPlug) { - return applySocketOverrides(defs, i, { - [y2MasterworkSocket.socketIndex]: fullMasterworkPlug.plugDef.hash, - }); - } + if (fullMasterworkPlug) { + return applySocketOverrides(createItemContext, i, { + [y2MasterworkSocket.socketIndex]: fullMasterworkPlug.plugDef.hash, + }); } - return i; - }); - } - items = items.map((i) => applySocketOverrides(defs, i, socketOverrides[i.id])); + } + return i; + }); } + items = items.map((i) => applySocketOverrides(createItemContext, i, socketOverrides[i.id])); return items; - }, [defs, doAssumeWeaponMasterworks, rawCompareItems, socketOverrides]); + }, [createItemContext, doAssumeWeaponMasterworks, rawCompareItems, socketOverrides]); const cancel = useCallback(() => { dispatch(endCompareSession()); diff --git a/src/app/destiny1/loadout-drawer/D1LoadoutDrawer.tsx b/src/app/destiny1/loadout-drawer/D1LoadoutDrawer.tsx index 8f5c3b3afb..94973a2b48 100644 --- a/src/app/destiny1/loadout-drawer/D1LoadoutDrawer.tsx +++ b/src/app/destiny1/loadout-drawer/D1LoadoutDrawer.tsx @@ -4,7 +4,7 @@ import Sheet from 'app/dim-ui/Sheet'; import { t } from 'app/i18next-t'; import { DimItem } from 'app/inventory/item-types'; import ItemIcon from 'app/inventory/ItemIcon'; -import { allItemsSelector, bucketsSelector } from 'app/inventory/selectors'; +import { allItemsSelector, createItemContextSelector } from 'app/inventory/selectors'; import { showItemPicker } from 'app/item-picker/item-picker'; import { deleteLoadout, updateLoadout } from 'app/loadout-drawer/actions'; import { @@ -57,16 +57,16 @@ export default function D1LoadoutDrawer({ const defs = useD1Definitions()!; const allItems = useSelector(allItemsSelector); - const buckets = useSelector(bucketsSelector)!; const [showingItemPicker, setShowingItemPicker] = useState(false); const [loadout, setLoadout] = useState(initialLoadout); + const createItemContext = useSelector(createItemContextSelector); const loadoutItems = loadout?.items; // Turn loadout items into real DimItems const [items, warnitems] = useMemo( - () => getItemsFromLoadoutItems(loadoutItems, defs, storeId, buckets, allItems), - [loadoutItems, defs, storeId, buckets, allItems] + () => getItemsFromLoadoutItems(createItemContext, loadoutItems, storeId, allItems), + [createItemContext, loadoutItems, storeId, allItems] ); const onAddItem = useCallback( diff --git a/src/app/inventory/actions.ts b/src/app/inventory/actions.ts index 4dd5c7ffd1..3a3856cea9 100644 --- a/src/app/inventory/actions.ts +++ b/src/app/inventory/actions.ts @@ -1,6 +1,5 @@ import { DestinyAccount } from 'app/accounts/destiny-account'; import { currentAccountSelector } from 'app/accounts/selectors'; -import { D2ManifestDefinitions } from 'app/destiny2/d2-definitions'; import { apiPermissionGrantedSelector } from 'app/dim-api/selectors'; import { t } from 'app/i18next-t'; import { showNotification } from 'app/notifications/notifications'; @@ -14,9 +13,9 @@ import { } from 'bungie-api-ts/destiny2'; import { createAction } from 'typesafe-actions'; import { TagCommand, TagValue } from './dim-item-info'; -import { InventoryBuckets } from './inventory-buckets'; import { DimItem } from './item-types'; import { AccountCurrency, DimCharacterStat, DimStore } from './store-types'; +import { CreateItemContext } from './store/d2-item-factory'; /** * Update the computed/massaged state of inventory, plus account-wide info like currencies. @@ -73,8 +72,7 @@ export const itemMoved = createAction('inventory/MOVE_ITEM')<{ export const awaItemChanged = createAction('inventory/AWA_CHANGE')<{ item: DimItem | null; changes: DestinyItemChangeResponse; - defs: D2ManifestDefinitions; - buckets: InventoryBuckets; + createItemContext: CreateItemContext; }>(); /* diff --git a/src/app/inventory/advanced-write-actions.ts b/src/app/inventory/advanced-write-actions.ts index cc2f754182..6449b82158 100644 --- a/src/app/inventory/advanced-write-actions.ts +++ b/src/app/inventory/advanced-write-actions.ts @@ -27,8 +27,8 @@ import { showNotification } from '../notifications/notifications'; import { awaItemChanged } from './actions'; import { DimItem, DimSocket } from './item-types'; import { + createItemContextSelector, currentStoreSelector, - d2BucketsSelector, profileResponseSelector, storesSelector, } from './selectors'; @@ -238,17 +238,15 @@ async function awaInsertSocketPlug( */ function refreshItemAfterAWA(changes: DestinyItemChangeResponse): ThunkResult { return async (dispatch, getState) => { - const defs = d2ManifestSelector(getState())!; - const buckets = d2BucketsSelector(getState())!; + const createItemContext = createItemContextSelector(getState()); const stores = storesSelector(getState()); - const newItem = makeItemSingle(defs, buckets, changes.item, stores); + const newItem = makeItemSingle(createItemContext, changes.item, stores); dispatch( awaItemChanged({ item: newItem, changes, - defs: d2ManifestSelector(getState())!, - buckets: d2BucketsSelector(getState())!, + createItemContext, }) ); }; diff --git a/src/app/inventory/d2-stores.ts b/src/app/inventory/d2-stores.ts index 266e51003e..74c3e762f8 100644 --- a/src/app/inventory/d2-stores.ts +++ b/src/app/inventory/d2-stores.ts @@ -5,6 +5,7 @@ import { DestinyAccount } from 'app/accounts/destiny-account'; import { getPlatforms } from 'app/accounts/platforms'; import { currentAccountSelector } from 'app/accounts/selectors'; import { loadClarity } from 'app/clarity/descriptions/loadDescriptions'; +import { settingSelector } from 'app/dim-api/selectors'; import { t } from 'app/i18next-t'; import { maxLightItemSet } from 'app/loadout-drawer/auto-loadouts'; import { d2ManifestSelector, manifestSelector } from 'app/manifest/selectors'; @@ -41,7 +42,6 @@ import { } from './actions'; import { ArtifactXP } from './ArtifactXP'; import { cleanInfos } from './dim-item-info'; -import { InventoryBuckets } from './inventory-buckets'; import { DimItem } from './item-types'; import { ItemPowerSet } from './ItemPowerSet'; import { d2BucketsSelector, storesLoadedSelector, storesSelector } from './selectors'; @@ -51,7 +51,7 @@ import { getCharacterStatsData as getD1CharacterStatsData, hasAffectingClassified, } from './store/character-utils'; -import { processItems } from './store/d2-item-factory'; +import { CreateItemContext, processItems } from './store/d2-item-factory'; import { getCharacterStatsData, makeCharacter, makeVault } from './store/d2-store-factory'; import { resetItemIndexGenerator } from './store/item-index'; import { getArtifactBonus } from './stores-helpers'; @@ -258,7 +258,7 @@ function loadStoresData(account: DestinyAccount): ThunkResult