Core
Schema
Schema authoring and binding.
This module is the bridge between raw descriptor declarations and the bound
Game API that systems, schedules, queries, commands, and runtimes use. It
answers "what world is allowed to exist in this game?" before any runtime
value is built.
The normal authoring flow is:
- declare descriptors with Descriptor.*
- group them into reusable Schema.fragment(...) values
- bind one Game with Schema.bind(...)
- build a runtime from that bound Game
Schema.Feature composes fragments and their schedules before binding; see
the feature module.
Examples
const Position = Descriptor.Component<{ x: number; y: number }>()("Position")
const Velocity = Descriptor.Component<{ x: number; y: number }>()("Velocity")
const Score = Descriptor.Resource<number>()("Score")
const Core = Schema.fragment({
components: { Position, Velocity },
resources: { Score }
})
const Root = Schema.defineRoot("Game")
const Game = Schema.bind(Core, Root)
Creates one explicit root token for schema-bound long-lived references.
Root tokens exist before schema construction so durable entity handles can be
stored in descriptor payload types without widening to Schema.Any.
const Root = Schema.defineRoot("Game")
const Target = Descriptor.Component<{
handle: Entity.Handle<typeof Root>
}>()("Target")
Creates an empty schema.
Creates a schema fragment.
Fragments are the composition unit for game modules: each says "this
subsystem contributes these components/resources/events/relations" and
nothing more. Binding and runtime assembly happen later.
const Combat = Schema.fragment({
components: { Health, Damage },
events: { Hit }
})
Merges two schema fragments into a larger closed schema.
Duplicate keys and descriptor names are rejected at the type level and at
runtime.
Composes one or more fragments and returns one bound Game surface.
Everything created from the returned object carries the same hidden root
brand, so systems, schedules, and runtimes from different bound schemas
cannot be connected accidentally.
const Root = Schema.defineRoot("Game")
const Game = Schema.bind(Core, Combat, Root)