Skip to content

Commit

Permalink
now eight can equip things again
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed May 13, 2024
1 parent 0c26ed0 commit bbd7ae0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"build": "next build && next export",
"start": "next start",
"lint": "next lint",
"generate": "graphql-codegen --config codegen.yml -r dotenv/config"
"generate": "graphql-codegen --config codegen.yml -r dotenv/config",
"ts": "tsc --noEmit --incremental"
},
"dependencies": {
"@apollo/client": "^3.5.9",
Expand Down
25 changes: 24 additions & 1 deletion src/game/inventory/equipment-slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,32 @@ export function EquipmentSlot({
},
) as InventoryItem[];

// make sure equipped item is standalone
const equippedItem = items.find((item) => item.id === equipped);
if (equippedItem && !uniqueItems.find((item) => item.id === equipped)) {
uniqueItems.push(equippedItem);
quantityMap[itemDisplayName(equippedItem)] -= 1;
}
// check if item is equipped in another slot and duplicate those
otherEquippedItems.forEach((id) => {
const otherEquippedItem = uniqueItems.find((item) => item.id === id);
if (otherEquippedItem) {
const name = itemDisplayName(otherEquippedItem);
if (quantityMap[name] > 1) {
// there's more than one of this item but the one in the unique item list is already equipped
// find an unequipped one
const unequippedItem = items.find(
(item) => itemDisplayName(item) === name && item.id !== id,
);
if (unequippedItem) {
uniqueItems.push(unequippedItem);
quantityMap[name] -= 1;
}
}
}
});

uniqueItems.sort(itemSorter);

return (
<React.Fragment>
Expand Down Expand Up @@ -159,7 +181,8 @@ export function EquipmentSlot({
) : (
<>
{itemDisplayName(inventoryItem)}
{quantityMap[itemDisplayName(inventoryItem)] > 1
{quantityMap[itemDisplayName(inventoryItem)] > 1 &&
otherEquippedItems.indexOf(inventoryItem.id) === -1
? ` x${quantityMap[itemDisplayName(inventoryItem)]}`
: ""}
</>
Expand Down

0 comments on commit bbd7ae0

Please sign in to comment.