Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

1.3 KB
Raw Blame
/**
 * `Households` reads `Grid` with `Game.System.thisTick`: `IndexGrid`, its only
 * writer, must run before it in the same step, or a home whose road was just
 * removed keeps its residents a step too long. `simulate` compiles because it
 * does; this locks the check in.
 */
import assert from "node:assert/strict"
import { test } from "node:test"

import { Game } from "../src/game/schema.ts"
import { headless } from "../src/game/headless.ts"
import { Households } from "../src/game/systems/town/index.ts"
import { IndexGrid } from "../src/game/systems/work/index.ts"

test("a Grid writer placed after Households fails to compile and tryTick rejects it", () => {
  const town = headless({ size: "small", term: 45, land: "fair", seed: 7 })
  const misordered = Game.Schedule(Households, IndexGrid)
  // Never called: the compile error is the test.
  const compileTime = () =>
    // @ts-expect-error Town/Households needs Town/Grid from this tick, but its writer Town/IndexGrid runs after it
    town.runtime.tick(misordered)
  void compileTime
  const result = town.runtime.tryTick(misordered)
  assert.equal(result.ok, false)
  assert.ok(!result.ok && result.error.kind === "TickOrderViolation" && result.error.issues.some((issue) => issue.writer === "Town/IndexGrid"))
})