mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:40:46 +00:00
a8ec56b5a4
- Added TimelineController to manage timeline events and state. - Introduced TimelinePanel for user interaction with the timeline. - Implemented LruCache for efficient storage of timeline records. - Enhanced Transport and GameRenderer to support timeline features. - Updated various layers to respond to timeline events, ensuring synchronization with game state. - Added support for seeking and jumping within the timeline, improving user experience during gameplay. This commit lays the groundwork for a more interactive and responsive timeline feature in the game client.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { GameMapImpl } from "../src/core/game/GameMap";
|
|
|
|
describe("GameMapImpl mutable state", () => {
|
|
it("exports and imports mutable state losslessly", () => {
|
|
const w = 4;
|
|
const h = 3;
|
|
const terrain = new Uint8Array(w * h).fill(1 << 7); // mark as land
|
|
|
|
const map1 = new GameMapImpl(w, h, terrain, w * h);
|
|
const t0 = map1.ref(0, 0);
|
|
const t1 = map1.ref(1, 0);
|
|
const t2 = map1.ref(2, 0);
|
|
|
|
map1.setOwnerID(t0, 123);
|
|
map1.setFallout(t1, true);
|
|
map1.setDefenseBonus(t2, true);
|
|
|
|
const exported = map1.exportMutableState();
|
|
|
|
const map2 = new GameMapImpl(w, h, terrain, w * h);
|
|
map2.importMutableState(exported.state, exported.numTilesWithFallout);
|
|
|
|
expect(map2.ownerID(t0)).toBe(123);
|
|
expect(map2.hasFallout(t1)).toBe(true);
|
|
expect(map2.hasDefenseBonus(t2)).toBe(true);
|
|
expect(map2.numTilesWithFallout()).toBe(1);
|
|
});
|
|
|
|
it("resets mutable state", () => {
|
|
const w = 2;
|
|
const h = 2;
|
|
const terrain = new Uint8Array(w * h).fill(1 << 7);
|
|
const map = new GameMapImpl(w, h, terrain, w * h);
|
|
|
|
map.setOwnerID(map.ref(0, 0), 1);
|
|
map.setFallout(map.ref(1, 0), true);
|
|
expect(map.numTilesWithFallout()).toBe(1);
|
|
|
|
map.resetMutableState();
|
|
expect(map.ownerID(map.ref(0, 0))).toBe(0);
|
|
expect(map.hasFallout(map.ref(1, 0))).toBe(false);
|
|
expect(map.numTilesWithFallout()).toBe(0);
|
|
});
|
|
});
|