mwg API
    Preparing search index...

    Class Whiteboard<T>

    The planned-but-uncommitted orders of a turn - Wesnoth's whiteboard - with undo across them.

    A plan is one entry per unit, so replanning a unit replaces its earlier order in place rather than stacking a second one for the same unit: what is on the board is the turn as it would be played, not the history of how a player got there. Undo pops the last plan onto a redo stack (planning again clears that stack, the usual undo contract), and commit hands the plans to the caller, which is where the framework stops - actually executing them is the game's turn.

    import { Whiteboard } from '@datamoc/mw_games/battle';

    const board = new Whiteboard<{ unit: string; x: number; y: number }>();
    board.plan({ unit: 'hero', x: 2, y: 3 });
    board.plan({ unit: 'archer', x: 5, y: 1 });
    board.undo();
    console.log(board.plans); // [{ unit: 'hero', x: 2, y: 3 }]

    Type Parameters

    Index
    onChange: Signal<void> = ...
    • Hands the plans to the caller and empties the board - the moment a turn stops being a plan. The orders are returned in planning order.

      Returns T[]

    • adds or replaces a unit's plan; clears the redo stack, as planning after undo does

      Parameters

      • action: T

      Returns void

    • the plan for a unit, if it has one on the board

      Parameters

      • unit: string

      Returns T | undefined

    • puts the last undone plan back, replacing any plan the unit has picked up since

      Returns T | null

    • takes the last plan off the board, returning it so a caller can put it back

      Returns T | null