Begin refactoring GameScene

This commit is contained in:
Peter Stockings
2026-01-26 15:30:14 +11:00
parent 1d7be54fd9
commit ef7d85750f
46 changed files with 2459 additions and 1291 deletions

View File

@@ -9,7 +9,6 @@ describe('World Utilities', () => {
width,
height,
tiles,
actors: new Map(),
exit: { x: 0, y: 0 }
});
@@ -81,38 +80,37 @@ describe('World Utilities', () => {
const world = createTestWorld(10, 10, tiles);
expect(isBlocked(world, 5, 5)).toBe(true);
const mockAccessor = { getActorsAt: () => [] } as any;
expect(isBlocked(world, 5, 5, mockAccessor)).toBe(true);
});
it('should return true for actor positions', () => {
const world = createTestWorld(10, 10, new Array(100).fill(0));
world.actors.set(1, {
id: 1,
category: "combatant",
isPlayer: true,
type: "player",
pos: { x: 3, y: 3 },
speed: 100,
stats: { hp: 10, maxHp: 10, attack: 1, defense: 0 } as any,
energy: 100
});
const mockAccessor = {
getActorsAt: (x: number, y: number) => {
if (x === 3 && y === 3) return [{ category: "combatant" }];
return [];
}
} as any;
expect(isBlocked(world, 3, 3)).toBe(true);
expect(isBlocked(world, 3, 3, mockAccessor)).toBe(true);
});
it('should return false for empty floor tiles', () => {
const world = createTestWorld(10, 10, new Array(100).fill(0));
const mockAccessor = { getActorsAt: () => [] } as any;
expect(isBlocked(world, 3, 3)).toBe(false);
expect(isBlocked(world, 7, 7)).toBe(false);
expect(isBlocked(world, 3, 3, mockAccessor)).toBe(false);
expect(isBlocked(world, 7, 7, mockAccessor)).toBe(false);
});
it('should return true for out of bounds', () => {
const world = createTestWorld(10, 10, new Array(100).fill(0));
const mockAccessor = { getActorsAt: () => [] } as any;
expect(isBlocked(world, -1, 0)).toBe(true);
expect(isBlocked(world, 10, 10)).toBe(true);
expect(isBlocked(world, -1, 0, mockAccessor)).toBe(true);
expect(isBlocked(world, 10, 10, mockAccessor)).toBe(true);
});
});
describe('tryDestructTile', () => {
@@ -148,32 +146,34 @@ describe('World Utilities', () => {
it('should return true when player is on exit', () => {
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
world.exit = { x: 5, y: 5 };
world.actors.set(1, {
id: 1,
pos: { x: 5, y: 5 },
isPlayer: true
} as any);
const mockAccessor = {
getPlayer: () => ({ pos: { x: 5, y: 5 } })
} as any;
expect(isPlayerOnExit(world, 1)).toBe(true);
expect(isPlayerOnExit(world, mockAccessor)).toBe(true);
});
it('should return false when player is not on exit', () => {
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
world.exit = { x: 5, y: 5 };
world.actors.set(1, {
id: 1,
pos: { x: 4, y: 4 },
isPlayer: true
} as any);
const mockAccessor = {
getPlayer: () => ({ pos: { x: 4, y: 4 } })
} as any;
expect(isPlayerOnExit(world, 1)).toBe(false);
expect(isPlayerOnExit(world, mockAccessor)).toBe(false);
});
it('should return false when player does not exist', () => {
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
world.exit = { x: 5, y: 5 };
expect(isPlayerOnExit(world, 999)).toBe(false);
const mockAccessor = {
getPlayer: () => null
} as any;
expect(isPlayerOnExit(world, mockAccessor)).toBe(false);
});
});
});