Skip to content

Commit

Permalink
quantities in inventory, altar location type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed May 7, 2024
1 parent ee1ed7a commit 5115d41
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
26 changes: 24 additions & 2 deletions src/game/inventory/equipment-slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<React.Fragment>
<div>
Expand All @@ -125,7 +142,7 @@ export function EquipmentSlot({
onEquip(slot, e.target.value);
}}
>
{items.map((inventoryItem) => {
{uniqueItems.map((inventoryItem) => {
return (
<MenuItem
key={inventoryItem.id}
Expand All @@ -135,7 +152,12 @@ export function EquipmentSlot({
{inventoryItem.id === equipped ? (
<b>{itemDisplayName(inventoryItem)}</b>
) : (
itemDisplayName(inventoryItem)
<>
{itemDisplayName(inventoryItem)}
{quantityMap[itemDisplayName(inventoryItem)] > 1
? ` x${quantityMap[itemDisplayName(inventoryItem)]}`
: ""}
</>
)}
<Typography
variant="caption"
Expand Down
26 changes: 24 additions & 2 deletions src/game/inventory/quest-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ export function QuestItems({
}
}, [existingItem, value]);

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 (
<React.Fragment>
<div>
Expand All @@ -55,9 +72,14 @@ export function QuestItems({
}
}}
>
{items.map((inventoryItem) => (
{uniqueItems.map((inventoryItem) => (
<MenuItem key={inventoryItem.id} value={inventoryItem.id}>
{itemDisplayName(inventoryItem)}
<>
{itemDisplayName(inventoryItem)}
{quantityMap[itemDisplayName(inventoryItem)] > 1
? ` x${quantityMap[itemDisplayName(inventoryItem)]}`
: ""}
</>
{getEnchantmentDisplay(inventoryItem.baseItem) !== "???" && (
<Typography
variant="subtitle2"
Expand Down
20 changes: 11 additions & 9 deletions src/map-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import { Layout } from "src/components/layout";
import RawLocationData from "./location-data.json";

type TerrainType = "land" | "water" | "forbidden";
type MapNames = "default";
type MapNames = "default" | "void";
type SpecialLocationType =
| "dock"
| "quest"
| "city"
| "bridge"
| "tavern"
| "hermit";
| "hermit"
| "altar"
| "fortress";

type LocationData = {
terrain: TerrainType;
Expand Down Expand Up @@ -75,7 +77,7 @@ function SpecialLocationEditor({
}): JSX.Element {
const location = LocationData.default.locations[x][y];
const specialLocation = LocationData.default.specialLocations.find(
(sloc) => sloc.x === x && sloc.y === y
(sloc) => sloc.x === x && sloc.y === y,
);

function findTerrainType(
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -229,7 +231,7 @@ function TerrainEditor({
x,
y,
nextTerrain,
LocationData.default.locations[x][y].terrain
LocationData.default.locations[x][y].terrain,
);
rerender();
} else {
Expand Down Expand Up @@ -285,7 +287,7 @@ export default function MapPreview(): JSX.Element {
rerender={rerender}
/>
);
})
}),
)}
</NoSsr>
</div>
Expand Down

0 comments on commit 5115d41

Please sign in to comment.