Constructor
new StoryGraph(definitionopt)
| Name | Type | Attributes | Description |
|---|---|---|---|
definition | Object | <optional> |
- Source
Classes
Members
currentNodeId
Current dialogue node ID.
- Source
history
Sequence of visited node IDs in order.
- Source
state
Current story state ('unstarted', 'active', 'completed').
- Source
visitedNodes
Set of unique visited node IDs.
- Source
Methods
(static) validate(storyDef) → {Object}
Validates a story graph definition structure.
| Name | Type | Description |
|---|---|---|
storyDef | Object |
- Source
- Type:
- Object
addNode(node) → {this}
Adds a dialogue node to the graph.
| Name | Type | Description |
|---|---|---|
node | Object |
- Source
- Type:
- this
advance() → {Object|null}
Advances linear dialogue to the next node (when node has no choices but defines 'next').
- Source
- Type:
- Object |
null
choose(choiceIndexOrId) → {Object|null}
Selects a dialogue choice by index or ID, applies consequences, and transitions.
| Name | Type | Description |
|---|---|---|
choiceIndexOrId | number | |
- Source
The new current node, or null if dialogue ended
- Type:
- Object |
null
diagnostics() → {Object}
Runs comprehensive diagnostics on the story graph: detects missing node references, absent speakers, and contradictory conditions.
- Source
- Type:
- Object
getAvailableChoices(nodeIdopt) → {Array.<Object>}
Returns only the choices currently available according to WorldFacts.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
nodeId | string | <optional> | null |
- Source
- Type:
- Array.<Object>
getChoices(nodeIdopt) → {Array.<Object>}
Returns all choices for a node with their availability evaluated against facts.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
nodeId | string | <optional> | null |
- Source
- Type:
- Array.<Object>
getCurrentNode() → {Object|null}
Returns the current node enriched with available choices.
- Source
- Type:
- Object |
null
getNode(nodeId) → {Object|null}
Gets a node by ID.
| Name | Type | Description |
|---|---|---|
nodeId | string |
- Source
- Type:
- Object |
null
hasNode(nodeId) → {boolean}
Checks if a node ID exists in the graph.
| Name | Type | Description |
|---|---|---|
nodeId | string |
- Source
- Type:
- boolean
isActive() → {boolean}
Checks if dialogue sequence is active.
- Source
- Type:
- boolean
isCompleted() → {boolean}
Checks if dialogue sequence has completed.
- Source
- Type:
- boolean
reset()
Resets dialogue to unstarted state.
- Source
restore(snapshot) → {this}
Restores dialogue state from snapshot.
| Name | Type | Description |
|---|---|---|
snapshot | Object |
- Source
- Type:
- this
setFacts(facts) → {this}
Binds or updates the authoritative WorldFacts instance.
| Name | Type | Description |
|---|---|---|
facts | WorldFacts |
- Source
- Type:
- this
snapshot() → {Object}
Serializes runtime dialogue state for save games.
- Source
- Type:
- Object
start(nodeIdopt, factsopt) → {Object}
Starts the dialogue sequence at the given node or initialNodeId.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
nodeId | string | <optional> | null | |
facts | WorldFacts | <optional> | null |
- Source
Current node
- Type:
- Object