Home Reference Source
import model from 'jumbogrove/src/jg/model.js'
public class | source

model

Maintains game state and allows you to make changes to it.

The model object is the primary way for you to interact with Jumbo Grove.

Member Summary

Public Members
public

List of all characters in the game.

public

The situation currently being run, or last seen by the user.

public

Store all non-character game state here; Must be JSON-safe! You may mutate this object freely as long as it is safe to convert it to JSON and back.

public

The character with ID 'player'.

Method Summary

Public Methods
public

character(id: string): *

Look up a character by ID.

public

do(string: command): *

Follow a Jumbo Grove link (@situation-id or >action).

public

Add arbitrary methods to the model object.

public

goTo(id: string): *

Go to the given sitaution (no @).

public

interpretChoices(arrayOfSituationIdsOrTags: string[], atLeast: number, atMost: number): *

Given a set of situations, do some smart stuff and return the situations that match the filter.

public

Returns true iff the given string can be handled by Jumbo Grove (rather than being a normal HTML link)

public

presentChoices(arrayOfSituationIdsOrTags: string[])

Given an array of tags or situation IDs (can be both in the same array), present the relevant choices in the transcript using the logic in model.interpretChoices, then go to the situation chosen by the player.

public

random(): *

Return a random number 0-1.

public

Looks up a situation by ID.

public

situations(idOrTag: string): Situation[]

Returns a list of all situations matching the given ID (foo) or tag (#foo).

Public Members

public allCharacters: Character[] source

List of all characters in the game.

public currentSituation: Situation | null source

The situation currently being run, or last seen by the user.

public globalState: * source

Store all non-character game state here; Must be JSON-safe! You may mutate this object freely as long as it is safe to convert it to JSON and back.

public player: Character | null source

The character with ID 'player'.

Public Methods

public character(id: string): * source

Look up a character by ID. Returns undefined if there isn't one.

Params:

NameTypeAttributeDescription
id string

Return:

*

public do(string: command): * source

Follow a Jumbo Grove link (@situation-id or >action).

Params:

NameTypeAttributeDescription
string command

Return:

*

public extend(fns: Map<string, function>) source

Add arbitrary methods to the model object. Since the model is passed to all callbacks, this is a good way to make convenient functions accessible.

Also, anything you pass here will also be provided to the template context.

Params:

NameTypeAttributeDescription
fns Map<string, function>

Mapping of name to function

public goTo(id: string): * source

Go to the given sitaution (no @).

Params:

NameTypeAttributeDescription
id string

Return:

*

public interpretChoices(arrayOfSituationIdsOrTags: string[], atLeast: number, atMost: number): * source

Given a set of situations, do some smart stuff and return the situations that match the filter.

  1. Filter out all situations for which situation.getCanSee(model, model.currentSituation, situation) returns false.
  2. Find the highest priority that matches a list of situations at least as big as atLeast.
  3. If there are more situations left than there are atMost, randomly remove some.
  4. Sort by situation.displayOrder.

Note that it is possible to end up with a list of situations for which getCanChoose() returned false for all of them!

This logic has been shamelessly stolen from Undum.

Params:

NameTypeAttributeDescription
arrayOfSituationIdsOrTags string[]

Like ['one-situation', '#situations-matching-this-tag']

atLeast number
atMost number

Return:

*

Returns true iff the given string can be handled by Jumbo Grove (rather than being a normal HTML link)

Params:

NameTypeAttributeDescription
string string

A string to check

Return:

Boolean

public presentChoices(arrayOfSituationIdsOrTags: string[]) source

Given an array of tags or situation IDs (can be both in the same array), present the relevant choices in the transcript using the logic in model.interpretChoices, then go to the situation chosen by the player.

Params:

NameTypeAttributeDescription
arrayOfSituationIdsOrTags string[]

Array of strings containing either #tags or situation-ids.

public random(): * source

Return a random number 0-1. Currently this just calls Math.random(), but in the future it might do something fancy with seeds that let you avoid save scumming.

Return:

*

public situation(id: string): Situation | null source

Looks up a situation by ID. Prints an error to the console if there isn't one.

Params:

NameTypeAttributeDescription
id string

Return:

Situation | null

Situation with the given ID

public situations(idOrTag: string): Situation[] source

Returns a list of all situations matching the given ID (foo) or tag (#foo).

Params:

NameTypeAttributeDescription
idOrTag string

Return:

Situation[]