Class

RezGame

RezGame()

Constructor

# new RezGame()

The central singleton that manages the entire game runtime. RezGame is automatically instantiated with id "game" and is accessible globally via $game.

RezGame provides:

  • Object Registry: All game objects are registered here and accessible via $() or getGameObject(). Objects are indexed by tags and attributes for fast lookup.
  • Scene Management: Controls scene transitions (startSceneWithId), interludes (interludeSceneWithId), and resumption (resumePrevScene) with a scene stack.
  • View System: Manages the RezView that renders content to the DOM, including layout management and bound control updates.
  • Persistence: Save/load functionality via save() and load() methods that serialize/deserialize all changed game object attributes.
  • Undo System: Tracks attribute changes and object creation/deletion for undo support.
  • Flash Messages: Temporary messages displayed on the next render cycle.
  • Systems: Manages enabled RezSystem objects that hook into game events.

The game is started by calling start(containerId) which initializes all objects, builds the view, and starts the initial scene.

View Source rez_game.js, line 5

Extends

Members

# globalBindings

Frozen map of element id to element for every $global: true element. Built once during game initialization (global elements cannot be created or replaced at runtime) and used as the lowest-priority layer of template bindings.

Properties:
Name Type Description
globalBindings Object

View Source rez_game.js, line 67

Methods

# addFlashMessage(message)

adds the given message to the flash to be displayed on the next render

Parameters:
Name Type Description
message string

View Source rez_game.js, line 895

# addGameObject(obj)

adds an object representing a game element to the game world and automatically tagging it by its attributes

Parameters:
Name Type Description
obj object

game-object

View Source rez_game.js, line 386

# addToTagIndex(obj)

indexes the specified game-object for all tags in its tags attribute

Parameters:
Name Type Description
obj object

game-object

View Source rez_game.js, line 360

# broadcastLifecycle(eventName, paramsopt) → {*}

Dispatches a game-level lifecycle event, notifying every enabled system before and after the event is handled. Each enabled system's before_lifecycle_event(system, eventName, params) is called (in priority order) before the game's own on_<eventName> handler runs, and its after_lifecycle_event(system, eventName, params, result) is called afterwards.

This is the second system path, parallel to before_event/after_event: where those wrap the six originating browser events, this wraps the game's lifecycle broadcasts (scene/card transitions and renders) so systems can observe transitions they would otherwise be blind to. The contract is observe-only — return values from system handlers are not threaded back into dispatch, though handlers may mutate the shared params object.

Parameters:
Name Type Attributes Default Description
eventName string

the name of the lifecycle event (e.g. "card_will_start")

params object <optional>
{}

parameters associated with the lifecycle event

View Source rez_game.js, line 854

the result of the game's own on_ handler (or false if none)

*

# buildView()

Assigns the #view private attribute with a RezView that is initialized with a single layout.

View Source rez_game.js, line 835

# canResume() → {boolean}

returns true if there is at least one scene in the scene stack

View Source rez_game.js, line 709

boolean

# clearBanner()

Clears any active banner

View Source rez_game.js, line 928

# clearFlashMessages()

empties the flash messages

View Source rez_game.js, line 905

# clearModal()

Clears any active modal (message or card)

View Source rez_game.js, line 947

# elementAttributeHasChanged(elem, attr_name, old_value, new_value)

should be called whenever an attribute value is changed

Currently this function notifies the undo manager and the view

Parameters:
Name Type Description
elem object

reference to game-object

attr_name string

name of the attribute whose value has changed

old_value *

value of the attribute before the change

new_value *

value of the attribute after the change

View Source rez_game.js, line 481

# filterObjects(pred) → {array}

filters all game-objects returning those for which the pred filter returns true

Parameters:
Name Type Description
pred function

predicate to filter with

View Source rez_game.js, line 542

game-objects passing the filter

array

# getAll(element) → {array}

filters all game-objects returning those with the specified type

Parameters:
Name Type Description
element string

(optional) a specific game element type (e.g. 'actor', 'item')

View Source rez_game.js, line 558

game-objects with the specified type

array

# getEnabledSystems() → {array}

View Source rez_game.js, line 843

all 'system' game-objects with attribute enabled=true

array

# getGameObject(idOrRef, should_throw) → {basic_object|undefined}

given an element id returns the appropriate game-object reference

Accepts both plain string IDs and {$ref: "id"} objects for backward compatibility. If should_throw is true an exception will be thrown if the element id is not valid. Otherwise undefined is returned.

Parameters:
Name Type Description
idOrRef string | object

either a string ID or a {$ref: "id"} object

should_throw boolean

(default: true)

View Source rez_game.js, line 436

game-object or undefined

basic_object | undefined

# getObjectsWithAttr(attrName) → {array}

Scans the game objects for those that define the attribute, so the result always reflects the attributes objects have right now, including attributes added after the object was created. Template objects are not included.

Cost is proportional to the number of game objects, so keep the result if you need it more than once in a handler. Attributes provided by mixins do not appear in an object's own attributes and so may not be found.

Parameters:
Name Type Description
attrName string

name of the attribute

View Source rez_game.js, line 302

ids of all game elements having the specified attribute

array
Example
$game.getObjectsWithAttr("behaviours").forEach((id) => {
  $(id).behaviours.executeBehaviour(wmem);
});

# getObjectsWithTag(tag) → {array}

returns all game-objects tagged with the specified tag

Parameters:
Name Type Description
tag string

View Source rez_game.js, line 286

array of indexed game-objects that have the specified tag

array

# getRelationship(source_id, target_id) → {RezRelationship|null}

we can cheat looking up a relationship because we know how their IDs are constructed.

Note that in Rez relationships are unidirectional so that getRelationship("a", "b") and getRelationship("b", "a") are different RezRelationship objects.

