test: refactor slay-the-spire-like combat tests

Update combat effect tests to use the new transform offset structure
and fix type mismatches in entity and inventory creation.
This commit is contained in:
hypercross 2026-04-20 11:37:18 +08:00
parent 90cb97e0ae
commit 88d31430a6
1 changed files with 7 additions and 14 deletions

View File

@ -40,14 +40,14 @@ function createRunContext(
return { return {
getItemData(id: string): ItemData | null { getItemData(id: string): ItemData | null {
const item = items.get(id); const item = items.get(id);
return item?.meta.itemData ?? null; return item?.meta?.itemData ?? null;
}, },
getNeighborItems(_id: string): Iterable<string> { getNeighborItems(_id: string): Iterable<string> {
return []; return [];
}, },
getConsumedUses(id: string): number { getConsumedUses(id: string): number {
const item = items.get(id); const item = items.get(id);
return item?.meta.consumedUses ?? 0; return item?.meta?.consumedUses ?? 0;
}, },
setConsumedUsesAsync(id: string, uses: number): Promise<void> { setConsumedUsesAsync(id: string, uses: number): Promise<void> {
const item = items.get(id); const item = items.get(id);
@ -94,9 +94,7 @@ function createItem(
id: itemId, id: itemId,
shape: { id: "1x1", cells: [{ x: 0, y: 0 }] } as unknown as ParsedShape, shape: { id: "1x1", cells: [{ x: 0, y: 0 }] } as unknown as ParsedShape,
transform: { transform: {
x: 0, offset: { x: 0, y: 0 },
y: 0,
rotation: 0,
flipX: false, flipX: false,
flipY: false, flipY: false,
} as unknown as Transform2D, } as unknown as Transform2D,
@ -123,13 +121,14 @@ function createInventory(
const occupied = new Set<CellKey>(); const occupied = new Set<CellKey>();
for (const item of items) { for (const item of items) {
map.set(item.id, item); map.set(item.id, item);
occupied.add(`${item.transform.x},${item.transform.y}`); occupied.add(`${item.transform.offset.x},${item.transform.offset.y}`);
} }
return { width: 6, height: 4, items: map, occupiedCells: occupied }; return { width: 6, height: 4, items: map, occupiedCells: occupied };
} }
function createCombatEntity(hp = 10, maxHp = 10): CombatEntity { function createCombatEntity(hp = 10, maxHp = 10): CombatEntity {
return { return {
id: "",
effects: {}, effects: {},
hp, hp,
maxHp, maxHp,
@ -159,9 +158,9 @@ function createEnemyEntity(id: string, hp = 10, maxHp = 10): EnemyEntity {
return { return {
...createCombatEntity(hp, maxHp), ...createCombatEntity(hp, maxHp),
id, id,
enemy: { id, name: id, description: "" }, enemy: { id, name: id, description: "", intents: null! },
intents: {}, intents: {},
currentIntentId: "", currentIntent: null!,
}; };
} }
@ -172,12 +171,6 @@ function createCombatState(
return { return {
player: createPlayerEntity(playerHp), player: createPlayerEntity(playerHp),
enemies, enemies,
inventory: {
width: 6,
height: 4,
items: new Map(),
occupiedCells: new Set(),
},
phase: "playerTurn", phase: "playerTurn",
turnNumber: 1, turnNumber: 1,
result: null, result: null,