AbstractWorldComponent
world/abstract-world-component.ts:48 Extends AbstractComponent<World>
Implements WorldComponent<TDeps>
Abstract base class for components attached to a World.
The recommended way to implement the WorldComponent contract. Supplies the boilerplate every world-scoped system would otherwise write by hand:
- The AbstractComponent.host reference, typed as World.
- A AbstractWorldComponent.world alias (identical to
hostat this tier) so subclass code reads symmetrically with the AbstractWorldObjectComponent convenience. - A AbstractWorldComponent.game accessor that hops through the world to the parent Game — the single-step way to reach page-scoped services like the keyboard or mouse samplers.
- No-op default implementations of the required lifecycle hooks
(
onAdded,onUpdate,onDestroy) so subclasses only override the ones they actually use. The optionalonPreUpdateandonPostUpdatehooks remain opt-in — declare them only when needed.
Subclasses that take additional constructor arguments must define
their own constructor and forward host via super(host). Subclasses
that need nothing beyond the host can omit the constructor entirely
and inherit the one on this base.
Example
class PauseGate extends AbstractWorldComponent {
public onUpdate(): void {
if (this.game.getKeyboardState().isDown('Escape')) {
this.world.enabled = false;
}
}
}Constructors
constructor(host: World): AbstractWorldComponent<TDeps> Parameters
-
hostWorld
Properties
enabled: boolean Per-component gate on the three update hooks (onPreUpdate,
onUpdate, onPostUpdate). When explicitly false, the engine skips
all three for this component during the host's tick — useful for
temporarily pausing behaviour (e.g. a freeze powerup) without removing
the component and losing its internal state.
Does not gate onAdded or onDestroy; those always fire so a host can
never end up with a half-attached component.
Accessors
game: Game The Game the host world belongs to. Always non-null — the
world's game field is a mandatory construction argument, not an
option.
world: World The World this component is attached to — identical to
AbstractComponent.host at this tier, exposed under the
world name so subclass code reads the same on every tier.
Methods
onAdded(_deps: TDeps): void Lifecycle hook that is called when the component is added to the host object. Should not be called directly.
Parameters
-
_depsTDeps
Returns
void onDestroy(_deps: TDeps): void Lifecycle hook that is called when the host object is destroyed. Should not be called directly.
Parameters
-
_depsTDeps
Returns
void onUpdate(_update: WorldUpdate, _deps: TDeps): void Lifecycle hook for the main update phase. Called once per world
tick, after every component's onPreUpdate and before any
onPostUpdate.
Parameters
-
_updateWorldUpdate -
_depsTDeps
Returns
void