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 794

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

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

# addToTagIndex(obj)

indexes the specified game-object for all tags in it's tags attribute

Parameters:
Name Type Description
obj object

game-object

View Source rez_game.js, line 311

# buildView()

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

View Source rez_game.js, line 775

# canResume() → {boolean}

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

View Source rez_game.js, line 647

boolean

# clearFlashMessages()

empties the flash messages

View Source rez_game.js, line 804

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

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

game-objects passing the filter

array

# getAll(target_type) → {array}

filters all game-objects returning those with the specified type

Parameters:
Name Type Description
target_type string

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

View Source rez_game.js, line 506

game-objects with the specified type

array

# getEnabledSystems() → {array}

View Source rez_game.js, line 783

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 null 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 389

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 199

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 453

the relationship object for this relationship

RezRelationship | null

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

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 414

game-object or null

basic_object | null

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

# indexObjectForTag(obj, tag)

applies the specified tag to the spectified game-object

Parameters:
Name Type Description
obj object

reference to a game-object

tag string

View Source rez_game.js, line 276

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

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

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

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 156

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

# pushScene()

interrupts the current scene and puts it on the scene stack

View Source rez_game.js, line 657

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

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

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

# setViewLayout(layout)

???

Parameters:
Name Type Description
layout *

???

View Source rez_game.js, line 681

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

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

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

# unmapObject(obj)

removes a game object from the object registry.

Parameters:
Name Type Description
obj object

game-object

View Source rez_game.js, line 357

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