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:

  1. declare descriptors with Descriptor.*
  2. group them into reusable Schema.fragment(...) values
  3. bind one Game with Schema.bind(...)
  4. 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)

Functions

Public helpers for defining roots, creating fragments, and binding Game.

defineRoot

Source

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")

empty

Source

Creates an empty schema.

fragment

Source

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 }
})

merge

Source

Merges two schema fragments into a larger closed schema.

Duplicate keys and descriptor names are rejected at the type level and at runtime.

bind

Source

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)