Constructor
new Game()
Sets up a game object with empty history, an initialized main navigation,
and with objects and locations parsed out of the current HTML file
Members
base_location :String
Id of first room main-character is in;
Type:
- String
future_history :Array
Used to maintain a stack (using Array push/pop) of Game State Objects
based on the the number previous turn clicks the user has done.
I.e., when a user clicks previous turn, the current state is pushed onto
this array so that if the user then clicks next turn the current
state can be restored.
A Game State Object is a serialized string:
{
timestamp: capture_time,
objects: array_of_game_objects_at_capture_time,
locations: array_of_game_locations_at_capture_time,
}
Type:
- Array
has_nav_bar :boolean
Whether this particular game has a nav bar or not
Type:
- boolean
history :Array
Used to maintain a stack (using Array push/pop) of Game State Objects
based on the turns the user has taken (the top of the stack corresponds
to the previous turn). A Game State Object is a serialized string:
{
timestamp: capture_time,
objects: array_of_game_objects_at_capture_time,
locations: array_of_game_locations_at_capture_time,
}
Type:
- Array
id :string
A semi-unique identifier for this particular game to try to ensure
two different games hosted in the same folder don't collide in
sessionStorage.
Type:
- string
is_here :Boolean
Is set to true just before a default action for a location the
main character is at is executed; otherwise, false
Type:
- Boolean
locations :Array.<Location>
List of all game Location's managed by the FRISE script. A Location
can be used to represent a place the main character can go. This
could be standard locations in the game, as well as Locations
like a Save page, Inventory page, Status page, etc.
In an HTML document a game Location is defined using an x-location tag.
Type:
- Array.<Location>
objects :Array.<Object>
List of all Game Object's managed by the FRISE script. An object
can be used to represent a thing such as a person, tool, piece of
clothing, letter, etc. In an HTML document, a game object is defined
using an x-object tag.
Type:
- Array.<Object>
reload :bool
Whether game page was just reloaded
Type:
- bool
tick :number
A counter that is incremented each time Javascript draws a new
clickProceed a tag. Each such tag is given an id, tick is used to ensure
these id's are unique.
Type:
- number
timestamp :number
Current date followed by a space followed by the current time of
the most recent game capture. Used in providing a description of
game saves.
Type:
- number
volatile_links :Array
List of id's of buttons and links to disable during the staging
phases of rendering a presentation or when viewing those locations.
Type:
- Array
Methods
captureState() → {string}
Creates a JSON encoded string representing the current state of
the game (all of the object and location states and where the main
character is).
Returns:
JSON encoded current state of game.
- Type
- string
clearHistory()
Deletes the game state capture history for the game. After this
calling this method, the game's next and previous arrow buttons
won't do anything until new turns have occurred.
debug()
Writes to console information about which objects and locations
might not be properly defined.
deleteSlot(slot_number)
Deletes any game data from sessionStorage at location
"slot" + slot_number, updates the game's saves location to reflect the
change.
Parameters:
Name | Type | Description |
---|---|---|
slot_number |
number | which save game to delete. Games are stored at a sessionStorage field "slot" + slot_number where it is intended (but not enforced) that the slot_number be an integer. |
deleteSlotAll()
Deletes all game saves from sessionStorage
describeMainCharacterLocation()
Used to present the location that the Main Character is currently at.
evaluateAction(Javascript)
Given a string holding pre-Javascript code from an x-action tag,
evaluates the code. If this function is passed additional arguments
then an args array is set up that can be used as a closure variable for
this eval call.
Parameters:
Name | Type | Description |
---|---|---|
Javascript |
string | code. |
evaluateDefaultActions(of)
For each game Object and each game Location in x_entities evaluate the
Javascript (if it exists) of its default action (from its
x-default-action tag).
Parameters:
Name | Type | Description |
---|---|---|
of |
Array | game Object's or Location's |
initSlotStates()
Initializes the save slots for the saves location page of a game.
This involves looking at session storage and determining which slots
have games already saved to them, and for those slots, determining also
what time the game was saved.
initializeGameNavListeners()
Used to initialize the event listeners for the next/previous history
buttons. It also adds listeners to all the a tag and x-button tags
to process their href attributes before following any link is followed
to its target.
- Source:
- See:
initializeMainNavGameContentArea()
Sets up the main navigation bar and menu on the side of the screen
determined by the is_right_to_left variable. Sets up an initially empty
game content area which can be written to by calling a Location
object's renderPresentation. The main navigation consists of a hamburger
menu toggle button for the navigation as well as previous
and next history arrows at the top of screen. The rest of the main
navigation content is determined by the contents of the x-main-nav
tag in the HTML file for the game. If this tag is not present, the
game will not have a main navigation bar and menu.
initializeObjectsLocations()
For each object, if object.position is defined, then adds the object
to the location.item array of the Location whose id is
given by object.position .
initializeScreen()
Checks if the game is being played on a mobile device. If not, this
method does nothing, If it is being played on a mobile device,
then this method sets up the viewport so that the HTML will
display properly. Also, in the case where the game is being played on a
mobile device, this method also sets it so the main nav bar on the side
of the screen is closed.
load()
Launches a file picker to allow the user to select a file
containing a saved game state, then tries to load the current game
from this file.
moveMainCharacter(hash)
Moves the main character according to the provided url fragment.
Parameters:
Name | Type | Description |
---|---|---|
hash |
string | a url fragment as described above |
moveObject(object_id, destination_id)
Moves a game Object to a new game Location. If the object had a
previous location, then also deletes the object from there.
Parameters:
Name | Type | Description |
---|---|---|
object_id |
string | of game Object to move |
destination_id |
string | of game Location to move it to |
nextHistory()
Called when the right arrow button on the main nav page is
clicked to go forward one turn in the game history (assuming the user had
clicked previous at least once). Pushes the current game state
to the history game state array, then pops the game state from the
future_history game state array and sets it as the current state.
previousHistory()
Called when the left arrow button on the main nav page is
clicked to go back one turn in the game history. Pushes the current
game state to the future_history game state array, then pops the most
recent game state from the history game state array and sets it as
the current state.
reset()
Used to reset the game to the condition at the start of a game
restoreState(gave_save)
Sets the current state of the game (current settings for all objects,
locations, and main character position), based on the state given in
a JSON encode string representing a game state.
Parameters:
Name | Type | Description |
---|---|---|
gave_save |
string | a JSON encoded state of the a FRISE game. |
save()
Creates a downloadable save file for the current game state.
saveLoadSlot(slot_number)
Saves the current game state to a sessionStorage save slot if that
slot if empty; otherwise, if the slot has data in it, then sets
the current game state to the state stored at that slot. When saving,
this method also records the timestamp of the save time to the
game's saves location.
Parameters:
Name | Type | Description |
---|---|---|
slot_number |
number |
takeTurn(hash)
Computes one turn of the current game based on the provided url hash
fragment. A url hash fragment is the part of the url after a # symbol.
In non-game HTML, #fragment is traditionally used to indicate the browser
should show the page as if it had been scrolled to where the element
with id attribute fragment is. In a FRISE game, a fragment has
the form #action_1_name;action_2_name;...;action_n_name;next_location_id
Such a fragment when processed by takeTurn will cause the Javascript in
x-action tags with id's action_1_name, action_2_name,...,action_n_name
to be invoked in turn. Then the main-character object is moved to
location next_location_id. If the fragment, only consists of
1 item, i.e., is of the form, #next_location_id, then this method
just moves the main-character to next_location_id.
After carrying out the action and moving the main-character,
takeTurn updates the game state history and future_history
accordingly. Then for each object and each location,
if the object/location, has an x-default-action tag, this default action
is executed. Finally, the Location of the main-character is presented
(its renderPresentation is called).
takeTurn supports two special case action #previous and #next
which move one step back or forward (if possible) in the Game state
history.
Parameters:
Name | Type | Description |
---|---|---|
hash |
string | url fragment ot use when computing one turn of the current game. |
volatileLinks() → {Array}
Return the array of link ids which should be disable while performing
the staging of a presentation
Returns:
- Type
- Array