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

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 896

# 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 385

# addToAttrIndex(elem)

For each attribute defined on this game object, add it to the game-wide index for that attribute.

Parameters:
Name Type Description
elem basic_object

element whose attributes are to be indexed

View Source rez_game.js, line 273

# 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 359

# 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 855

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 836

# canResume() → {boolean}

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

View Source rez_game.js, line 710

boolean

# clearBanner()

Clears any active banner

View Source rez_game.js, line 929

# clearFlashMessages()

empties the flash messages

View Source rez_game.js, line 906

# clearModal()

Clears any active modal (message or card)

View Source rez_game.js, line 948

# 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 482

# 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 543

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 559

game-objects with the specified type

array

# getEnabledSystems() → {array}

View Source rez_game.js, line 844

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 437

game-object or undefined

basic_object | undefined

# getObjectsWithTag(tag) → {array}

returns all game-objects tagged with the specified tag

Parameters:
Name Type Description
tag string

View Source rez_game.js, line 249

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 501

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 462

game-object or undefined

basic_object | undefined

# indexAttribute(elem_id, attr_name)

Adds the element to the per-attribute index.

Parameters:
Name Type Description
elem_id string

id of element to add to the per-attr index

attr_name string

View Source rez_game.js, line 295

# 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 324

# 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 754

# 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 615

# 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 426

true if a known game object, otherwise false

boolean

# load(source)

given a JSON source archive restore the game state to what was archived.

Parameters:
Name Type Description
source string

JSON format source archive

View Source rez_game.js, line 160

# 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 573

# 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 732

# pushScene()

interrupts the current scene and puts it on the scene stack

View Source rez_game.js, line 720

# 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 208

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 372

# 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 631

# 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 125

# 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 915

# 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 938

# 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 958

# 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 968

# setViewLayout(layout)

set the view layout that will be rendered by updateView

Parameters:
Name Type Description
layout RezLayout

View Source rez_game.js, line 744

# 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 775

# 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 597

# 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 341

# 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 686