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

Situation

Constructor Summary

Public Constructor
public

constructor(args: object, getCanChoose: function(model: model, hostSituation: Situation): Boolean, getCanSee: function(model: model, hostSituation: Situation): Boolean, priority: number | function(model: model, hostSituation: Situation): number, displayOrder: number | function(model: model, hostSituation: Situation): number, optionText: string | function(model: model, hostSituation: Situation): string, willEnter: function(model: model, ui: ui, fromSituation: Situation): Boolean, enter: function(model: model, ui: ui, fromSituation: Situation), exit: function(model: model, ui: ui, toSituation: Situation), act: function(model: model, ui: ui, action: String), actions: Map<string, function>)

Member Summary

Public Members
public

If true, then presenting choices from this situation will call debugger so you can step through the code and see what's up.

public

ID of this situation.

public

Tags associated with this situation.

public

Number of times this situation has been successfully entered.

Method Summary

Public Methods
public

hasTag(tag: string): bool

Returns true if this situation has the given tag, otherwise false.

Public Constructors

public constructor(args: object, getCanChoose: function(model: model, hostSituation: Situation): Boolean, getCanSee: function(model: model, hostSituation: Situation): Boolean, priority: number | function(model: model, hostSituation: Situation): number, displayOrder: number | function(model: model, hostSituation: Situation): number, optionText: string | function(model: model, hostSituation: Situation): string, willEnter: function(model: model, ui: ui, fromSituation: Situation): Boolean, enter: function(model: model, ui: ui, fromSituation: Situation), exit: function(model: model, ui: ui, toSituation: Situation), act: function(model: model, ui: ui, action: String), actions: Map<string, function>) source

Params:

NameTypeAttributeDescription
args object
args.id string
args.autosave Boolean

If true, game will save when scene is entered. Default false.

args.autosave Boolean

If true, transcript will be cleared when scene is entered. Default false.

args.content string

Markdown template to be rendered to the transcript when this situation is entered. {@see /markup.html}

args.choices string[]

List of situation IDs or tags. See model#interpretChoices for how this works.

args.snippets Map<string, string>

Snippets used by writers/replacers. {@see /writers_replacers.html}.

args.input object | null

If provided, prompts user for input. Looks like input: {placeholder: "Your name", next: "situation-id", store: function(model, value)}

args.input.placeholder string | null

Placeholder value for the HTML input field

args.input.next string

Situation or action to go to after user enters a value. Must start with either @ (for situation IDs) or > (for actions).

args.input.store function(model: model, value: string)

Your chance to do something with the given alue

args.debugChoices Boolean

See debugChoices

getCanChoose function(model: model, hostSituation: Situation): Boolean

If this function is provided and returns false, this situation is not linkified in the choices list.

getCanSee function(model: model, hostSituation: Situation): Boolean

If this function is provided and returns false, the situation will not show up in the choices list for the situation presenting the choice.

priority number | function(model: model, hostSituation: Situation): number

May be a constant number, or function returning a number. This value is used by model#interpretChoices.

displayOrder number | function(model: model, hostSituation: Situation): number

May be a constant number, or function returning a number. This value is used by model#interpretChoices.

optionText string | function(model: model, hostSituation: Situation): string

Text shown to user when being presented as a choice.

willEnter function(model: model, ui: ui, fromSituation: Situation): Boolean

This situation will enter, unless this function returns false. It is safe to call model.do() from here, as long as you then return false.

enter function(model: model, ui: ui, fromSituation: Situation)

The situation has been entered, and Situation#content has been written to the transcript.

exit function(model: model, ui: ui, toSituation: Situation)

The situation is being exited, but the next situation has not yet been entered.

act function(model: model, ui: ui, action: String)

An action-based link has been clicked. You might just want to use the actions key instead of this function if you're just mapping action names to functions.

actions Map<string, function>

Map of action name to function that is called when the user invokes the action.

Example:

 jumbogrove('#app', {
     id: 'situations-example',
     autosave: true,

     // stuff related to this situation being a choice in another situation:
     optionText: "Proclaim hungriness",
     getCanChoose: (model, host) => true,
     getCanSee: (model, host) => true,
     priority: 1,
     displayOrder: 1,

     // stuff related to content and what happens inside the situation:
     content: `
     I am [very](>replaceself:more_adjectives) hungry.

     [Eat](>eat)

     [Go to restaurant](@restaurant)
     `,
     snippets: {
         more_adjectives: "very, very, very, very"
     },
     act: (model, ui, action) => console.log("did action", action),
     actions: {
         eat: () => console.log("OM NOM NOM"),
     },

     // going to other situations:
     choices: ['next-situation', '#situations-involving-food'],
     // normally you wouldn't have 'choices' and 'input' in the same situation.
     input: {
         placeholder: "Please enter your favorite food.",
         next: "@restaurant",
     },
     debugChoices: false,

     // lifecycle
     willEnter: (model, ui, from) => true,
     enter: (model, ui, from) => console.log("entered"),
     exit: (model, ui, from) => console.log("exited"),
 });

Public Members

public debugChoices: Boolean source

If true, then presenting choices from this situation will call debugger so you can step through the code and see what's up.

public id: string source

ID of this situation.

public tags: string[] source

Tags associated with this situation.

public totalVisits: number source

Number of times this situation has been successfully entered. This value persists when saving and loading.

Public Methods

public hasTag(tag: string): bool source

Returns true if this situation has the given tag, otherwise false.

Params:

NameTypeAttributeDescription
tag string

The tag to check for

Return:

bool