A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Households reads this tick's Grid (Game.System.thisTick)
SandroMaglione653fbf519c91
diff --git a/src/sim/headless.ts b/src/sim/headless.tsindex 314e220..c3d2d98 100644--- a/src/sim/headless.ts+++ b/src/sim/headless.ts@@ -37,6 +37,8 @@ export const headless = (charter: CharterValue, options: { readonly toast?: (mes}const town = {ui,+ /** The runtime itself, for tools (devtools sessions, lints, replays) and type-level checks. */+ runtime,/** Runs the town on for `seconds` of game time. */run: (seconds: number) => {for (let i = 0; i < Math.round(seconds / STEP_SECONDS); i++) step()diff --git a/src/sim/town.ts b/src/sim/town.tsindex d66aa0f..642f19f 100644--- a/src/sim/town.ts+++ b/src/sim/town.ts@@ -41,7 +41,7 @@ export const Households = Game.System(stores: Game.Query({ selection: { inventory: Game.Query.write(Inventory) }, with: [Storage], without: [Site, Rising] })},resources: {- grid: Game.System.readResource(Grid),+ grid: Game.System.thisTick(Game.System.readResource(Grid)),mood: Game.System.readResource(Mood),appeal: Game.System.readResource(Appeal),time: Game.System.readResource(Time),diff --git a/test/this-tick.test.ts b/test/this-tick.test.tsnew file mode 100644index 0000000..0ad768c--- /dev/null+++ b/test/this-tick.test.ts@@ -0,0 +1,26 @@+/**+ * `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/schema.ts"+import { headless } from "../src/sim/headless.ts"+import { Households } from "../src/sim/town.ts"+import { IndexGrid } from "../src/sim/work.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"))+})