*.system.ts
Any file ending in .system.ts under src/ is a system. Its default export is the
declaration.
// src/room/warmth.system.ts — the system room/warmth
import { comfort } from "./comfort"
export default defineSystem({
reads: ["temperature"],
writes: ["heating"],
run() {
for (const room of ecs.query({ components: ["temperature"] })) {
ecs.set({ id: room.id, components: { heating: { on: comfort.cold(room.temperature) } } })
}
},
})
defineSystem, ecs and kernel are ambient — never imported. Component names are checked
by the editor against types/, so a typo is a red line, not a failed tick.
run receives { now, stimuli, since }. Make it async run() for an async system.
Types
The generated types for a component are importable, for plain code and tests:
import type { Temperature } from "#schema/room/room.types"
Runs on
The main thread by default; thread: "worker" for another core. TypeScript can do everything
a system can — including stimuli and every kernel verb.
What a system can declare is in Systems.