Skip to content

Commit

Permalink
Merge pull request #9040 from DestinyItemManager/plumb-item-data
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis authored Jan 30, 2023
2 parents 98f34e7 + 138076b commit e8b1a88
Show file tree
Hide file tree
Showing 31 changed files with 347 additions and 468 deletions.
20 changes: 10 additions & 10 deletions src/app/armory/Armory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand All @@ -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);

Expand Down Expand Up @@ -208,7 +208,7 @@ export default function Armory({
{itemDef.setData?.itemList && (
<ol>
{itemDef.setData.itemList.map((h) => {
const stepItem = makeFakeItem(defs, buckets, undefined, h.itemHash);
const stepItem = makeFakeItem(createItemContext, h.itemHash);
return (
stepItem && (
<li
Expand Down
48 changes: 24 additions & 24 deletions src/app/compare/Compare.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BungieImage from 'app/dim-ui/BungieImage';
import { t } from 'app/i18next-t';
import { locateItem } from 'app/inventory/locate-item';
import { createItemContextSelector } from 'app/inventory/selectors';
import {
applySocketOverrides,
useSocketOverridesForItems,
Expand Down Expand Up @@ -66,6 +67,7 @@ export default function Compare({ session }: { session: CompareSession }) {
const defs = useD2Definitions()!;
const [compareBaseStats, setCompareBaseStats] = useSetting('compareBaseStats');
const [assumeWeaponMasterwork, setAssumeWeaponMasterwork] = useSetting('compareWeaponMasterwork');
const createItemContext = useSelector(createItemContextSelector);
const rawCompareItems = useSelector(compareItemsSelector(session.vendorCharacterId));
const organizerLink = useSelector(compareOrganizerLinkSelector);

Expand All @@ -84,35 +86,33 @@ export default function Compare({ session }: { session: CompareSession }) {
// Produce new items which have had their sockets changed
const compareItems = useMemo(() => {
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());
Expand Down
8 changes: 4 additions & 4 deletions src/app/destiny1/loadout-drawer/D1LoadoutDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions src/app/inventory/actions.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}>();

/*
Expand Down
10 changes: 4 additions & 6 deletions src/app/inventory/advanced-write-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
})
);
};
Expand Down
Loading

0 comments on commit e8b1a88

Please # to comment.