areamap

Sleepy Macros

Areamap Library

Areamap is a map library for SugarCube designed for room-to-room movement like Darkest Dungeon or node-to-node movement like Faster Than Light — NOT for grid movement like Zelda or Final Fantasy Tactics.

Areamap takes a space-separated 2D text grid and converts it into a functional map for player movement (mapmove). All grid spaces with the same id will be treated as one big room (maparea) — regardless of how many grid spaces it occupies or whether it is continuous or not. Adjacent mapareas will be connected by exits that allow navigation between them.

Get the map library here

Features:

• • •

Macros

<<new_areamap>>

Defines a new areamap. This macro must be called in StoryInit. It accepts a 2D grid layout via its contents and supports optional child tags for advanced configuration.

<<place_arearose>>

Generates a 3x3 grid of directional links for navigation.

<<update_arearose>>

Manually updates a rose element.

<<place_areamapview>>

Renders a visual representation of the areamap with the tiles configured in the <<mapareas>> child tag of <<new_areamap>>, using the 2D grid defined in the <<mapview>> child tag of <<new_areamap>>. If no <<mapview>> was used, the 2D logic map is used. Can optionally be made clickable for navigation or to display maparea names.

<<update_areamapview>>

Manually updates a mapview element.

<<set_areascripts>>

Assigns TwineScript logic to run during the mapmove process (areascripts). Arguments can be used to control which mapareas trigger the areascripts. This macro must be called in StoryInit. Child tag order is preserved, but <<onmapattempt>> tags always run first, followed by: - when mapmove succeeds: <<onmapstart>> then <<onmapend>> - when mapmove fails: <<onmapabort>>

<<areamapmove>>

Manually triggers a mapmove attempt. This macro does not check exits — allowing for more flexible navigation — but blocked will still apply and cause the mapmove to fail.

• • •

JavaScript Methods

Javascript methods are stored on the Areamap window object. All methods take an argObj argument object.

new_areamap

Creates a new areamap. The <<new_areamap>> macro is a wrapper for this method.

create_rose

Creates a jQuery rose element. The <<place_arearose>> macro calls this method and appends the result to the macro output.

update_rose

Manually updates rose elements in the DOM. If the jQuery object passed to this method references multiple roses, all of them will update. Non-rose elements will be ignored. The <<update_arearose>> macro is a wrapper for this method.

create_mapview

Creates a jQuery mapview element. The <<place_areamapview>> macro calls this method and appends the result to the macro output.

update_mapview

Manually updates mapview elements in the DOM. If the jQuery object passed to this method references multiple mapviews, all of them will update. Non-mapview elements will be ignored. The <<update_areamapview>> macro is a wrapper for this method.

set_areascripts

Assigns TwineScript logic to run during the mapmove process. The <<set_areascripts>> macro is a wrapper for this method.

begin_mapmove

Begins the mapmove procedure and fires the areamap:mapmove_began event. This method does not check exits. The <<areamapmove>> macro is a wrapper for this method.

get_map

Retrieves a copy of a map object. Manipulating the returned object will not affect or update the original map. Use Areamap.edit_map to edit areamaps.

edit_map

Allows for dynamic modification of an existing areamap. This method will automatically update the areamap’s exits and update any roses or mapviews set to autoupdate.

• • •

Events

Areamap fires several events that allow for manipulating player movement and tracking map changes. All Areamap events fire off #passages and resolve on document. Authors that intend to intercept Areamap events should place their listeners on #story.

areamap:mapmove_began

Triggered immediately when any mapmove attempt begins

areamap:mapmove_resolved

Triggered after any mapmove resolves

areamap:map_edited

Triggered after the edit_map method completes, useful if you need to perform additional UI updates not covered by the standard autoupdate functionality.

• • •

Options

• • •

Usage Tips & Styling