hex-world
    Preparing search index...

    Class UnitManager

    Manages a collection of HexUnits — updates their world positions each frame and syncs their attached Three.js Object3Ds.

    Usage:

    const unitManager = new UnitManager({ scene, map, layout, fogData });

    const unit = new HexUnit({ col: 10, row: 10, travelSpeed: 4, fogRevealRange: 3 });
    unit.onMoveStart = () => mixer.clipAction(walkClip).play();
    unit.onMoveEnd = () => mixer.clipAction(idleClip).play();

    unitManager.addUnit(unit, gltf.scene);
    unit.travel(path);

    // In your render loop:
    unitManager.update(deltaTime);
    Index

    Constructors

    Properties

    Unit lifecycle and movement events. The same information the per-unit onMoveStart / onCellEnter / onMoveEnd callbacks carry, but as a broadcast: any number of subscribers, and no need to re-wire a callback every time a unit is created.

    unitManager.events.on('unitArrived', ({ unit, col, row }) => endTurn(unit, col, row));
    

    Accessors

    • get hideUnitsInFog(): boolean

      Whether units on explored-but-not-currently-visible cells are hidden. While enabled, this manager owns each unit Object3D's visible flag — turn it off to drive visibility yourself.

      Returns boolean

    • set hideUnitsInFog(enabled: boolean): void

      Parameters

      • enabled: boolean

      Returns void

    Methods

    • True if the unit's cell is currently within some source's sight — i.e. whether it is drawn under the ghost-state rule. Always true when there is no fog data.

      Parameters

      Returns boolean

    • Registers a unit and adds its Object3D to the scene. The unit's initial fog reveal is applied immediately if fogRevealRange > 0.

      The unit's own onMoveStart / onCellEnter / onMoveEnd callbacks are wrapped, not replaced — whatever you set stays wired, and removeUnit puts the originals back, so a unit can be removed and re-added without stacking a second layer of fog reveals on it.

      Parameters

      Returns void

    • Call once per frame with the elapsed time in seconds. Updates all unit positions and syncs their Object3Ds — including the ghost-state rule when hideUnitsInFog is on.

      Parameters

      • deltaTime: number

      Returns void

    • Clears and re-applies all unit fog contributions. Call this after fogData.reset() — or after fogData.load() restores a saved memory tier — to rebuild the live visibility tier from where the units actually are.

      Returns void