mwg API
    Preparing search index...

    Class Minimap

    A downscaled picture of a level, built from exactly the data roguelike.FieldOfView already tracks - explored, distinct from visible - plus a per-cell colour a game supplies, since mwg has no opinion on what a wall or a floor should look like.

    The same widget serves both sizes a map screen comes in: a small corner HUD element at a coarse cellSize, or a full, Window-sized pause-and-look screen at a larger one - nothing here is specific to either. Quest markers or a tracked-quest location (see rpg.QuestLog.markerFor/trackedLocation) are a game's own overlay on top of world, same as they would be over any other rendered view.

    Revealed cells are painted once into a persistent RenderTexture and never revisited - sync only rasterises what newlyRevealed reports as new, rather than redrawing the whole map from scratch on every call, which is the one open engineering question this item named: how an explored-cell set becomes a small texture without becoming a per-frame cost that grows with how much of the level has been seen.

    import { Minimap } from '@datamoc/mw_games/two-d/render';

    const minimap = new Minimap({ widthInCells: 40, heightInCells: 24, cellSize: 2 });

    const explored = new Set([0, 1, 40]);
    minimap.sync(explored, (x, y) => ((x + y) % 2 === 0 ? 0x3a3a2a : 0x2f5a2f));
    minimap.setMarker(0, 0, Math.PI / 2); // the hero, facing down

    console.log(minimap.exploredCount); // 3

    Hierarchy

    • Container
      • Minimap
    Index
    • get exploredCount(): number

      cells revealed since the last call, by width/height already given to the constructor

      Returns number

    • Removes all internal references and listeners as well as removes children from the display list. Do not use a Container after calling destroy.

      Parameters

      • Optionaloptions: DestroyOptions

        Options parameter. A boolean will act as if all options have been set to that value

      Returns void

      container.destroy();
      container.destroy(true);
      container.destroy({ children: true });
      container.destroy({ children: true, texture: true, textureSource: true });
    • forgets everything baked, so the next sync repaints from a clean texture - a fresh floor

      Returns void

    • positions a marker at a cell, optionally pointing it in a facing direction (radians)

      Parameters

      • x: number
      • y: number
      • Optionalfacing: number
      • color: number = 0xffffff

      Returns void

    • Bakes every cell in explored that has not been drawn yet, at whatever colour colorFor reports for it. A cell already baked is never revisited even if colorFor would now answer differently - explored terrain does not usually change colour, and a game that wants it to can reset() and resync from a clean texture.

      Parameters

      • explored: ReadonlySet<number>
      • colorFor: (x: number, y: number) => number

      Returns void