mwg API
    Preparing search index...

    Class SceneComponentHost<TScene>

    Composes a scene out of named SceneComponents instead of one class accreting every responsibility a scene ends up needing - a factory assembling named sections (map, encounters, UI) at scene-creation time, each a separate module with its own lifecycle.

    A composition helper, not a base class: a scene owns one SceneComponentHost and forwards core.Scene's lifecycle methods to it, the same few lines regardless of whether that scene extends core.Scene directly or two-d.Scene2D - inheritance would have to pick one of those to sit above, composition does not.

    import { Scene, SceneComponentHost, type SceneComponent } from '@datamoc/mw_games/core';

    class MapSection implements SceneComponent<DungeonScene> {
    readonly name = 'map';
    create(scene: DungeonScene): void { console.log('map ready for', scene.floor); }
    update(_scene: DungeonScene, dt: number): void { }
    }

    class DungeonScene extends Scene {
    floor = 1;
    private components = new SceneComponentHost<DungeonScene>();

    create(): void {
    this.components.add(new MapSection(), this);
    }
    override update(dt: number): void { this.components.update(this, dt); }
    protected override teardown(): void { this.components.destroy(this); }
    }

    Type Parameters

    Index