Parameters:
Name Type Description
source_id string

id of game-object that holds the relationship

target_id string

id of game-object to which the relationship refers

View Source rez_game.js, line 500

the relationship object for this relationship

RezRelationship | null

# getTypedGameObject(id, type, should_throw) → {basic_object|undefined}

Parameters:
Name Type Description
id string

id of game-object

type string

game object type (e.g. 'actor' or 'item')

should_throw boolean

(default: true)

View Source rez_game.js, line 461

game-object or undefined

basic_object | undefined

# indexObjectForTag(obj, tag)

applies the specified tag to the specified game-object

Parameters:
Name Type Description
obj object

reference to a game-object

tag string

View Source rez_game.js, line 325

# installWindowEvents()

Reads the $window_events attribute and installs window-level event listeners that route through the event processor's custom event handling. Each event name in the list (e.g. "wheel") maps to a handler named "on_window_<event_name>" (e.g. "on_window_wheel").

View Source rez_game.js, line 753

# interludeSceneWithId(scene_id, params)

interrupts the current scene, pushing it to the scene stack, and then starts the new scene with the given id

Parameters:
Name Type Description
scene_id string
params object

data to pass to the new scene

View Source rez_game.js, line 614

# isGameObjectRef(id) → {boolean}

given a string return true if it corresponds to a known game element

Parameters:
Name Type Description
id string

to test

View Source rez_game.js, line 425

true if a known game object, otherwise false

boolean

# load(source)

given a JSON source archive restore the game state to what was archived. Sets in the archive are restored as Sets, and an object whose tags were archived has the tag index rebuilt to match.

Parameters:
Name Type Description
source string

JSON format source archive

View Source rez_game.js, line 180

# playCardWithId(cardId, params)

tells the current scene to start a new card

Parameters:
Name Type Description
cardId string

id of a @card object

params object

data to the pass to the new

View Source rez_game.js, line 572

# popScene(params)

removes the top object of the scene stack and makes it the current scene

Parameters:
Name Type Description
params object

data to be passed to the scene being resumed

View Source rez_game.js, line 731

# pushScene()

interrupts the current scene and puts it on the scene stack

View Source rez_game.js, line 719

# reconstructObject(id, data, inProgressopt) → {RezBasicObject}

Rebuilds a procedurally-created object from a save archive. The object's $original_id identifies the template to copy from; if that template is itself a not-yet-rebuilt procedural object (e.g. someCopy.addCopy()), it is reconstructed first. Uses copyForLoad (structural-only re_init, no generative initializers) and the exact saved id. The archived attributes are applied separately by load().

Parameters:
Name Type Attributes Description
id string

id of the procedural object to rebuild

data object

the full data archive (id -> archived attributes)

inProgress Set <optional>

guards against cyclic template references

View Source rez_game.js, line 245

the reconstructed (and registered) object

# removeFromTagIndex(obj)

unindexes the specified object from all tags in its tags attribute

Parameters:
Name Type Description
obj object

game-object

View Source rez_game.js, line 373

# resumePrevScene(params)

finishes the current scene, then pops the previous scene from the scene stack and resumes it

Parameters:
Name Type Description
params object

data to pass back to the previous scene

View Source rez_game.js, line 630

# save()

triggers a download of the game archive

This uses a hidden link with a 'download' attribute. The link is "clicked" triggering the download of the JSON file. A timeout is used to remove the link.

View Source rez_game.js, line 145

# setBanner(config)

Sets the current banner message and schedules its auto-dismissal

Parameters:
Name Type Description
config object

banner config with message, cssClass, onscreen (ms), dark, and vpos (percent of viewport height)

View Source rez_game.js, line 914

# setModal(config)

Sets the current modal message to be displayed on the next render

Parameters:
Name Type Description
config object

modal config with message and optional title

View Source rez_game.js, line 937

# setModalCard(config)

Sets the current modal card to be displayed on the next render

Parameters:
Name Type Description
config object

modal card config with cardId and params

View Source rez_game.js, line 957

# setProcessing(processing)

Reflects the event processor's busy state. Stores a plain $processing flag (not a tracked attribute — it does not trigger re-render or bound-control updates, so it is only meaningful to templates that re-render for other reasons) and asks the view to toggle its rez-busy CSS hook, which CSS can use to disable or dim controls while the player's input is gated.

Parameters:
Name Type Description
processing boolean

whether a queued event sequence is in flight

View Source rez_game.js, line 967

# setViewLayout(layout)

set the view layout that will be rendered by updateView

Parameters:
Name Type Description
layout RezLayout

View Source rez_game.js, line 743

# start(container_id)

called automatically from the index.html this runs init on the registered game objects then starts the view and starts the initial scene

Parameters:
Name Type Description
container_id string

id of the HTML element into which game content is rendered

View Source rez_game.js, line 774

# startSceneWithId(scene_id, params)

finish the current scene and start the new scene with the given id

Parameters:
Name Type Description
scene_id string

id of scene game-object

params object

data to pass to the new scene

View Source rez_game.js, line 596

# unindexObjectForTag(obj, tag)

removes the specified tag from the specified game-object

Parameters:
Name Type Description
obj object

reference to a game-object

tag string

a tag to remove

View Source rez_game.js, line 342

# unmapObject(obj)

removes a game object from the object registry.

Parameters:
Name Type Description
obj object

game-object

View Source rez_game.js, line 405

# updateView()

re-renders the view calling 'will_render' and 'did_render' event handlers on both game and current scene

View Source rez_game.js, line 685

# static setGlobalBindings(bindings)

Installs the global bindings map. Called once from generated init code.

Parameters:
Name Type Description
bindings Object

map of element id to element

View Source rez_game.js, line 71