mwg API
    Preparing search index...

    Class World<M>

    Many maps in one world, joined by transitions.

    mwg deliberately does not say what a "map" is here - a TileMap and a Level, a DialogueStage, or a game's own bundle of the two. What World owns is the part that is the same regardless: a map is created from a factory registered by id, and by default kept alive for as long as the world exists - so a monster left half-dead in a dungeon room is still half-dead when the player wanders back in, without the game writing that by hand.

    That default is ADOM's shape, not every game's. A game with SPD's shape - most floors are never revisited, and the ones that are should feel new - marks those maps persistent: false at define time: enter then rebuilds them from the factory every time, discarding whatever was there. Both live in the same World; a game's overworld and towns can stay persistent while its dungeon floors do not.

    import { World } from '@datamoc/mw_games/world';

    interface MyMap { name: string }

    const world = new World<MyMap>();
    world.define('town', () => ({ name: 'town' })); // persistent by default
    world.define('dungeon1', () => ({ name: 'dungeon1' }), { persistent: false });

    world.enter('town');
    console.log(world.current?.name); // 'town'

    Type Parameters

    • M
    Index
    • get spawn(): string | undefined

      the spawn point passed to the most recent enter, for the game to place its player by

      Returns string | undefined

    • Registers how to build a map.

      Parameters

      • id: string
      • create: () => M
      • options: { persistent?: boolean } = {}

      Returns void

    • Switches to a map - creating it on first entry, reusing it on every one after unless it was defined persistent: false, in which case every entry rebuilds it.

      Parameters

      • id: string
      • Optionalspawn: string

        a named entry point within the target map; the game reads it back from World.spawn to know where to place the player - World does not know what a position is, only that one was asked for

      Returns M

    • true once a map has been created, whether or not it is the current one

      Parameters

      • id: string

      Returns boolean

    • true if this id was defined with persistent: false

      Parameters

      • id: string

      Returns boolean

    • drops a map's live state, so its factory builds a fresh one next time it is entered

      Parameters

      • id: string

      Returns void