Skip to content

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

Devtools: no monitor, Verify.acrossEngines, lint entry loads host schedules lazily

SandroMaglione547a374cba0f
diff --git a/PLAYTEST.md b/PLAYTEST.md
index c60eafb..cfccf6e 100644
--- a/PLAYTEST.md
+++ b/PLAYTEST.md
@@ -22,9 +22,9 @@ Open the address it prints (usually http://localhost:5173). Replays work in
Any of these saves the last minute of play:
-- **The button.** Press `\` (backslash) or the "◉ monitor" button in the
- corner to open the Ritmo monitor, then **Save replay**. Do it right after
- you see the problem: the replay holds the last 60 seconds before the press.
+- **The key.** Press `\` (backslash) anywhere on the page but in a text
+ field. Do it right after you see the problem: the replay holds the last 60
+ seconds before the press.
- **By itself, when a step fails.** If the simulation fails, a replay is
saved without you doing anything.
- **By itself, when a rule breaks.** The dev build checks rules after every
@@ -41,7 +41,7 @@ replay is saved.
In the terminal running `pnpm dev` you see a line like:
```
-[bevy-ts] replay saved: .replays/2026-10-17T12-04-09.512Z-tick-1412.json (1800 ticks): invariant fewer than ten buildings broke at tick 1412: ...
+[ritmo] replay saved: .replays/2026-10-17T12-04-09.512Z-tick-1412.json (1800 ticks): invariant fewer than ten buildings broke at tick 1412: ...
```
The file is in `.replays/` in this folder. It is ignored by git: it is a
@@ -64,7 +64,9 @@ steps that show it into a test, fixes it, and deletes the replay.
## For the agent
- `pnpm replay <file>`: replays it, compares the recorded checkpoints, replays
- twice for determinism, and prints the session report.
+ twice for determinism (`Verify.acrossEngines`), and prints the session report.
+ `pnpm exec ritmo-devtools verify src/game/headless.ts <file> --engines node,chromium`
+ plays it in a real browser too, for a bug only one engine shows.
- `pnpm replay <file> --journal <from>-<to>`: what happened in those ticks.
- `pnpm replay <file> --extract <from>-<to> <out.json>`: a small replay with
its own start, for building a test. Prefer an ordinary `headless` test when
diff --git a/scripts/replay.ts b/scripts/replay.ts
index a9d060e..86a61e5 100644
--- a/scripts/replay.ts
+++ b/scripts/replay.ts
@@ -11,7 +11,7 @@
*/
import { readFileSync, writeFileSync } from "node:fs"
-import { Replay } from "@typeonce/ritmo-devtools"
+import { Replay, Verify } from "@typeonce/ritmo-devtools"
import { replayTarget } from "../src/game/headless.ts"
@@ -54,8 +54,9 @@ if (flag === "--extract") {
console.log(opened.value.session.journal({ frames: [first, opened.value.session.frame()] }).text)
} else {
console.log(opened.value.play().text)
- const verified = Replay.verify(replayTarget, file)
- console.log(verified.ok ? verified.value.text : JSON.stringify(verified.error))
+ // Twice in this process and against the recording's checkpoints (`ritmo-devtools verify` adds browsers).
+ const verified = await Verify.acrossEngines(replayTarget, file)
+ console.log(verified.ok ? verified.value.text : verified.error.text)
console.log(opened.value.session.report().text)
}
}
diff --git a/src/app/devtools.ts b/src/app/devtools.ts
index db61aa2..8a8c566 100644
--- a/src/app/devtools.ts
+++ b/src/app/devtools.ts
@@ -1,19 +1,17 @@
/**
- * Dev builds only (`browser.ts` imports this behind `import.meta.env.DEV`): the
- * bevy-ts monitor, and a replay recorder that keeps the last minute of
- * `simulate` and saves it to `.replays/` (through the dev server, see
- * `vite.config.ts`) when a step fails, when an invariant breaks, or when the
- * monitor's "Save replay" button is pressed. See PLAYTEST.md.
+ * Dev builds only (`browser.ts` imports this behind `import.meta.env.DEV`): a
+ * replay recorder that keeps the last minute of `simulate` and saves it to
+ * `.replays/` (through the dev server, see `vite.config.ts`) when a step
+ * fails, when an invariant breaks, or when `\` (backslash) is pressed. The
+ * replay is debugged headless (`pnpm replay`). See PLAYTEST.md.
*/
import type { HostClock } from "@typeonce/ritmo"
-import { Invariant, Monitor, Replay } from "@typeonce/ritmo-devtools"
+import { Invariant, Replay } from "@typeonce/ritmo-devtools"
import * as ReplayViteSink from "@typeonce/ritmo-devtools/ReplayViteSink"
import { step } from "../game/content/index.ts"
import { Building, Game, Root, Treasury } from "../game/schema.ts"
import { simulate } from "../game/schedule.ts"
-import { draw } from "../render/three/schedule.ts"
-import { project } from "../view/schedule.ts"
/** The treasury holds a whole number of coins: a NaN or a fraction means some sum went wrong. */
export const CoinsAreWhole = Invariant.fromInspector(Game.Inspector("coins are whole", {
@@ -35,9 +33,7 @@ export const FewerThanTenBuildings = Invariant.fromInspector(Game.Inspector("few
}))
export interface DevtoolsHost {
- readonly runtime: Replay.Recordable<typeof Game.schema, typeof Root> & Monitor.Target<typeof Game.schema, typeof Root>
- /** Where the monitor's panel goes. */
- readonly mount: HTMLElement
+ readonly runtime: Replay.Recordable<typeof Game.schema, typeof Root>
readonly fetch: ReplayViteSink.Options["fetch"]
/**
* A wall clock for the recorder: a replay's `savedAt` names its file in
@@ -45,7 +41,7 @@ export interface DevtoolsHost {
* page-relative `performance.now` the runtime's debug timings read.
*/
readonly wallClock: HostClock.HostClock
- /** The page the monitor listens to. */
+ /** The page whose `\` key saves a replay. */
readonly host: Window
/** Breaks `FewerThanTenBuildings` on purpose, to try a replay out. */
readonly demo: boolean
@@ -61,6 +57,13 @@ export const attachDevtools = (host: DevtoolsHost) => {
hostClock: host.wallClock,
saveOn: { failure: true, invariants: host.demo ? [CoinsAreWhole, FewerThanTenBuildings] : [CoinsAreWhole] }
})
- const monitor = Monitor.attach(host.runtime, { schedules: { simulate, project, draw }, mount: host.mount, host: host.host, replay: recorder })
- return { recorder, monitor }
+ // A key in place of the old monitor's "Save replay" button; never while typing in a field.
+ const onKey = (event: KeyboardEvent) => {
+ if (event.key !== "\\" || event.repeat) return
+ const target = event.target
+ if (target instanceof HTMLElement && (target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName))) return
+ recorder.save("saved by the player")
+ }
+ host.host.addEventListener("keydown", onKey)
+ return { recorder, dispose: () => host.host.removeEventListener("keydown", onKey) }
}
diff --git a/src/app/lint.ts b/src/app/lint.ts
index c663762..838c7ce 100644
--- a/src/app/lint.ts
+++ b/src/app/lint.ts
@@ -4,7 +4,9 @@
* `project` and the renderer's `draw` schedules described without running
* (they need a page). It lives with the app because it is the one place that
* knows every layer; the simulation's headless entry stays free of the view
- * and the renderer.
+ * and the renderer. Those two load inside `lintTarget`, so the lint treats
+ * them as host code and checks only what the simulation loads against the
+ * simulation rules in `.oxlintrc.json`.
*/
import { HostClock } from "@typeonce/ritmo"
@@ -13,12 +15,11 @@ import { founding } from "../game/headless.ts"
import { resolveRules } from "../game/rules/config.ts"
import { blankResources, simulate } from "../game/schedule.ts"
import { Edits, Game, Rules } from "../game/schema.ts"
-import { draw } from "../render/three/schedule.ts"
-import { project } from "../view/schedule.ts"
const lintCharter: CharterValue = { size: "small", term: 45, land: "fair", seed: 7 }
-export const lintTarget = () => {
+export const lintTarget = async () => {
+ const [{ draw }, { project }] = await Promise.all([import("../render/three/schedule.ts"), import("../view/schedule.ts")])
const made = Game.Runtime.make({
services: Game.Runtime.services(Game.Runtime.service(Edits, founding(lintCharter)), Game.Runtime.service(Rules, resolveRules())),
resources: blankResources(),