mwg API
    Preparing search index...

    Class FeatureLayer<TContext>

    import { FeatureLayer } from '@datamoc/mw_games/roguelike';

    const features = new FeatureLayer<{ hp: number }>();
    features.define('trap', {
    interact: () => true,
    consequence: (_cell, ctx) => { ctx.hp -= 5; },
    persistent: false, // sprung once, then gone
    });

    features.place(42, 'trap');
    const hero = { hp: 20 };
    features.interact(42, hero); // hero.hp is now 15, and the trap is gone

    Type Parameters

    • TContext = unknown
    Index
    • looking at or searching the cell; a no-op on a cell with no feature or no inspect rule

      Parameters

      Returns void

    • places a defined kind onto a cell, replacing whatever was there

      Parameters

      • cell: number
      • kind: string

      Returns void

    • only which cell has which kind is save data; definitions are supplied fresh on load

      Returns { cells: [number, string][] }