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  | |
| 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 | Returns  | |
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:
| Name | Type | Attribute | Description | 
| 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
      | |
| 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  | |
| 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  | |
| getCanSee | function(model: model, hostSituation: Situation): Boolean | If this function is provided and returns  | |
| 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  | |
| 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 | 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"),
 }); 
    
  