diff --git a/engine/Scene.ts b/engine/Scene.ts index 049cb12..58c4d30 100644 --- a/engine/Scene.ts +++ b/engine/Scene.ts @@ -1,10 +1,10 @@ -import { box } from "#/engine/Box.ts"; import { type Process as EntityProcess, entityBlueprintMap, entityProcessMap, } from "#/engine/Entity.ts"; import { type Graph, getNeighbours } from "#/engine/Graph.ts"; +import { box } from "#/engine/lib/box"; import { type Cache, memoize } from "#/engine/lib/cache.ts"; import MapArray from "#/engine/lib/MapArray.ts"; diff --git a/engine/lib/MapArray.test.ts b/engine/lib/MapArray.test.ts new file mode 100644 index 0000000..238390a --- /dev/null +++ b/engine/lib/MapArray.test.ts @@ -0,0 +1,27 @@ +import { expect, test } from "vitest"; +import { box } from "./box.ts"; +import MapArray from "./MapArray.ts"; + +test("MapArray", () => { + const mapArray = new MapArray([ + ["a", box(1)], + ["b", box(2)], + ["c", box(3)], + ]); + mapArray.set("foo", box(42)); + mapArray.set("bar", box(0)); + mapArray.delete("bar"); + + expect(mapArray.get("foo")!.value).toBe(42); + expect(mapArray.get("bar")).toBe(undefined); + expect(mapArray.map.size).toBe(mapArray.array.length); + expect( + mapArray.entries().reduce( + (a, c) => { + a[1].value = a[1].value + c[1].value; + return a; + }, + ["_", box(0)], + )[1].value, + ).toBe(48); +}); diff --git a/engine/lib/MapArray.ts b/engine/lib/MapArray.ts index d848e37..633b9a2 100644 --- a/engine/lib/MapArray.ts +++ b/engine/lib/MapArray.ts @@ -1,4 +1,4 @@ -import type { Box } from "#/engine/Box.ts"; +import type { Box } from "./box.ts"; export default class MapArray { map: Map>; diff --git a/engine/lib/box.test.ts b/engine/lib/box.test.ts new file mode 100644 index 0000000..9fb4339 --- /dev/null +++ b/engine/lib/box.test.ts @@ -0,0 +1,7 @@ +import { expect, test } from "vitest"; +import { type Box, box } from "./box.ts"; + +test("box", () => { + const b: Box = box(42); + expect(b).toEqual({ value: 42 }); +}); diff --git a/engine/Box.ts b/engine/lib/box.ts similarity index 100% rename from engine/Box.ts rename to engine/lib/box.ts diff --git a/engine/system/drawSprites.ts b/engine/system/drawSprites.ts index c1dba60..f42b353 100644 --- a/engine/system/drawSprites.ts +++ b/engine/system/drawSprites.ts @@ -1,4 +1,4 @@ -import type { Box } from "#/engine/Box.ts"; +import type { Box } from "#/engine/lib/box"; import { sceneChangeSet, sceneComponentsMap } from "#/engine/Scene.ts"; import { drawSprite, type Sprite, spriteSheetMap } from "#/engine/Sprite.ts"; import type { Vector } from "#/engine/Vector.ts";