mwg API
    Preparing search index...

    Class PresentationQueue<Event>

    Plays simulation events one at a time, at whatever pace their presentation actually takes, entirely separate from the commit that already happened: simulation.SimulationRuntime. dispatch (or runScenario) returns its events synchronously and completely, and this is what a scene hands them to afterwards. mwg never sees what an event means - play is the game's own mapping from event to animation/sound/UI, this only sequences the calls.

    The same shape as two-d.ui.Toast's queued, timed presentation, generalised to any event type and freed of Toast's own Pixi container, since queuing which event plays next needs no renderer at all.

    import { PresentationQueue } from '@datamoc/mw_games/core';

    type GameEvent = { type: 'move' } | { type: 'damage'; amount: number };

    const presentation = new PresentationQueue<GameEvent>({
    play: (event) => {
    if (event.type === 'move') return 0.2; // a move tween takes 200ms
    console.log('damage:', event.amount); // a floating number, shown instantly
    },
    });

    presentation.enqueue([{ type: 'move' }, { type: 'damage', amount: 7 }]);
    presentation.update(0.2); // the move finishes; the damage event plays right behind it
    console.log(presentation.isBusy); // false - nothing left queued

    Type Parameters

    • Event
    Index
    • get isBusy(): boolean

      true while an event is playing or others are waiting behind it

      Returns boolean

    • adds events to the end of the queue, starting them immediately if nothing is playing

      Parameters

      • events: readonly Event[]

      Returns void

    • advances the current event's timer; starts the next one once it elapses

      Parameters

      • dt: number

      Returns void