# 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
$()orgetGameObject(). 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()andload()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.
Extends
Methods
# addFlashMessage(message)
adds the given message to the flash to be displayed on the next render
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
# 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 |
# 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 |
# addToTagIndex(obj)
indexes the specified game-object for all tags in it's tags attribute
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object
|
game-object |
# buildView()
Assigns the #view private attribute with a RezView that is initialized with a single layout.
# 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 |
# 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 |
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') |
game-objects with the specified type
array
# getEnabledSystems() → {array}
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) |
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
|
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 |
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) |
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
|
# 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
|
# 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").
# 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 |
# isGameObjectRef(id) → {boolean}
given a string return true if it corresponds to a known game element
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string
|
to test |
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 |
# 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 |
# pushScene()
interrupts the current scene and puts it on the scene stack
# removeFromTagIndex(obj)
unindexes the specified object from all tags in its tags attribute
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object
|
game-object |
# 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 |
# 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.
# 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 |
# 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 |
# 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 |
# unmapObject(obj)
removes a game object from the object registry.
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object
|
game-object |
# updateView()
re-renders the view calling 'will_render' and 'did_render' event handlers on both game and current scene