Class: Genmo

Genmo(storyData, opts)

new Genmo(storyData, opts)

Creates a Genmo Object based on storyData, a JSON object created using the Twison format in Twine

Parameters:
Name Type Description
storyData StoryData
opts GenmoOptions
Properties:
Name Type Description
outputFunction function
errorFunction function
Source:
Throws:

Extends

Classes

Genmo

Methods

addHelper(helperName, helperFn)

Adds a Handlebars helper with the name helperName.
If a helper already existed at helperName, it is overwritten.

Parameters:
Name Type Description
helperName String
helperFn function
Source:

addInventory(item)

Parameters:
Name Type Description
item String
Source:

addReducer(fn)

Adds a reducer which will be called whenever an action is dispatched

Parameters:
Name Type Description
fn function
Overrides:
Source:

doAction(action, callbackopt, …callbackArgsopt)

Applies an action to the state, via the currently registered reducers.
If a reducer throws an error, it is caught and sent to onError

Once all reducers have been called, the action is pushed onto actions (to allow inspecting previous actions).

After everything, the callback is called, if provided

Parameters:
Name Type Attributes Description
action Object
callback function <optional>
callbackArgs any <optional>
<repeatable>
Overrides:
Source:

Follows the given link or pid to the next passage.

The link must exist on the current passage (getCurrentPassage()). Otherwise an error will be sent to errorFunction.
An error will also be sent if the linked to passage doesn't exist.

Parameters:
Name Type Attributes Description
link Passage | Pid
callback function <optional>
callbackArgs any <optional>
<repeatable>
Source:
Throws:

getCurrentPassage() → {Passage}

Returns current passage. This function also appends passageText (with data and helpers replaced), and filters links

Source:
Returns:
Type
Passage

getData() → {Object}

Returns Genmo's custom data

Source:
Returns:
Type
Object

getInventory() → {Object}

Returns the inventory

Source:
Returns:
Type
Object

getItem(item) → {Number|null}

Parameters:
Name Type Description
item String
Source:
Returns:

the quantity of item, null if the item isn't in the inventory at all.

Type
Number | null

getPassage(passageOrPid) → {Passage}

Returns the passage indicated by passageOrPid, with passageText set and passage.link properly filtered.
Returns null if passage is not found.

Parameters:
Name Type Description
passageOrPid Passage | Pid
Source:
Returns:
Type
Passage

getPassageByName(name) → {Passage}

Returns a passage with the name property set to name, or null if it doesn't exist.

Parameters:
Name Type Description
name String
Source:
Returns:
Type
Passage

getPassageData(passage) → {Object}

Gets the passage_data object for the current passage, or an empty Object if it isn't set.
If passage is not specified, currentPassage is used instead.

Parameters:
Name Type Description
passage Passage | null
Source:
Returns:
Type
Object

getPassageText(passage) → {String}

Returns just the text of the passage, with variables replaced and helpers processed.
If passage is not specified, currentPassage is used instead.

Parameters:
Name Type Description
passage Passage | null
Source:
Returns:
Type
String

getPreviousState() → {Object|null}

Returns the update previous to the current one. If there was no previous state (e.g. there were no updates yet), returns null.

Overrides:
Source:
Returns:
Type
Object | null

getRawPassageData(passage) → {Object|null}

Returns the data object associated with this passage, if it exists.
If passage is not specified, currentPassage is used instead.

Parameters:
Name Type Description
passage Passage | null
Source:
Returns:
Type
Object | null

hasItem(item) → {Boolean}

Returns whether the item a) exists in the inventory and b) the player has more than 0 of that item

Parameters:
Name Type Description
item String
Source:
Returns:
Type
Boolean

helperWrapper(helperFn)

Returns a function that wraps the helper function, forwarding Handlebars'
options object (as handlebarsOptions) and passing a second argument,
an object containing genmo which refers to this instance.

Parameters:
Name Type Description
helperFn function
Source:
Returns:

Function

isValidPassage(passage) → {Boolean}

Returns whether this passage is valid or not. A valid passage is an object that has a key pid that matches an object in state.storyData.passages

Parameters:
Name Type Description
passage Passage | null
Source:
Returns:
Type
Boolean

outputCurrentPassage() → {any}

Calls the provided outputFunction during construction with the current passage.
If outputFunction returned something, this returns that as well.

Source:
Returns:
Type
any

removeHelper(helperName)

Removes a Handlebars helpers with the name helperName,
if it exists.

Parameters:
Name Type Description
helperName String
Source:

removeInventory(item)

Parameters:
Name Type Description
item String
Source:

respondToPrompt(response, callbackopt, …callbackArgsopt)

When a passage requires a prompt, this function will add the response to the story's state.data

Parameters:
Name Type Attributes Description
response String
callback function <optional>
callbackArgs any <optional>
<repeatable>
Source:

setData(data)

Merges data with Genmo's state.data

Parameters:
Name Type Description
data Object
Source:

setState(newState, callbackopt)

Merges newState into state, then calls callback if provided.

Parameters:
Name Type Attributes Description
newState Object
callback function <optional>
Overrides:
Source:

updateInventory(items)

Directly adds quantities of items to the inventory. The items object uses the item name as key, and the quantity change as value.

Parameters:
Name Type Description
items Object
Source:
Example
const newItems = {
 toy: 1,
 coin: -2,
}
updateInventory(newItems);
// This will add one `toy` and remove 2 `coins`