Global

Members

(constant) ADJ_DIRECTIONS

Description:
  • Directions that lead to adjacent cells on the same board (8-directional).

Source:

Directions that lead to adjacent cells on the same board (8-directional).

(constant) DIR_BY_DELTA

Description:
  • Lookup table: "${xDelta},${yDelta}" → Direction constant, derived from ADJ_DIRECTIONS.

Source:

Lookup table: "${xDelta},${yDelta}" → Direction constant, derived from ADJ_DIRECTIONS.

(constant) DIR_KEYS

Description:
  • Direction keys used after throw/fire-mode

Source:

Direction keys used after throw/fire-mode

(constant) EMPTY_HANDED

Description:
  • Singleton representing the player wielding nothing. Always lives at index 0 in the PlayerBag.

Source:

Singleton representing the player wielding nothing. Always lives at index 0 in the PlayerBag.

(constant) FIRE_DAMAGE

Description:
  • Animated fire — 4-frame loop using ω glyph cycling through red/orange/yellow. Deals fire damage to non-fire-resistant agents and converts trees to stumps.

Source:

Animated fire — 4-frame loop using ω glyph cycling through red/orange/yellow. Deals fire damage to non-fire-resistant agents and converts trees to stumps.

(constant) KEY_MAP

Description:
  • Key → { action, dir? } mapping — matches original Java InputManager key bindings.

    Movement: arrow keys / vi keys (hjkl + yubn) / numpad Pickup: g (or p) Drop: d Use: Enter Throw: t followed by a direction key (two-step) Fire (ranged): f followed by a direction key (two-step), OR shift+direction (one-step) Shift+arrow, shift+vi (HJKLYUBN), or ctrl+numpad Vertical: z (game detects UP vs DOWN from terrain) Bag select-up: a Bag select-down: s First weapon: w Empty-handed: e Reorder up: c (or <) Reorder down: v (or >)

Source:

Key → { action, dir? } mapping — matches original Java InputManager key bindings.

Movement: arrow keys / vi keys (hjkl + yubn) / numpad Pickup: g (or p) Drop: d Use: Enter Throw: t followed by a direction key (two-step) Fire (ranged): f followed by a direction key (two-step), OR shift+direction (one-step) Shift+arrow, shift+vi (HJKLYUBN), or ctrl+numpad Vertical: z (game detects UP vs DOWN from terrain) Bag select-up: a Bag select-down: s First weapon: w Empty-handed: e Reorder up: c (or <) Reorder down: v (or >)

(constant) MAP_DIRECTIONS

Description:
  • Directions that can lead to adjacent boards (cardinal + vertical).

Source:

Directions that can lead to adjacent boards (cardinal + vertical).

(constant) NOT_EDITABLE

Description:
  • This piece should not be available in the map editor.

Source:

This piece should not be available in the map editor.

(constant) PENETRABLE

Description:
  • Thrown items can fly over this terrain.

Source:

Thrown items can fly over this terrain.

(constant) PLAYER

Description:
  • Bitmask flag constants for pieces, terrain, items, and agents. Mirrors Flags.java exactly.

Source:

Bitmask flag constants for pieces, terrain, items, and agents. Mirrors Flags.java exactly.

(constant) SHIFT_ARROW_DIRS

Description:
  • Shift+arrow keys that fire instantly — the arrow-key subset of DIR_KEYS.

Source:

Shift+arrow keys that fire instantly — the arrow-key subset of DIR_KEYS.

(constant) TerrainUtils

Description:
  • Utility helpers for terrain manipulation. Mirrors TerrainUtils.java.

Source:

Utility helpers for terrain manipulation. Mirrors TerrainUtils.java.

(constant) _FIREBALL_SYMBOLS

Description:
  • Fireball — fired by Thermadon. Deals heavy fire damage.

Source:

Fireball — fired by Thermadon. Deals heavy fire damage.

(constant) _serializers

