typeonce.devypeonce
Menu

Ritmo

The all-in-one toolkit for agent-first game development.

A type-safe ECS runtime for TypeScript. You direct the mechanics and the feel, and your coding agent writes the game. Wrong code does not compile and the error names the fix.

pnpm add @typeonce/ritmo

Ritmo: the agent-first type safe ECS runtime

Why Ritmo

  • Errors that name the fix

    Systems receive only the access they declare. When the agent gets it wrong, the compiler says what to change.

  • Headless by default

    Devtools sessions run the simulation without a screen and show lints, invariants, and why each value changed.

  • Your renderer, your loop

    Ritmo runs the simulation. Drawing stays in your game, with bridges for Pixi and any node-based renderer.

  • Everything around the core

    Input and local multiplayer, rollback and lockstep netcode, and agent tools for pixel art, sound, and music.

A first look

game.ts
import { Clock, Descriptor, Schema } from "@typeonce/ritmo"

type Vec = { x: number; y: number }

// Define the world once: components, resources, and the fixed step.
const step = Clock.hz(60)
const Time = Clock.resource("Example/Time", step)
const Position = Descriptor.Component<Vec>()("Example/Position")
const Velocity = Descriptor.Component<Vec>()("Example/Velocity")

// Bind the schema to its game-facing APIs.
const Game = Schema.bind(
  Schema.fragment({
    components: { Position, Velocity },
    resources: { Time }
  })
)

const AdvanceTime = Clock.system(Game, {
  name: "Example/AdvanceTime",
  resource: Time
})

// Systems receive only the access they declare.
const Move = Game.System(
  "Example/Move",
  {
    queries: {
      moving: Game.Query({
        selection: {
          position: Game.Query.write(Position),
          velocity: Game.Query.read(Velocity)
        }
      })
    },
    resources: { time: Game.System.readResource(Time) }
  },
  ({ queries, resources }) => {
    const { dt } = resources.time.get()
    for (const match of queries.moving.each()) {
      const position = match.data.position.get()
      const velocity = match.data.velocity.get()
      match.data.position.set({
        x: position.x + velocity.x * dt,
        y: position.y + velocity.y * dt
      })
    }
  }
)

// Starting can fail (the clock is a validated resource),
// and so can a tick: both return a Result.
const made = Game.Runtime.make({
  services: Game.Runtime.services(),
  resources: { Time: Clock.start(step) }
})
if (made.ok) {
  const runtime = made.value
  const ticked = runtime.tick(Game.Schedule(AdvanceTime, Move))
  if (!ticked.ok) console.error(ticked.error)
}

Packages

typeonce.games

Original games for web, mobile, and desktop. Start playing in your browser.

Play now