mwg API
    Preparing search index...

    Class UnitSelector

    The two-step unit selector an attack starts with: pick who attacks, then pick what they attack.

    Renderer-free, so the choosing rules are tested without a board: candidates are the enabled units on the selecting side, targets are the enabled units that pass canTarget once an attacker is chosen, move walks the active list and select advances a stage. back undoes the attacker choice rather than only the target, so a player who picked the wrong attacker lands where they can pick again rather than being stuck one step in.

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

    const selector = new UnitSelector({
    units: [{ id: 'hero', side: '1' }, { id: 'rat', side: '2' }],
    side: '1',
    });
    selector.select(); // hero attacks
    console.log(selector.targets.map((unit) => unit.id)); // ['rat']
    Index
    onChange: Signal<void> = ...
    • moves the highlight, wrapping at both ends, within whichever list is active

      Parameters

      • delta: number

      Returns void

    • takes the highlighted unit: on the attacker stage it advances to choosing a target

      Returns boolean