@flare-engine/testing 0.4.13 → 0.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,7 +55,7 @@ In-app bench harnesses — a scenario runner that ships in app code, its done-la
55
55
 
56
56
  An app that does want the seeded session at runtime may list `@flare-engine/testing` as a regular `dependency` instead of a `devDependency`. Its own dependencies are the `@flare-engine/*` runtime packages `assets`, `core`, `ecs`, `input`, `math` and `render` only, with no peer dependencies, so nothing outside the engine enters the bundle.
57
57
 
58
- See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-enginetesting--4kb-raw).
58
+ See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-enginetesting).
59
59
 
60
60
  ## License
61
61
 
package/dist/index.js CHANGED
@@ -205,10 +205,10 @@ function singletonQuery(world, def) {
205
205
  byComponent = /* @__PURE__ */ new Map();
206
206
  singletonQueries.set(world, byComponent);
207
207
  }
208
- let q = byComponent.get(def.id);
208
+ let q = byComponent.get(def);
209
209
  if (q === void 0) {
210
210
  q = world.query(def);
211
- byComponent.set(def.id, q);
211
+ byComponent.set(def, q);
212
212
  }
213
213
  return q;
214
214
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["SeededRNG","InputManager","World","GameLoop","Camera2D","AssetManager"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n","import { type AssetLoader, AssetManager, type SpriteSheet } from '@flare-engine/assets';\nimport { Camera2D } from '@flare-engine/render';\nimport { createMockInputManager, type MockInputManager } from './mock-input.js';\nimport { type CreateTestWorldOptions, createTestWorld, type TestWorld } from './test-world.js';\n\nexport interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {\n /**\n * Viewport width in pixels, forwarded to `camera.setViewport`. Must be given\n * together with `viewportHeight`; one without the other throws a\n * `RangeError`. Omitting both leaves the camera at its `new Camera2D()`\n * default of a 0×0 viewport.\n */\n viewportWidth?: number;\n /** Viewport height in pixels. See `viewportWidth`. */\n viewportHeight?: number;\n /**\n * Value exposed as `scenes` on the context, passed through untouched. The\n * real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`\n * is tier 3 and this package is tier 2.5, so the caller builds it (or any\n * stand-in) and hands it over here.\n */\n scenes?: S;\n}\n\nexport interface HeadlessContext<S = undefined> extends TestWorld {\n /** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */\n readonly camera: Camera2D;\n /** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */\n readonly input: MockInputManager;\n /** Real `AssetManager` with a loader that resolves `null` for every entry. */\n readonly assets: AssetManager;\n /**\n * Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`\n * whose `get` always returns `0` and `has` always returns `true`, so\n * `getFrame(sheet, anyName)` resolves to that frame.\n */\n readonly sheet: SpriteSheet;\n /** Whatever `options.scenes` was; `undefined` when omitted. */\n readonly scenes: S;\n}\n\nconst noopLoader: AssetLoader = () => Promise.resolve(null);\n\nfunction createPermissiveSheet(): SpriteSheet {\n const frameMap = new Map<string, number>();\n frameMap.get = () => 0;\n frameMap.has = () => true;\n return {\n frames: [{ name: 'headless', x: 0, y: 0, w: 8, h: 8 }],\n frameMap,\n animations: new Map(),\n };\n}\n\n/**\n * Build a headless stand-in for the React `GameContextValue` for loop-harness\n * tests. It is `createTestWorld(options)` plus the same `camera`, `input` and\n * `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are\n * omitted — they need a platform), a permissive `sheet`, and a caller-supplied\n * `scenes` slot. Nothing here imports React Native or Skia.\n *\n * Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs\n * `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves\n * `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once\n * frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the\n * test world's own.\n */\nexport function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;\nexport function createHeadlessContext<S>(\n options: CreateHeadlessContextOptions<S> & { scenes: S },\n): HeadlessContext<S>;\nexport function createHeadlessContext(\n options: CreateHeadlessContextOptions<unknown> = {},\n): HeadlessContext<unknown> {\n const { viewportWidth, viewportHeight } = options;\n if ((viewportWidth === undefined) !== (viewportHeight === undefined)) {\n throw new RangeError(\n '[@flare-engine/testing] viewportWidth and viewportHeight must be given together',\n );\n }\n\n const testWorld = createTestWorld({ fixedDt: options.fixedDt, maxDt: options.maxDt });\n const camera = new Camera2D();\n if (viewportWidth !== undefined && viewportHeight !== undefined) {\n camera.setViewport(viewportWidth, viewportHeight);\n }\n const input = createMockInputManager();\n const assets = new AssetManager(noopLoader);\n\n testWorld.loop.onLateUpdate.add((dt) => {\n camera.update(dt);\n input.update();\n });\n\n return {\n ...testWorld,\n camera,\n input,\n assets,\n sheet: createPermissiveSheet(),\n scenes: options.scenes,\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<number, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def.id);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def.id, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAgB,mB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,EAAE,GAAG,OAAO;EAErC,OAAO;CACT;CACA,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,KAAK;EACX,MAAM,KAAK;EACX,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;EACpC,KAAK,MAAM,KAAK,IAAI;GAClB,IAAI,CAAC,OAAO,OAAO,IAAI,CAAC,GAAG,OAAO;GAClC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,OAAO;EACvC;EACA,OAAO;CACT;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"index.js","names":["SeededRNG","InputManager","World","GameLoop","Camera2D","AssetManager"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n","import { type AssetLoader, AssetManager, type SpriteSheet } from '@flare-engine/assets';\nimport { Camera2D } from '@flare-engine/render';\nimport { createMockInputManager, type MockInputManager } from './mock-input.js';\nimport { type CreateTestWorldOptions, createTestWorld, type TestWorld } from './test-world.js';\n\nexport interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {\n /**\n * Viewport width in pixels, forwarded to `camera.setViewport`. Must be given\n * together with `viewportHeight`; one without the other throws a\n * `RangeError`. Omitting both leaves the camera at its `new Camera2D()`\n * default of a 0×0 viewport.\n */\n viewportWidth?: number;\n /** Viewport height in pixels. See `viewportWidth`. */\n viewportHeight?: number;\n /**\n * Value exposed as `scenes` on the context, passed through untouched. The\n * real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`\n * is tier 3 and this package is tier 2.5, so the caller builds it (or any\n * stand-in) and hands it over here.\n */\n scenes?: S;\n}\n\nexport interface HeadlessContext<S = undefined> extends TestWorld {\n /** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */\n readonly camera: Camera2D;\n /** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */\n readonly input: MockInputManager;\n /** Real `AssetManager` with a loader that resolves `null` for every entry. */\n readonly assets: AssetManager;\n /**\n * Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`\n * whose `get` always returns `0` and `has` always returns `true`, so\n * `getFrame(sheet, anyName)` resolves to that frame.\n */\n readonly sheet: SpriteSheet;\n /** Whatever `options.scenes` was; `undefined` when omitted. */\n readonly scenes: S;\n}\n\nconst noopLoader: AssetLoader = () => Promise.resolve(null);\n\nfunction createPermissiveSheet(): SpriteSheet {\n const frameMap = new Map<string, number>();\n frameMap.get = () => 0;\n frameMap.has = () => true;\n return {\n frames: [{ name: 'headless', x: 0, y: 0, w: 8, h: 8 }],\n frameMap,\n animations: new Map(),\n };\n}\n\n/**\n * Build a headless stand-in for the React `GameContextValue` for loop-harness\n * tests. It is `createTestWorld(options)` plus the same `camera`, `input` and\n * `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are\n * omitted — they need a platform), a permissive `sheet`, and a caller-supplied\n * `scenes` slot. Nothing here imports React Native or Skia.\n *\n * Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs\n * `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves\n * `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once\n * frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the\n * test world's own.\n */\nexport function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;\nexport function createHeadlessContext<S>(\n options: CreateHeadlessContextOptions<S> & { scenes: S },\n): HeadlessContext<S>;\nexport function createHeadlessContext(\n options: CreateHeadlessContextOptions<unknown> = {},\n): HeadlessContext<unknown> {\n const { viewportWidth, viewportHeight } = options;\n if ((viewportWidth === undefined) !== (viewportHeight === undefined)) {\n throw new RangeError(\n '[@flare-engine/testing] viewportWidth and viewportHeight must be given together',\n );\n }\n\n const testWorld = createTestWorld({ fixedDt: options.fixedDt, maxDt: options.maxDt });\n const camera = new Camera2D();\n if (viewportWidth !== undefined && viewportHeight !== undefined) {\n camera.setViewport(viewportWidth, viewportHeight);\n }\n const input = createMockInputManager();\n const assets = new AssetManager(noopLoader);\n\n testWorld.loop.onLateUpdate.add((dt) => {\n camera.update(dt);\n input.update();\n });\n\n return {\n ...testWorld,\n camera,\n input,\n assets,\n sheet: createPermissiveSheet(),\n scenes: options.scenes,\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component definition), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<ComponentDef<unknown>, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAC/E,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,MAAM,IAAIA,mBAAAA,UAAU,IAAI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,CAAC;CAExC,IAAI,UAA+B;CACnC,MAAM,WAAW,IAAI,SAAe,QAAQ;EAC1C,UAAU;CACZ,CAAC;CAED,IAAI,eAAe;CAEnB,OAAO;EACL;EACA,QAAQ,MAAc,OAAsB;GAC1C,MAAM,QAAQ;EAChB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;CACT;CACA,OAAO;AACT"}
package/dist/index.mjs CHANGED
@@ -204,10 +204,10 @@ function singletonQuery(world, def) {
204
204
  byComponent = /* @__PURE__ */ new Map();
205
205
  singletonQueries.set(world, byComponent);
206
206
  }
207
- let q = byComponent.get(def.id);
207
+ let q = byComponent.get(def);
208
208
  if (q === void 0) {
209
209
  q = world.query(def);
210
- byComponent.set(def.id, q);
210
+ byComponent.set(def, q);
211
211
  }
212
212
  return q;
213
213
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n","import { type AssetLoader, AssetManager, type SpriteSheet } from '@flare-engine/assets';\nimport { Camera2D } from '@flare-engine/render';\nimport { createMockInputManager, type MockInputManager } from './mock-input.js';\nimport { type CreateTestWorldOptions, createTestWorld, type TestWorld } from './test-world.js';\n\nexport interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {\n /**\n * Viewport width in pixels, forwarded to `camera.setViewport`. Must be given\n * together with `viewportHeight`; one without the other throws a\n * `RangeError`. Omitting both leaves the camera at its `new Camera2D()`\n * default of a 0×0 viewport.\n */\n viewportWidth?: number;\n /** Viewport height in pixels. See `viewportWidth`. */\n viewportHeight?: number;\n /**\n * Value exposed as `scenes` on the context, passed through untouched. The\n * real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`\n * is tier 3 and this package is tier 2.5, so the caller builds it (or any\n * stand-in) and hands it over here.\n */\n scenes?: S;\n}\n\nexport interface HeadlessContext<S = undefined> extends TestWorld {\n /** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */\n readonly camera: Camera2D;\n /** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */\n readonly input: MockInputManager;\n /** Real `AssetManager` with a loader that resolves `null` for every entry. */\n readonly assets: AssetManager;\n /**\n * Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`\n * whose `get` always returns `0` and `has` always returns `true`, so\n * `getFrame(sheet, anyName)` resolves to that frame.\n */\n readonly sheet: SpriteSheet;\n /** Whatever `options.scenes` was; `undefined` when omitted. */\n readonly scenes: S;\n}\n\nconst noopLoader: AssetLoader = () => Promise.resolve(null);\n\nfunction createPermissiveSheet(): SpriteSheet {\n const frameMap = new Map<string, number>();\n frameMap.get = () => 0;\n frameMap.has = () => true;\n return {\n frames: [{ name: 'headless', x: 0, y: 0, w: 8, h: 8 }],\n frameMap,\n animations: new Map(),\n };\n}\n\n/**\n * Build a headless stand-in for the React `GameContextValue` for loop-harness\n * tests. It is `createTestWorld(options)` plus the same `camera`, `input` and\n * `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are\n * omitted — they need a platform), a permissive `sheet`, and a caller-supplied\n * `scenes` slot. Nothing here imports React Native or Skia.\n *\n * Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs\n * `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves\n * `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once\n * frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the\n * test world's own.\n */\nexport function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;\nexport function createHeadlessContext<S>(\n options: CreateHeadlessContextOptions<S> & { scenes: S },\n): HeadlessContext<S>;\nexport function createHeadlessContext(\n options: CreateHeadlessContextOptions<unknown> = {},\n): HeadlessContext<unknown> {\n const { viewportWidth, viewportHeight } = options;\n if ((viewportWidth === undefined) !== (viewportHeight === undefined)) {\n throw new RangeError(\n '[@flare-engine/testing] viewportWidth and viewportHeight must be given together',\n );\n }\n\n const testWorld = createTestWorld({ fixedDt: options.fixedDt, maxDt: options.maxDt });\n const camera = new Camera2D();\n if (viewportWidth !== undefined && viewportHeight !== undefined) {\n camera.setViewport(viewportWidth, viewportHeight);\n }\n const input = createMockInputManager();\n const assets = new AssetManager(noopLoader);\n\n testWorld.loop.onLateUpdate.add((dt) => {\n camera.update(dt);\n input.update();\n });\n\n return {\n ...testWorld,\n camera,\n input,\n assets,\n sheet: createPermissiveSheet(),\n scenes: options.scenes,\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<number, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def.id);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def.id, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAC/E,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,MAAM,IAAI,UAAU,IAAI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,CAAC;CAExC,IAAI,UAA+B;CACnC,MAAM,WAAW,IAAI,SAAe,QAAQ;EAC1C,UAAU;CACZ,CAAC;CAED,IAAI,eAAe;CAEnB,OAAO;EACL;EACA,QAAQ,MAAc,OAAsB;GAC1C,MAAM,QAAQ;EAChB;EACA,QAAQ,MAAuB;GAC7B,OAAO,MAAM,SAAS;EACxB;EACA,OAAa;GACX,IAAI,CAAC,cAAc;IACjB,eAAe;IACf,UAAU;GACZ;EACF;EACA;EACA,MAAY;GAGV,IAAI,KAAK,WAAW,SAClB,KAAK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C,KAAK,MAAM,OAAO,YAChB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,QAAQ,MAAM,IAAI,IAAI,GAAG;EAE7D,SAAS,KAAK;GAAE;GAAI,YAAY;EAAM,CAAC;CACzC;CACA,OAAO,EAAE,SAAS;AACpB;;;;;AAMA,SAAgB,eAAe,GAAkB,GAA2B;CAC1E,OAAO,UAAU,GAAG,CAAC;AACvB;AAEA,SAAS,UAAU,GAAY,GAAqB;CAClD,IAAI,OAAO,GAAG,GAAG,CAAC,GAAG,OAAO;CAC5B,IAAI,OAAO,MAAM,OAAO,GAAG,OAAO;CAClC,IAAI,MAAM,QAAQ,MAAM,MAAM,OAAO;CACrC,IAAI,MAAM,QAAQ,CAAC,GAAG;EACpB,IAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,OAAO;EACvD,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO;EAErC,OAAO;CACT;CACA,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,KAAK;EACX,MAAM,KAAK;EACX,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;EACpC,KAAK,MAAM,KAAK,IAAI;GAClB,IAAI,CAAC,OAAO,OAAO,IAAI,CAAC,GAAG,OAAO;GAClC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,OAAO;EACvC;EACA,OAAO;CACT;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n","import { type AssetLoader, AssetManager, type SpriteSheet } from '@flare-engine/assets';\nimport { Camera2D } from '@flare-engine/render';\nimport { createMockInputManager, type MockInputManager } from './mock-input.js';\nimport { type CreateTestWorldOptions, createTestWorld, type TestWorld } from './test-world.js';\n\nexport interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {\n /**\n * Viewport width in pixels, forwarded to `camera.setViewport`. Must be given\n * together with `viewportHeight`; one without the other throws a\n * `RangeError`. Omitting both leaves the camera at its `new Camera2D()`\n * default of a 0×0 viewport.\n */\n viewportWidth?: number;\n /** Viewport height in pixels. See `viewportWidth`. */\n viewportHeight?: number;\n /**\n * Value exposed as `scenes` on the context, passed through untouched. The\n * real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`\n * is tier 3 and this package is tier 2.5, so the caller builds it (or any\n * stand-in) and hands it over here.\n */\n scenes?: S;\n}\n\nexport interface HeadlessContext<S = undefined> extends TestWorld {\n /** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */\n readonly camera: Camera2D;\n /** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */\n readonly input: MockInputManager;\n /** Real `AssetManager` with a loader that resolves `null` for every entry. */\n readonly assets: AssetManager;\n /**\n * Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`\n * whose `get` always returns `0` and `has` always returns `true`, so\n * `getFrame(sheet, anyName)` resolves to that frame.\n */\n readonly sheet: SpriteSheet;\n /** Whatever `options.scenes` was; `undefined` when omitted. */\n readonly scenes: S;\n}\n\nconst noopLoader: AssetLoader = () => Promise.resolve(null);\n\nfunction createPermissiveSheet(): SpriteSheet {\n const frameMap = new Map<string, number>();\n frameMap.get = () => 0;\n frameMap.has = () => true;\n return {\n frames: [{ name: 'headless', x: 0, y: 0, w: 8, h: 8 }],\n frameMap,\n animations: new Map(),\n };\n}\n\n/**\n * Build a headless stand-in for the React `GameContextValue` for loop-harness\n * tests. It is `createTestWorld(options)` plus the same `camera`, `input` and\n * `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are\n * omitted — they need a platform), a permissive `sheet`, and a caller-supplied\n * `scenes` slot. Nothing here imports React Native or Skia.\n *\n * Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs\n * `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves\n * `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once\n * frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the\n * test world's own.\n */\nexport function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;\nexport function createHeadlessContext<S>(\n options: CreateHeadlessContextOptions<S> & { scenes: S },\n): HeadlessContext<S>;\nexport function createHeadlessContext(\n options: CreateHeadlessContextOptions<unknown> = {},\n): HeadlessContext<unknown> {\n const { viewportWidth, viewportHeight } = options;\n if ((viewportWidth === undefined) !== (viewportHeight === undefined)) {\n throw new RangeError(\n '[@flare-engine/testing] viewportWidth and viewportHeight must be given together',\n );\n }\n\n const testWorld = createTestWorld({ fixedDt: options.fixedDt, maxDt: options.maxDt });\n const camera = new Camera2D();\n if (viewportWidth !== undefined && viewportHeight !== undefined) {\n camera.setViewport(viewportWidth, viewportHeight);\n }\n const input = createMockInputManager();\n const assets = new AssetManager(noopLoader);\n\n testWorld.loop.onLateUpdate.add((dt) => {\n camera.update(dt);\n input.update();\n });\n\n return {\n ...testWorld,\n camera,\n input,\n assets,\n sheet: createPermissiveSheet(),\n scenes: options.scenes,\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component definition), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<ComponentDef<unknown>, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAC/E,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,MAAM,IAAI,UAAU,IAAI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,CAAC;CAExC,IAAI,UAA+B;CACnC,MAAM,WAAW,IAAI,SAAe,QAAQ;EAC1C,UAAU;CACZ,CAAC;CAED,IAAI,eAAe;CAEnB,OAAO;EACL;EACA,QAAQ,MAAc,OAAsB;GAC1C,MAAM,QAAQ;EAChB;EACA,QAAQ,MAAuB;GAC7B,OAAO,MAAM,SAAS;EACxB;EACA,OAAa;GACX,IAAI,CAAC,cAAc;IACjB,eAAe;IACf,UAAU;GACZ;EACF;EACA;EACA,MAAY;GAGV,IAAI,KAAK,WAAW,SAClB,KAAK,SAAS;QAEd,QAAQ,KACN,uLAEF;EAEJ;CACF;AACF;;AC1DA,SAAgB,eACd,QACmE;CAEnE,MAAM,wBAAQ,IAAI,QAAwB;CAC1C,MAAM,OAAO,OAAO,KAAK,MAAM;CAE/B,QAAQ,UAAiB;EACvB,IAAI,UAAU,MAAM,IAAI,KAAK;EAC7B,IAAI,YAAY,KAAA,GAAW;GACzB,UAAU,KAAK,KAAK,QAAQ;IAC1B,MAAM,YAAY,OAAO;IACzB,OAAO,MAAM,MAAM,GAAI,UAAU,KAAiC;GACpE,CAAC;GACD,MAAM,IAAI,OAAO,OAAO;EAC1B;EAEA,MAAM,SAA6C,CAAC;EACpD,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MA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MAAM,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,OAAO;EACvD,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO;EAErC,OAAO;CACT;CACA,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,KAAK;EACX,MAAM,KAAK;EACX,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;EACpC,KAAK,MAAM,KAAK,IAAI;GAClB,IAAI,CAAC,OAAO,OAAO,IAAI,CAAC,GAAG,OAAO;GAClC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,OAAO;EACvC;EACA,OAAO;CACT;CACA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/testing",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "Deterministic World factory, fake Clock, mock InputManager, and scene snapshot helpers",
5
5
  "keywords": ["flare-engine", "testing", "ecs", "fake-clock", "snapshot", "typescript"],
6
6
  "license": "Apache-2.0",
@@ -37,12 +37,12 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "dependencies": {
40
- "@flare-engine/assets": "^0.4.13",
41
- "@flare-engine/core": "^0.4.13",
42
- "@flare-engine/ecs": "^0.4.13",
43
- "@flare-engine/input": "^0.4.13",
44
- "@flare-engine/math": "^0.4.13",
45
- "@flare-engine/render": "^0.4.13"
40
+ "@flare-engine/assets": "^0.4.14",
41
+ "@flare-engine/core": "^0.4.14",
42
+ "@flare-engine/ecs": "^0.4.14",
43
+ "@flare-engine/input": "^0.4.14",
44
+ "@flare-engine/math": "^0.4.14",
45
+ "@flare-engine/render": "^0.4.14"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=20"