76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
|
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { applyAction } from '../simulation';
|
|
import type { World, CombatantActor, Action, EntityId } from '../../../core/types';
|
|
import { TileType } from '../../../core/terrain';
|
|
import { GAME_CONFIG } from '../../../core/config/GameConfig';
|
|
import { EntityAccessor } from '../../EntityAccessor';
|
|
import { ECSWorld } from '../../ecs/World';
|
|
|
|
describe('Movement Blocking Behavior', () => {
|
|
let world: World;
|
|
let player: CombatantActor;
|
|
let accessor: EntityAccessor;
|
|
let ecsWorld: ECSWorld;
|
|
|
|
beforeEach(() => {
|
|
// minimalist world setup
|
|
world = {
|
|
width: 3,
|
|
height: 3,
|
|
tiles: new Array(9).fill(TileType.GRASS),
|
|
exit: { x: 2, y: 2 },
|
|
trackPath: []
|
|
};
|
|
|
|
// Blocking wall at (1, 0)
|
|
world.tiles[1] = TileType.WALL;
|
|
|
|
player = {
|
|
id: 1 as EntityId,
|
|
type: 'player',
|
|
category: 'combatant',
|
|
isPlayer: true,
|
|
pos: { x: 0, y: 0 },
|
|
speed: 100,
|
|
energy: 0,
|
|
stats: { ...GAME_CONFIG.player.initialStats }
|
|
};
|
|
|
|
ecsWorld = new ECSWorld();
|
|
ecsWorld.addComponent(player.id, "position", player.pos);
|
|
ecsWorld.addComponent(player.id, "stats", player.stats);
|
|
ecsWorld.addComponent(player.id, "actorType", { type: player.type });
|
|
ecsWorld.addComponent(player.id, "player", {});
|
|
ecsWorld.addComponent(player.id, "energy", { current: player.energy, speed: player.speed });
|
|
|
|
accessor = new EntityAccessor(world, player.id, ecsWorld);
|
|
});
|
|
|
|
it('should return move-blocked event when moving into a wall', () => {
|
|
const action: Action = { type: 'move', dx: 1, dy: 0 }; // Try to move right into wall at (1,0)
|
|
const events = applyAction(world, player.id, action, accessor);
|
|
|
|
expect(events).toHaveLength(1);
|
|
expect(events[0]).toMatchObject({
|
|
type: 'move-blocked',
|
|
actorId: player.id,
|
|
x: 1,
|
|
y: 0
|
|
});
|
|
});
|
|
|
|
it('should return moved event when moving into empty space', () => {
|
|
const action: Action = { type: 'move', dx: 0, dy: 1 }; // Move down to (0,1) - valid
|
|
const events = applyAction(world, player.id, action, accessor);
|
|
|
|
expect(events).toHaveLength(1);
|
|
expect(events[0]).toMatchObject({
|
|
type: 'moved',
|
|
actorId: player.id,
|
|
from: { x: 0, y: 0 },
|
|
to: { x: 0, y: 1 }
|
|
});
|
|
});
|
|
});
|