Description:
  • Registry — singleton cache for all piece instances.

    Pieces are immutable singletons identified by their serialization key (pipe-delimited: "TypeName|arg1|arg2"). Nested piece references within an arg use ^ as a sub-delimiter (e.g. "Altar^none" deserializes as the piece from key "Altar|none").

    Usage: Registry.register("Floor", Floor.SERIALIZER); const floor = Registry.terrain("Floor"); Registry.serialize(floor); // → "Floor"

Source:

Registry — singleton cache for all piece instances.

Pieces are immutable singletons identified by their serialization key (pipe-delimited: "TypeName|arg1|arg2"). Nested piece references within an arg use ^ as a sub-delimiter (e.g. "Altar^none" deserializes as the piece from key "Altar|none").

Usage: Registry.register("Floor", Floor.SERIALIZER); const floor = Registry.terrain("Floor"); Registry.serialize(floor); // → "Floor"

(constant) events

Description:
  • Global event bus singleton.

Source:

Global event bus singleton.

(constant) store

Description:
  • IndexedDB-backed wrapper for game saves. All methods are async. Quota is effectively unlimited (50% of available disk).

Source:

IndexedDB-backed wrapper for game saves. All methods are async. Quota is effectively unlimited (50% of available disk).

Methods

_buildCellHoverText(cell) → {string|null}

Description:
  • Build the HTML legend for a hovered cell: terrain, then agent (if any), then the topmost item (unless the terrain has HIDES_ITEMS). Mirrors Java's CellInfoPanel.renderCellInfo().

Source:
Parameters:
Name Type Description
cell Cell
Returns:
Type
string | null

_buildItemListText(cell) → {string|null}

Description:
  • Build the HTML text for the item-list popup, mirroring Java's MessageManager.displayItemsAtCurrentCell(). Returns null if the cell has no items.

Source:
Parameters:
Name Type Description
cell Cell
Returns:
Type
string | null

_cellEl()

Description:
  • Look up the .cell span at (x, y). Cannot index boardEl.children directly — #board also contains non-cell children (e.g. #loading-overlay), which would throw off a positional index.

Source:

_getPlayerAdjacentRects()

Description:
  • Returns viewport DOMRects for the 8 cells adjacent to the player. Mirrors Java's current.getAdjacentCells(null) check in positionDoesNotOverlap().

Source:

_itemAtDisplayIndex()

Description:
  • Return the item at visual display index index in the grouped item list for the given cell. Groups items by name (matching popup display order). Index 0 = first item shown in the popup (pressing '1' or 'p').

Source:

_matchesNameOrType()

Description:
  • True if item's display name matches name exactly, or if its Registry type ID (the piece's serialization key, up to the first "|") matches. Mirrors the Java Util.getType(item) comparison used by the "on drop" and "on pickup" triggers.

Source:

_openDB()

Description:
  • Open (or reuse) the IndexedDB database.

Source:

_positionPopup()

Description:
  • Position a popup using the 8-position strategy from Java's MessageManager. Tries positions in the same order as Java, picks the first valid one.

Source:

_rectsOverlap()

Description:
  • AABB overlap test — mirrors Java's CellMessagePanel.overlaps().

Source:

_renderPieceLabel(piece, outside) → {string}

Description:
  • Render a colored symbol + name label for one piece.

Source:
Parameters:
Name Type Description
piece Piece
outside boolean
Returns:
Type
string

_showFadePopup(boardEl, popupLayer, text, cellX, cellY, optionsopt) → {HTMLElement|null}

