Members
game :Game
Global game object used to track one interactive story fiction game
Type:
includes_to_load :int
Number of x-include tags left to load before game can run
Type:
- int
is_mobile :boolean
Flag used to tell if current user is interacting on a mobile device or not
Type:
- boolean
is_right_to_left :boolean
Flag to set the text direction of the game to right-to-left.
(if false, the text direction is left-to-right)
Type:
- boolean
locale :string
Locale to use when looking up strings to be output in a particular language.
We set the default here, but a particular game can override this in
its script tag before calling initGame()
Type:
- string
object_counter :number
Used as part of the closure of makeGameObject so that every game
object has an integer id.
Type:
- number
tl :Object
Contains {locale => {to_translate_id => translation}} for each
item in the game engine that needs to be localized.
There are not too many strings to translate. For a particular game you
could tack on to this tl variable after you load game.js in a script
tag before you call initGame.
Type:
- Object
Methods
addListenersAnchors(anchors)
Adds click event listeners to all anchor objects in a list
that have href targets beginning with #. Such a target
is to a location within the current game, so the click event callback
then calls game.takeTurn based on this url.
Parameters:
| Name | Type | Description |
|---|---|---|
anchors |
NodeList | HTMLCollection | to add click listeners for game take turn callbacks. |
baseLoc()
Returns the Location object the player begins the game at
clickProceed(message, any) → {Promise}
Adds a link with link text message which when clicked will allow the
rendering of a Location to continue.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string | link text for the link that is pausing the rendering of the current location. |
any |
string | html that should appear after the proceed link |
Returns:
which will be resolved which the link is clicked.
- Type
- Promise
disableVolatileLinks()
Used to disable any volatile links which might cause
issues if clicked during rendering of the staging
portion of a presentation. For example, saves screen links
in either the main-nav panel/main-nav bar or in the
game content area. The current place where this is used
is at the start of rendering a location. A location
might have several x-present tags, some of which could
be drawn after a clickProceed, or a delay. As these
steps in rendering are not good "save places", at the
start of rendering a location, all save are disabled.
Only after the last drawable x-present for a location
has completed are they renabled.
doll(object_id) → {Location}
Returns the game doll (paperdoll) with the provided id.
Parameters:
| Name | Type | Description |
|---|---|---|
object_id |
string | to get game doll for |
Returns:
game doll associated with object_id if it exists
- Type
- Location
elt(id) → {Element}
Returns an Element object from the current document which has the provided
id.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | of element trying to get an object for |
Returns:
desired element, if exists, else null
- Type
- Element
enableVolatileLinks()
Used to re-enable any disabled volatile links
in either the main-nav panel/main-nav bar or in the
game content area. The current place where this is used
is at the end of rendering a location. For why this is called,
evaluateDataChecks(section) → {string}
A data-ck attribute on any tag other than an x-present tag can
contain a Javascript boolean expression to control the display
or non-display of that element. This is similar to a ck attribute
of an x-present tag. This method evalutes data-ck expressions for
each tag in the text in its section argument and adds a class="none"
attribute to that tag if it evaluates to false (causing it not to
display). The string after these substitutions is returned.
Parameters:
| Name | Type | Description |
|---|---|---|
section |
string | of text to check for data-ck attributes and for which to carry out the above described substitutions |
Returns:
after substitutions have been carried out.
- Type
- string
(async) finishInitGame()
This function is called after all images for Doll's have
loaded to finish initializing the Frise Game. To do this, if there is a
current game state in sessionStorage it is used to initialize the game
state, otherwise,* the game state is based on the start of the game. After
this state is set up, the current location is drawn to the game content area.
(async) finishInitSlides()
If the current game is a slideshow presentation
this function is called after all images for Doll's have
loaded to finish initializing the slides for the presentation. This
sets up the forward, backward, table of conents, all slides on a single
page, and reset buttons as well as keyboard listeners to go this through
slides
hasVisited(location_id) → {boolean}
Returns whether the main character has ever been to the location
given by location_id
Parameters:
| Name | Type | Description |
|---|---|---|
location_id |
string | id of location checking if main character has been to |
Returns:
whther the main chracter has been there
- Type
- boolean
here() → {Location}
Returns the location object associated with the main-character current
position.
Returns:
associated with main-character position
- Type
- Location
imageCoordinates(x, y, width, height, doll_part, of)
Given a rectangle within an Image object of a DollSlot doll_part
specified by a point x,y and a width and a height. Scales it to a
corresponding rectangle in the DollSlot coordinates (coordinates
used to specify where it is within a Doll).
Parameters:
| Name | Type | Description |
|---|---|---|
x |
int | coordinate of the image rectangle |
y |
int | coordinate of the image rectangle |
width |
int | of the image rectangle |
height |
int | of the image rectangle |
doll_part |
DollSlot | with respect to which the coordinate transformation is done |
of |
Array.<int> | length 4 containing output [x, y, width, height] |
(async) initGame()
Module initialization function used to set up the game object corresponding
to the current HTML document. It first loads any x-included game fragments
before calling @see finishInitGame to perform the rest of the game
initialization process
(async) initSlides()
This module initialization is called to initialize FRISE when it is being
used to show a slide presentation. It first loads any x-included slideshow
fragments before calling @see finishInitSlides to perform the rest of the
game initialization process
interpolateVariables(text) → {string}
Given a string which may contain Javascript string interpolation expressions,
i.e., ${some_expression}, produces a string where those expressions have
been replaced with their values.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | to have Javascript interpolation expressions replaced with their values |
Returns:
result of carrying out the replacement
- Type
- string
intersectRectangles(rect1, rect2) → {Array.<int>|boolean}
Given two rectangles: [x1, y1, width1, height1] and [x2, y2, width2, height2]
Computes an intersection [x_out, y_out, width_out, height_out] of the
rectangles if the rectangles intersect and outputs false otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
rect1 |
Array.<int> | 4-tuple [x1, y1, width1, height1] of first rectangle |
rect2 |
Array.<int> | 4-tuple [x1, y1, width1, height1] of second rectangle |
Returns:
4-tuple [x_out, y_out, width_out, height_out] of
intersection rectangle or false otherwise
- Type
- Array.<int> | boolean
isHere() → {boolean}
For use in default actions only!!! Returns whether the main-character is
in the Location of the default action. In all other cases returns false
Returns:
where the main-character is in the room of the current
default action
- Type
- boolean
(async) loadIncludes(callback)
Function used to load any x-included game fragments into this game.
This function is run before the rest of the game's initialization is
done in @see finishInitGame or finishInitSlides
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | called to complete game initialization after the included game fragments are laoded. This is typically either finishInitGame or finishInitSlides |
loc(object_id) → {Location}
Returns the game location with the provided id.
Parameters:
| Name | Type | Description |
|---|---|---|
object_id |
string | to get game Location for |
Returns:
game location associated with object_id if it exists
- Type
- Location
makeGameObject(DOMElement) → {Object}
Used to convert a DOM Element dom_object to an Object or Location suitable
for a FRISE game. dom_object's whose tagName does not begin with x-
will result in null being returned. If the tagName is x-location, a
Location object will be returned, otherwise, a Javascript Object is returned.
The innerHTML of any subtag of an x-object or an
x-location beginning with x- becomes the value of a field in the resulting
object with the name of the tag less x-. For example, a DOM Object
representing the following HTML code:
Robert Smith
25
will be processed to a Javascript Object
{
id: "bob",
name: "Robert Smith",
age: "25"
}
Parameters:
| Name | Type | Description |
|---|---|---|
DOMElement |
Element | to be convert into a FRISE game Object or Location |
Returns:
the resulting FRISE game Object or Location or
null if the tagName of the DOMElement didn't begin with x-
- Type
- Object
makeGameObjects(tag_objects) → {Array}
Creates from an HTMLCollection or Nodelist of x-object or x-location
elements an array of Location's or Object's suitable for a FRISE Game
object. Elements of the collection whose name aren't of the form x-
or which don't have id's are ignored. Otherwise, the id field of
the output Object or Location is set to the value of the x-object or
x-location's id. Details about how a suitable FRISE Game object is created
can be found @see makeGameObject()
Parameters:
| Name | Type | Description |
|---|---|---|
tag_objects |
HTMLCollection | Nodelist | collection to be converted into an array FRISE game objects or location objects. |
Returns:
an array of FRISE game or location objects.
- Type
- Array
mc() → {object}
Returns the game object associated with the main-character. This
function is just an abbreviation for obj('main-character')
Returns:
game object associated with main-character
- Type
- object
obj(object_id) → {object}
Returns the game object with the provided id.
Parameters:
| Name | Type | Description |
|---|---|---|
object_id |
string | to get game object for |
Returns:
game object associated with object_id if it exists
- Type
- object
parseObjectsInts(Array
Given an array of arrays [Object, property_name1, property_name2, ...]
Parses the property names to int's in the given object. If the
this results in Not a Number (NaN) then sets the property to the
provided default value
Parameters:
| Name | Type | Description |
|---|---|---|
Array |
String...>> | |
int |
default_value |
sel(a) → {NodeList}
Returns a list of Node's which match the CSS selector string provided.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
string | CSS selector string to match against current document |
Returns:
of matching Element's
- Type
- NodeList
sleep(time) → {Promise}
Sleep time many milliseconds before continuing to execute whatever code was
executing. This function returns a Promise so needs to be executed with await
so that the code following the sleep statement will be used to resolve the
Promise
Parameters:
| Name | Type | Description |
|---|---|---|
time |
number | time in milliseconds to sleep for |
Returns:
a promise whose resolve callback is to be executed after
that many milliseconds.
- Type
- Promise
tag(name) → {HTMLCollection}
Returns a collection of objects for Element's that match the provided Element
name in the current document.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | of HTML/XML Element wanted from current document |
Returns:
of matching Element's
- Type
- HTMLCollection
toggleDisplay(id, display_type)
Used to change the display css property of the element of the provided id
to display_type if it doesn't already have that value, if it does,
then the display property is set to none. If display_type is not provided
then its value is assumed to be block.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
id |
string | of HTML Element to toggle display property of | |
display_type |
string | block | value to toggle between it and none. |
toggleMainNav()
Used to toggle the display or non-display of the main navigation bar
on the side of game screen
upperFirst(str) → {string}
Upper cases first letter of a string
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | string to upper case the first letter of |
Returns:
result of upper-casing
- Type
- string
xelt(id) → {Object}
Returns a game object based on the element in the current document of the
provided id.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | of element in current document. |
Returns:
a game object.
- Type
- Object
xsel(a) → {Array}
Returns an array of game objects based on the elements in the current
document that match the CSS selector passed to it.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
string | CSS selector for objects in the current document |
Returns:
of game objects based on the tags that matched the selector
- Type
- Array
xtag(a) → {Array}
Returns an array of game objects based on the elements in the current
document of the given tag name.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
string | name of a tag such as x-location or x-object. |
Returns:
of game objects based on the tags that matched the selector
- Type
- Array