Skip to content

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

Lint with the Ritmo oxlint plugin

SandroMaglione61fdd7225a02
diff --git a/.oxlintrc.json b/.oxlintrc.json
index aa2f9b7..89c60bd 100644
--- a/.oxlintrc.json
+++ b/.oxlintrc.json
@@ -1,12 +1,38 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript"],
- "jsPlugins": ["./tools/lint/plugin.mjs"],
+ "jsPlugins": ["./tools/lint/plugin.mjs", "@typeonce/oxlint-plugin-ritmo"],
"categories": {
"correctness": "off"
},
"rules": {
- "town/no-cast-escape": "error"
+ "town/no-cast-escape": "error",
+ "ritmo/handle-tick-result": "error",
+ "ritmo/prefix-descriptor-and-system-names": "error",
+ "ritmo/use-cell-value": "error"
},
+ "overrides": [
+ {
+ "files": [
+ "src/sim/**",
+ "src/rules/**",
+ "src/grid.ts",
+ "src/mapgen.ts",
+ "src/places.ts",
+ "src/appeal.ts",
+ "src/content.ts",
+ "src/schema.ts",
+ "src/archetypes.ts",
+ "src/iso.ts"
+ ],
+ "rules": {
+ "ritmo/use-clock-for-time": "error",
+ "ritmo/use-random-for-randomness": "error",
+ "ritmo/use-ops-for-math": "error",
+ "ritmo/keep-simulation-headless": "error",
+ "ritmo/no-infinity-in-simulation-data": "error"
+ }
+ }
+ ],
"ignorePatterns": ["dist/**", "node_modules/**", "deploy/**", "output/**"]
}
diff --git a/scripts/look-ui.ts b/scripts/look-ui.ts
index 26751de..74234fb 100644
--- a/scripts/look-ui.ts
+++ b/scripts/look-ui.ts
@@ -76,7 +76,8 @@ for (const [name, width, height, phone] of [["desktop", 1440, 1000, false], ["ph
const t = e.components["Town/Tile"], w = e.components["Town/Water"]
if (w && Math.abs(t.x - f.x) <= 3 && Math.abs(t.y - f.y) <= 3) e.components["Town/Water"] = { fished: tick }
}
- runtime.restore(s)
+ const restored = runtime.restore(s)
+ if (!restored.ok) throw new Error(`The changed town did not load: ${JSON.stringify(restored.error)}`)
}, f)
await page.evaluate(() => (window as any).town.advance(12))
await look(f.x + 1, f.y + 1, phone ? 1.4 : 2)
@@ -102,7 +103,8 @@ for (const [name, width, height, phone] of [["desktop", 1440, 1000, false], ["ph
const s = runtime.snapshot()
s.resources["Town/Fate"].rank = Math.max(s.resources["Town/Fate"].rank, 2)
s.resources["Town/Treasury"].coins = 5000
- runtime.restore(s)
+ const restored = runtime.restore(s)
+ if (!restored.ok) throw new Error(`The changed town did not load: ${JSON.stringify(restored.error)}`)
})
await page.evaluate(() => (window as any).town.advance(1))
const hall = (await find(page, (e) => e.components["Town/TownHall"])).components["Town/Tile"] as Tile
@@ -124,7 +126,8 @@ for (const [name, width, height, phone] of [["desktop", 1440, 1000, false], ["ph
const inv = e.components["Town/Inventory"]
if (e.components["Town/Storage"] && inv) inv.stock = { ...inv.stock, planks: Math.min(inv.cap, 120), stone: Math.min(inv.cap, 120), tools: Math.min(inv.cap, 40), cloth: Math.min(inv.cap, 40) }
}
- runtime.restore(s)
+ const restored = runtime.restore(s)
+ if (!restored.ok) throw new Error(`The changed town did not load: ${JSON.stringify(restored.error)}`)
})
const kinds = ["townhall", "warehouse", "farm", "bakery", "market", "chapel", "quarry", "firewatch"]
const picked: Array<{ kind: string; tile: Tile }> = []
diff --git a/scripts/look-upgrades.ts b/scripts/look-upgrades.ts
index dbd87f9..275dac1 100644
--- a/scripts/look-upgrades.ts
+++ b/scripts/look-upgrades.ts
@@ -33,7 +33,8 @@ try {
s.resources["Town/Treasury"].coins = 5000
const hall = s.entities.find((e: any) => e.components["Town/TownHall"])
hall.components["Town/Inventory"].stock = { ...hall.components["Town/Inventory"].stock, planks: 90, stone: 90, tools: 20 }
- runtime.restore(s)
+ const restored = runtime.restore(s)
+ if (!restored.ok) throw new Error(`The changed town did not load: ${JSON.stringify(restored.error)}`)
})
await page.evaluate(() => (window as any).town.advance(1))
const hall = await page.evaluate(() => (window as any).town.runtime.snapshot().entities.find((e: any) => e.components["Town/TownHall"]).components["Town/Tile"])
@@ -62,7 +63,8 @@ try {
const hall=s.entities.find((e:any)=>e.components["Town/TownHall"])
Object.assign(hall.components["Town/Inventory"].stock,{planks:120,stone:120,tools:40,cloth:40})
s.resources["Town/Treasury"].coins=5000
- t.runtime.restore(s)
+ const restored = t.runtime.restore(s)
+ if (!restored.ok) throw new Error(`The changed town did not load: ${JSON.stringify(restored.error)}`)
})
await page.evaluate(([x,y])=>(window as any).town.ui.edits.push({type:"upgrade",cell:{x,y}}),[hall.x,hall.y])
await page.evaluate(()=>(window as any).town.advance(80))
diff --git a/src/main.ts b/src/main.ts
index 2b779d8..4500a4f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -90,7 +90,10 @@ const start = async () => {
// `town.runtime.snapshot()`, and `town.advance(seconds)` to fast-forward the simulation.
if (import.meta.env.DEV) {
const advance = (seconds: number) => {
- for (let i = 0; i < Math.round(seconds / step.dt); i++) runtime.tick(simulate)
+ for (let i = 0; i < Math.round(seconds / step.dt); i++) {
+ const stepped = runtime.tick(simulate)
+ if (!stepped.ok) throw new Error(`A step failed: ${JSON.stringify(stepped.error)}`)
+ }
}
Object.assign(window, { town: { ui, runtime, advance, view: stage } })
if (runtime.debug !== undefined) {