Description:
  • Show a fade-out popup anchored near a cell. Uses an 8-position strategy (matching Java's MessageManager) to find the first position that stays in the viewport, avoids other popups, and avoids the player's adjacent cells. Returns the popup element so callers can remove it early if needed.

Source:
Parameters:
Name Type Attributes Description
boardEl HTMLElement
popupLayer HTMLElement
text string
cellX number
cellY number
options Object <optional>
Returns:
Type
HTMLElement | null

_showModalPopup()

Description:
  • Show a modal (blocking) positional popup. Freezes the game until ESC/Enter. Positioning mirrors Java's CellMessageModalPanel.center(): starts right of cell, then clamps to viewport bounds.

Source:

allColors()

Description:
  • All registered color names → Color instances.

Source:

assessAmmo()

Description:
  • Check whether the player has loaded ammo for weapon. If so, decrement the ammo count and return ammoItem to be fired. Otherwise fire an "Out of ammo" message and return null.

Source:

buildBoard()

Description:
  • Build a Board from a deserialized scenario data object. Also used to restore boards from player.unsavedMaps.

Source:

burntColor(color) → {string}

Description:
  • Return a darker, browned version of the given color (the "burnt" effect).

Source:
Parameters:
Name Type Description
color Color
Returns:
Type
string

closeAllDialogs()

Description:
  • Close any currently-open dialog(s). Only one modal dialog should ever be open at a time — call this before showing a new one so a dialog left open by a prior flow (e.g. the game ending while a scroll/help dialog was up) doesn't linger open underneath and resurface later.

Source:

colorByName(name) → {Color|null}

Description:
  • Look up a Color instance by its name (case-insensitive). Returns null if not found.

Source:
Parameters:
Name Type Description
name string
Returns:
Type
Color | null

description()

Description:
  • Return a comma-separated string of visible flag labels for a given flags value. Returns an empty string if no visible flags are set.

Source:

deserializeBoard()

Description:
  • Restore a Board's state from a serialized data object.

Source:

deserializePlayer()

Description:
  • Restore the player's mutable state from a serialized object. The player instance must already exist; this mutates it.

Source:

directionByName()

Description:
  • Look up a Direction by name (case-insensitive). Returns null if not found.

Source:

findPathToTarget()

Description:
  • Determine the direction an agent should move given its targeting spec. Returns a Direction or null if no move is possible.

    Mirrors Java AgentUtils.findPathToTarget. There are two ways a target can be found:

    • the "direct" fast path, used only when the agent is attacking the player, isn't a CARNIVORE (which might prefer nearby meat) and isn't tracking breadcrumbs — this compares straight-line (Euclidean) distance to the player against the range.
    • the "visitor" path (everything else), which scans outward ring by ring — closest first — via board.visitRange, mirroring TargetingVisitor's per-cell priority: carnivore meat first, then the player (attack or flee), then (only in the ring immediately adjacent to the agent) a breadcrumb trail. The first match wins, so distance to the found cell is the ring index, not the true Euclidean distance.
Source:

frozenColor(color) → {string}

Description:
  • Return an rgb() string lightened toward white (the "frozen" effect).

Source:
Parameters:
Name Type Description
color Color
Returns:
Type
string

getFlag()

Description:
  • Look up a flag constant by its display label. Returns -1 if not found.

Source:

initCellHoverPopup()

Description:
  • Show a brief legend popup when the player hovers over a cell. Mirrors the Java CellInfoPanel behaviour: 600 ms delay to show, auto-hides after 2100 ms or on mouseout/mousedown.

Source:

initDialogs(onWinCloseopt)

Description:
  • Connect the events bus to the modal-message dialog. Call once during app init.

Source:
Parameters:
Name Type Attributes Description
onWinClose function <optional>

called when win dialog is closed

initInput(target)

Description:
  • Wire keyboard input to the game controller.

Source:
Parameters:
Name Type Description
target

element to listen on (typically document or #board)

initInventoryPanel()

Description:
  • Inventory panel — renders the player's bag as a list of clickable items. The selected item is highlighted. Clicking an item selects it.

Source:

initMessageLog()

Description:
  • Message log — appends game messages to the #message-list element and auto-scrolls to the bottom.

Source:

initMouseInput()

Description:
  • Wire mouse clicks on the board and inventory to game actions. Board click rules:

    • Click on a different cell: move one step toward it (or fire with Shift).
    • Click on the player's own cell: pick up the topmost item. Inventory click: select that item in the bag.
Source:

initStatsPanel()

Description:
  • Stats panel — keeps the HP bar, HP text, XP, gold, and flags display in sync with the player model via the events bus.

Source:

is()

Description:
  • True if flag is set in flags.

Source:

isMoveViable()

Description:
  • Can the agent move from from in direction dir? Mirrors Java AgentUtils.isMoveViable exactly, including the "don't move into the player's line of fire" and "don't wander into a bullet" checks.

    targetCell is the cell the agent is ultimately trying to reach (may be null, e.g. when falling back to breadcrumb tracking or random movement — in which case, as in Java, the LOF-dodge check is skipped since it isn't about the player).

Source:

loadBoard()

Description:
  • Load a board from a scenario JSON file.

Source:

nameByColor(hex) → {string|null}

Description:
  • Look up a color's display name by its hex string. Returns null if not found.

Source:
Parameters:
Name Type Description
hex string
Returns:
Type
string | null

not()

Description:
  • True if flag is NOT set in flags.

Source:

randomColor()

Description:
  • Return a random color hex string (used by win-game animation).

Source:

serializeBoard()

Description:
  • Serialize a Board's cell state to a plain object (safe to JSON.stringify). Player position is NOT saved here (managed by game.js).

Source:

serializePlayer()

Description:
  • Serialize the player to a plain object.

Source:

showConfirm(message, onConfirm, optsopt)

Description:
  • Show a yes/no confirmation dialog.

Source:
Parameters:
Name Type Attributes Description
message string
onConfirm function
opts Object <optional>

showLoadDialog(onLoad)

Description:
  • Show load dialog with a list of saves to choose from. The onLoad callback receives the chosen slot name.

Source:
Parameters:
Name Type Description
onLoad function

showMenu(optsopt) → {Promise.<(string|null)>}

Description:
  • Show the main menu. Returns a Promise that resolves with the chosen action. Possible resolved values: "new-game" | "load-game" | "help" | null (dismissed)

    Rendered as a plain overlay div rather than a native

    : browsers force-close a after enough Escape presses regardless of preventDefault on its cancel event (an anti-abuse measure so pages can't trap users behind an inescapable modal), which made the menu flash closed-then-reopened under repeated Escape presses.

Source:
Parameters:
Name Type Attributes Description
opts Object <optional>
Properties
Name Type Attributes Default Description
allowDismiss boolean <optional>
true

when false, Escape does nothing — there is no game in progress to return to, so dismissing would just reopen the same menu.

Returns:
Type
Promise.<(string|null)>

showModalMessage(message, onCloseopt)

Description:
  • Show a short modal message (used for win conditions, key events, etc.). If the message looks like a URL (.html extension), shows the win dialog. Otherwise shows a confirm dialog with "OK" only.

Source:
Parameters:
Name Type Attributes Description
message string
onClose function <optional>

showSaveDialog(onSave)

Description:
  • Show save dialog. The onSave callback receives the chosen slot name.

Source:
Parameters:
Name Type Description
onSave function

showScenarioDialog(scenarios) → {Promise.<({id:string, start:string}|null)>}

Description:
  • Show scenario selection list.

Source:
Parameters:
Name Type Description
scenarios Array.<{id:string, start:string, name:string, description:string, creator:string}>
Returns:
Type
Promise.<({id:string, start:string}|null)>

showScrollDialog(url, title)

Description:
  • Show a scroll's HTML page in a simple modal dialog.

Source:
Parameters:
Name Type Description
url string

full URL of the HTML page to display

title string

scroll name shown in the dialog header

showWinDialog(url, onCloseopt)

Description:
  • Show the win screen with an iframe pointing to the win URL.

Source:
Parameters:
Name Type Attributes Description
url string

relative or absolute URL for the win HTML page

onClose function <optional>

stateFromString()

Description:
  • Parse a state string (case-insensitive) to a State constant.

Source: