ecspresso
    Preparing search index...

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

    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

    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

      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.

      Fires exactly once per system. For systems added before initialize(), the hook is awaited inside initialize() itself. For systems added after initialize() has returned, the hook fires on registration (at the next update()'s finalize step) — async hooks run fire-and-forget, so don't rely on completion ordering against the first process call.

      Parameters

      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

    • Inline-query terminator: define a single query and a per-entity callback in one call. Collapses the common addQuery + setProcess + for-loop pattern into a single chain step.

      Only valid on a builder with no prior queries or process function — TypeScript narrows this to never otherwise, and a runtime guard throws for untyped callers. For multi-query systems use addQuery + setProcess.

      When mutates is declared, the callback may return false to skip the auto-mark for that specific entity. Returning true, undefined, or any other value stamps all components listed in mutates. Components in with but absent from mutates are narrowed to Readonly<T> on the per-entity iteration type.

      Type Parameters

      • W extends string | number | symbol
      • WO extends string | number | symbol = never
      • O extends string | number | symbol = never
      • M extends string | number | symbol = W

      Parameters

      • this: [keyof Queries] extends [never]
            ? [keyof Singletons] extends [never]
                ? SystemBuilder<
                    Cfg,
                    Queries,
                    Label,
                    SysGroups,
                    ResourceKeys,
                    Singletons,
                >
                : never
            : never
      • definition: {
            changed?: readonly W[];
            mutates?: readonly M[];
            optional?: readonly O[];
            parentHas?: readonly (keyof Cfg["components"])[];
            with: readonly W[];
            without?: readonly WO[];
        }

        Inline query definition (with / without / optional / changed / parentHas / mutates)

      • process: (
            ctx: {
                dt: number;
                ecs: default<Cfg>;
                entity: FilteredEntity<Cfg["components"], W, WO, O, M>;
            } & (
                [ResourceKeys] extends [never]
                    ? {}
                    : {
                        resources: {
                            readonly [K in string | number | symbol]: Cfg["resources"][K]
                        };
                    }
            ),
        ) => boolean
        | void

        Callback invoked once per matching entity each frame

      Returns SystemBuilder<
          Cfg,
          Queries & Record<"__each", QueryDefinition<Cfg["components"], W, WO, O, M>>,
          Label,
          SysGroups,
          ResourceKeys,
          Singletons,
      >