Half changes to switch to exit level, Ran out of credits, re added enemies

This commit is contained in:
2026-01-31 14:56:53 +11:00
parent f6fc057e4f
commit 4b50e341a7
21 changed files with 762 additions and 747 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { idx, inBounds, isWall, isBlocked, tryDestructTile, isPlayerOnExit } from '../world/world-logic';
import { idx, inBounds, isWall, isBlocked, tryDestructTile } from '../world/world-logic';
import { type World, type Tile } from '../../core/types';
import { TileType } from '../../core/terrain';
@@ -9,13 +9,14 @@ describe('World Utilities', () => {
width,
height,
tiles,
exit: { x: 0, y: 0 }
exit: { x: 0, y: 0 },
trackPath: []
});
describe('idx', () => {
it('should calculate correct index for 2D coordinates', () => {
const world = createTestWorld(10, 10, []);
expect(idx(world, 0, 0)).toBe(0);
expect(idx(world, 5, 0)).toBe(5);
expect(idx(world, 0, 1)).toBe(10);
@@ -26,7 +27,7 @@ describe('World Utilities', () => {
describe('inBounds', () => {
it('should return true for coordinates within bounds', () => {
const world = createTestWorld(10, 10, []);
expect(inBounds(world, 0, 0)).toBe(true);
expect(inBounds(world, 5, 5)).toBe(true);
expect(inBounds(world, 9, 9)).toBe(true);
@@ -34,7 +35,7 @@ describe('World Utilities', () => {
it('should return false for coordinates outside bounds', () => {
const world = createTestWorld(10, 10, []);
expect(inBounds(world, -1, 0)).toBe(false);
expect(inBounds(world, 0, -1)).toBe(false);
expect(inBounds(world, 10, 0)).toBe(false);
@@ -49,9 +50,9 @@ describe('World Utilities', () => {
tiles[0] = TileType.WALL; // wall at 0,0
tiles[55] = TileType.WALL; // wall at 5,5
const world = createTestWorld(10, 10, tiles);
expect(isWall(world, 0, 0)).toBe(true);
expect(isWall(world, 5, 5)).toBe(true);
});
@@ -59,7 +60,7 @@ describe('World Utilities', () => {
it('should return false for floor tiles', () => {
const tiles: Tile[] = new Array(100).fill(TileType.EMPTY);
const world = createTestWorld(10, 10, tiles);
expect(isWall(world, 3, 3)).toBe(false);
expect(isWall(world, 7, 7)).toBe(false);
@@ -67,7 +68,7 @@ describe('World Utilities', () => {
it('should return false for out of bounds coordinates', () => {
const world = createTestWorld(10, 10, new Array(100).fill(0));
expect(isWall(world, -1, 0)).toBe(false);
expect(isWall(world, 10, 10)).toBe(false);
});
@@ -78,7 +79,7 @@ describe('World Utilities', () => {
const tiles: Tile[] = new Array(100).fill(TileType.EMPTY);
tiles[55] = TileType.WALL; // wall at 5,5
const world = createTestWorld(10, 10, tiles);
const mockAccessor = { getActorsAt: () => [] } as any;
@@ -88,19 +89,19 @@ describe('World Utilities', () => {
it('should return true for actor positions', () => {
const world = createTestWorld(10, 10, new Array(100).fill(0));
const mockAccessor = {
getActorsAt: (x: number, y: number) => {
if (x === 3 && y === 3) return [{ category: "combatant" }];
return [];
}
getActorsAt: (x: number, y: number) => {
if (x === 3 && y === 3) return [{ category: "combatant" }];
return [];
}
} as any;
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, mockAccessor)).toBe(false);
expect(isBlocked(world, 7, 7, mockAccessor)).toBe(false);
});
@@ -108,7 +109,7 @@ describe('World Utilities', () => {
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, mockAccessor)).toBe(true);
expect(isBlocked(world, 10, 10, mockAccessor)).toBe(true);
});
@@ -120,7 +121,7 @@ describe('World Utilities', () => {
const world = createTestWorld(10, 10, tiles);
const result = tryDestructTile(world, 0, 0);
expect(result).toBe(true);
expect(world.tiles[0]).toBe(TileType.GRASS_SAPLINGS);
});
@@ -131,49 +132,14 @@ describe('World Utilities', () => {
const world = createTestWorld(10, 10, tiles);
const result = tryDestructTile(world, 0, 0);
expect(result).toBe(false);
expect(world.tiles[0]).toBe(TileType.WALL);
});
it('should return false for out of bounds', () => {
const world = createTestWorld(10, 10, new Array(100).fill(TileType.EMPTY));
expect(tryDestructTile(world, -1, 0)).toBe(false);
});
});
describe('isPlayerOnExit', () => {
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 };
const mockAccessor = {
getPlayer: () => ({ pos: { x: 5, y: 5 } })
} as any;
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 };
const mockAccessor = {
getPlayer: () => ({ pos: { x: 4, y: 4 } })
} as any;
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 };
const mockAccessor = {
getPlayer: () => null
} as any;
expect(isPlayerOnExit(world, mockAccessor)).toBe(false);
expect(tryDestructTile(world, -1, 0)).toBe(false);
});
});
});