ecspresso
    Preparing search index...

    Class SystemBuilder<Cfg, Queries, Label, SysGroups, ResourceKeys>

    Builder class for creating type-safe ECS Systems with proper query inference. Systems are automatically registered with their ECSpresso instance when finalized (at the start of initialize() or update()).

    Type Parameters

    • Cfg extends WorldConfig = EmptyConfig
    • Queries extends Record<string, QueryDefinition<Cfg["components"]>> = {}
    • Label extends string = string
    • SysGroups extends string = never
    • ResourceKeys extends keyof Cfg["resources"] = never
    Index

    Constructors

    Accessors

    Methods

    • Exclude this system from running in specified screens. System will be skipped during update() when the current screen is in this list.

      Parameters

      • screens: readonly (keyof Cfg["screens"] & string)[]

        Array of screen names where this system should NOT run

      Returns this

      This SystemBuilder instance for method chaining

    • Set the execution phase for this system. Systems are grouped by phase and executed in order: preUpdate -> fixedUpdate -> update -> postUpdate -> render

      Parameters

      • phase: SystemPhase

        The phase to assign this system to (default: 'update')

      Returns this

      This SystemBuilder instance for method chaining

    • Restrict this system to only run in specified screens. System will be skipped during update() when the current screen is not in this list.

      Parameters

      • screens: readonly (keyof Cfg["screens"] & string)[]

        Array of screen names where this system should run

      Returns this

      This SystemBuilder instance for method chaining

    • Require specific assets to be loaded for this system to run. System will be skipped during update() if any required asset is not loaded.

      Parameters

      • assets: readonly (keyof Cfg["assets"] & string)[]

        Array of asset keys that must be loaded

      Returns this

      This SystemBuilder instance for method chaining

    • Allow this system to run even when all queries return zero entities. By default, systems with queries are skipped when no entities match.

      Returns this

    • Set event handlers for the system These handlers will be automatically subscribed when the system is attached

      Parameters

      • handlers: {
            [EventName in string | number | symbol]?: (
                ctx: { data: Cfg["events"][EventName]; ecs: default<Cfg> },
            ) => void
        }

        Object mapping event names to handler functions

      Returns this

      This SystemBuilder instance for method chaining

    • Set the onDetach lifecycle hook Called when the system is removed from the ECS

      Parameters

      • onDetach: LifecycleFunction<Cfg>

        Function to run when this system is detached from the ECS

      Returns this

      This SystemBuilder instance for method chaining

    • Register a callback that fires once per entity the first time it appears in a query's results. Fires before process. Automatic cleanup when entity leaves the query so re-entry fires the callback again.

      Type Parameters

      • QN extends string

      Parameters

      • queryName: QN

        Name of a query previously added via addQuery

      • callback: (
            ctx: {
                ecs: default<Cfg>;
                entity: FilteredEntity<
                    Cfg["components"],
                    Queries[QN] extends QueryDefinition<Cfg["components"], W> ? W : never,
                    Queries[QN] extends QueryDefinition<Cfg["components"], any, WO>
                        ? WO
                        : never,
                    Queries[QN] extends QueryDefinition<Cfg["components"], any, any, O>
                        ? O
                        : never,
                >;
            },
        ) => void

        Function called with the entity and ecs instance

      Returns this

      This SystemBuilder instance for method chaining

    • Set the onInitialize lifecycle hook Called when the system is initialized via ECSpresso.initialize() method

      Parameters

      • onInitialize: LifecycleFunction<Cfg>

        Function to run when this system is initialized

      Returns this

      This SystemBuilder instance for method chaining

    • Set the priority of this system. Systems with higher priority values execute before those with lower values. Systems with the same priority execute in the order they were registered.

      Parameters

      • priority: number

        The priority value (default: 0)

      Returns this

      This SystemBuilder instance for method chaining

    • Set the system's process function that runs each update. The callback receives a single context object { queries, dt, ecs, resources? }. The context is pre-allocated per system and reused every frame.

      Parameters

      • process: ProcessFunction<Cfg, Queries, ResourceKeys>

        Function to process entities matching the system's queries each update

      Returns this

      This SystemBuilder instance for method chaining

    • Declare resource dependencies for this system. Resources are resolved once (on first process call) and the same object is reused every frame. The resolved resources are available as ctx.resources in setProcess.

      Type Parameters

      • RK extends string

      Parameters

      • keys: readonly RK[]

        Array of resource keys to resolve

      Returns SystemBuilder<Cfg, Queries, Label, SysGroups, RK>

      This SystemBuilder instance for method chaining