2026-01-02 00:08:54 +00:00
|
|
|
import { expect } from "@esm-bundle/chai";
|
|
|
|
|
import { GameLoop } from "../../../src/core/GameLoop.js";
|
|
|
|
|
import {
|
|
|
|
|
createGameLoopSetup,
|
|
|
|
|
cleanupGameLoop,
|
|
|
|
|
createRunData,
|
|
|
|
|
createMockGameStateManagerForCombat,
|
|
|
|
|
setupCombatUnits,
|
|
|
|
|
cleanupTurnSystem,
|
|
|
|
|
} from "./helpers.js";
|
|
|
|
|
|
2026-01-02 01:57:06 +00:00
|
|
|
describe("Core: GameLoop - Combat Movement Calculation", function () {
|
2026-01-02 00:08:54 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
|
|
let gameLoop;
|
|
|
|
|
let container;
|
|
|
|
|
let playerUnit;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
const setup = createGameLoopSetup();
|
|
|
|
|
gameLoop = setup.gameLoop;
|
|
|
|
|
container = setup.container;
|
|
|
|
|
|
|
|
|
|
if (gameLoop.turnSystemAbortController) {
|
|
|
|
|
gameLoop.turnSystemAbortController.abort();
|
|
|
|
|
}
|
|
|
|
|
gameLoop.stop();
|
|
|
|
|
if (
|
|
|
|
|
gameLoop.turnSystem &&
|
|
|
|
|
typeof gameLoop.turnSystem.reset === "function"
|
|
|
|
|
) {
|
|
|
|
|
gameLoop.turnSystem.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameLoop.init(container);
|
2026-01-02 01:57:06 +00:00
|
|
|
const mockGameStateManager = createMockGameStateManagerForCombat();
|
2026-01-02 00:08:54 +00:00
|
|
|
gameLoop.gameStateManager = mockGameStateManager;
|
|
|
|
|
|
|
|
|
|
const runData = createRunData({
|
|
|
|
|
squad: [{ id: "u1", classId: "CLASS_VANGUARD" }],
|
|
|
|
|
});
|
|
|
|
|
await gameLoop.startLevel(runData, { startAnimation: false });
|
|
|
|
|
|
|
|
|
|
gameLoop.updateCombatState = async () => Promise.resolve();
|
|
|
|
|
|
|
|
|
|
const units = setupCombatUnits(gameLoop);
|
|
|
|
|
playerUnit = units.playerUnit;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
|
gameLoop.clearMovementHighlights();
|
|
|
|
|
gameLoop.clearSpawnZoneHighlights();
|
|
|
|
|
cleanupTurnSystem(gameLoop);
|
|
|
|
|
cleanupGameLoop(gameLoop, container);
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-02 01:57:06 +00:00
|
|
|
it("CoA 8: should calculate reachable positions correctly", () => {
|
|
|
|
|
const reachable = gameLoop.movementSystem.getReachableTiles(playerUnit, 4);
|
2026-01-02 00:08:54 +00:00
|
|
|
|
2026-01-02 01:57:06 +00:00
|
|
|
expect(reachable).to.be.an("array");
|
|
|
|
|
expect(reachable.length).to.be.greaterThan(0);
|
2026-01-02 00:08:54 +00:00
|
|
|
|
2026-01-02 01:57:06 +00:00
|
|
|
reachable.forEach((pos) => {
|
|
|
|
|
expect(pos).to.have.property("x");
|
|
|
|
|
expect(pos).to.have.property("y");
|
|
|
|
|
expect(pos).to.have.property("z");
|
|
|
|
|
expect(gameLoop.grid.isValidBounds(pos)).to.be.true;
|
|
|
|
|
});
|
2026-01-02 00:08:54 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|