mwg API
    Preparing search index...

    Class Secrets

    A cell that renders and blocks like its surroundings until revealed.

    The concealment itself is just terrain: conceal writes the disguise kind straight into the Level, so a secret door already passes every passable/transparent check as whatever it is disguised as - a wall that cannot be walked through or seen past, a floor that can. Nothing in FieldOfView or Pathfinder needs to know secrets exist. What this class remembers is the other half: which cells have a secret at all, and what they turn into once discovered - a secret door swapping to a passable, transparent kind; a trap staying passable but becoming visibly a trap.

    Discovery itself is a game's call, not this class's: a search action rolling against a distance, a trap firing the moment a creature steps onto it, a wand of revealing. This only does the bookkeeping once that decision has been made.

    import { Secrets, Level, WALL, FLOOR } from '@datamoc/mw_games/roguelike';

    const level = new Level(20, 20, [WALL, FLOOR], 1);
    const secrets = new Secrets(level);

    secrets.conceal(5, 5, 0, 1); // disguised as WALL (0), reveals as FLOOR (1) once found
    console.log(secrets.isSecret(5, 5)); // true - the cell reads as solid rock until found

    secrets.discover(5, 5); // a search action succeeded
    Index
    • hides a cell as disguise, remembering that it becomes revealed once discovered

      Parameters

      • x: number
      • y: number
      • disguise: number
      • revealed: number

      Returns void

    • Swaps a concealed cell to its revealed kind.

      Parameters

      • x: number
      • y: number

      Returns boolean

      whether there was anything to discover - false for a cell with no secret, or one already found, so a caller can tell a real discovery from a wasted search

    • a cell with a secret, still hidden - what a search action should be rolling against

      Parameters

      • x: number
      • y: number

      Returns boolean

    • Returns { discovered: number[]; revealed: [number, number][] }

    • rebuilds secrets from save data onto a (separately restored) level

      Parameters

      • level: Level
      • data: { discovered: number[]; revealed: [number, number][] }

      Returns Secrets