From 5115d41a1f384117e9f1671330dbd4f37f644397 Mon Sep 17 00:00:00 2001 From: Chris Vickery Date: Mon, 6 May 2024 17:24:18 -0700 Subject: [PATCH] quantities in inventory, altar location type --- src/game/inventory/equipment-slot.tsx | 26 ++++++++++++++++++++++++-- src/game/inventory/quest-items.tsx | 26 ++++++++++++++++++++++++-- src/map-preview.tsx | 20 +++++++++++--------- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/game/inventory/equipment-slot.tsx b/src/game/inventory/equipment-slot.tsx index 0a9f864..be8653f 100644 --- a/src/game/inventory/equipment-slot.tsx +++ b/src/game/inventory/equipment-slot.tsx @@ -109,6 +109,23 @@ export function EquipmentSlot({ .filter((item) => canEquipTo(slot, item)) .sort(itemSorter); + const quantityMap: { [x in string]: number } = {}; + items.forEach((item) => { + const displayName = itemDisplayName(item); + if (quantityMap[displayName]) { + quantityMap[displayName] += 1; + } else { + quantityMap[displayName] = 1; + } + }); + + const uniqueItems: InventoryItem[] = Object.keys(quantityMap).map( + (displayName) => { + const item = items.find((i) => itemDisplayName(i) === displayName); + return item; + }, + ) as InventoryItem[]; + return (
@@ -125,7 +142,7 @@ export function EquipmentSlot({ onEquip(slot, e.target.value); }} > - {items.map((inventoryItem) => { + {uniqueItems.map((inventoryItem) => { return ( {itemDisplayName(inventoryItem)} ) : ( - itemDisplayName(inventoryItem) + <> + {itemDisplayName(inventoryItem)} + {quantityMap[itemDisplayName(inventoryItem)] > 1 + ? ` x${quantityMap[itemDisplayName(inventoryItem)]}` + : ""} + )} { + const displayName = itemDisplayName(item); + if (quantityMap[displayName]) { + quantityMap[displayName] += 1; + } else { + quantityMap[displayName] = 1; + } + }); + + const uniqueItems: InventoryItem[] = Object.keys(quantityMap).map( + (displayName) => { + const item = items.find((i) => itemDisplayName(i) === displayName); + return item; + }, + ) as InventoryItem[]; + return (
@@ -55,9 +72,14 @@ export function QuestItems({ } }} > - {items.map((inventoryItem) => ( + {uniqueItems.map((inventoryItem) => ( - {itemDisplayName(inventoryItem)} + <> + {itemDisplayName(inventoryItem)} + {quantityMap[itemDisplayName(inventoryItem)] > 1 + ? ` x${quantityMap[itemDisplayName(inventoryItem)]}` + : ""} + {getEnchantmentDisplay(inventoryItem.baseItem) !== "???" && ( sloc.x === x && sloc.y === y + (sloc) => sloc.x === x && sloc.y === y, ); function findTerrainType( @@ -84,7 +86,7 @@ function SpecialLocationEditor({ terrain: TerrainType, direction: number, maxMagnitude: number, - magnitude: number + magnitude: number, ) { const checkLocation = LocationData.default.locations[x][y]; console.log(x, y, checkLocation.terrain, terrain); @@ -181,14 +183,14 @@ function TerrainEditor({ function setTerrain( terrainX: number, terrainY: number, - terrain: TerrainType + terrain: TerrainType, ) { LocationData.default.locations[terrainX][terrainY].terrain = terrain; } function getNextTerrain(terrainX: number, terrainY: number): TerrainType { const nextTerrainIndex = (terrainTypes.indexOf( - LocationData.default.locations[terrainX][terrainY].terrain + LocationData.default.locations[terrainX][terrainY].terrain, ) + 1) % terrainTypes.length; @@ -202,7 +204,7 @@ function TerrainEditor({ terrainX: number, terrainY: number, terrain: TerrainType, - fillTerrain: TerrainType + fillTerrain: TerrainType, ) { if (terrainX >= 128 || terrainY >= 96 || terrainX < 0 || terrainY < 0) { return; @@ -229,7 +231,7 @@ function TerrainEditor({ x, y, nextTerrain, - LocationData.default.locations[x][y].terrain + LocationData.default.locations[x][y].terrain, ); rerender(); } else { @@ -285,7 +287,7 @@ export default function MapPreview(): JSX.Element { rerender={rerender} /> ); - }) + }), )}