feat(slay-the-spire-like): add getItemEffects to grid inventory

This commit is contained in:
hypercross 2026-04-21 23:15:02 +08:00
parent d1605a9ee3
commit 0547180074
1 changed files with 37 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import { EffectData } from "../types";
import type { ParsedShape } from "../utils/parse-shape"; import type { ParsedShape } from "../utils/parse-shape";
import type { Transform2D } from "../utils/shape-collision"; import type { Transform2D } from "../utils/shape-collision";
import { import {
@ -10,6 +11,7 @@ import {
} from "../utils/shape-collision"; } from "../utils/shape-collision";
import type { import type {
CellKey, CellKey,
GameItemMeta,
GridInventory, GridInventory,
InventoryItem, InventoryItem,
MutationResult, MutationResult,
@ -255,3 +257,38 @@ export function getAdjacentItems<TMeta>(
return adjacent; return adjacent;
} }
// export type EffectTable = Record<string, { data: EffectData; stacks: number }>;
export function getItemEffects(
inv: GridInventory<GameItemMeta>,
lookup: EffectData[],
) {
const effects = {} as Record<
string,
Record<string, { data: EffectData; stacks: number }>
>;
for (const item of inv.items.values()) {
if (!item.meta) continue;
const { startEffects } = item.meta;
if (!startEffects) continue;
const table = (effects[item.id] = {} as Record<
string,
{
data: EffectData;
stacks: number;
}
>);
for (const [id, stacks] of Object.entries(startEffects)) {
const data = lookup.find((row) => row.id === id);
if (!data) continue;
table[id] = {
data,
stacks,
};
}
}
return effects;
}