Interface: NarrationManagerInterface
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:16
Properties
alreadyCurrentStepMadeChoices
> readonly alreadyCurrentStepMadeChoices: number[] | undefined
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:82
Get the choices already made in the current step. Attention: if the choice step index is edited or the code of choice step is edited, the result will be wrong.
Returns
The choices already made in the current step. If there are no choices, it will return undefined.
canContinue
> readonly canContinue: boolean
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:110
Return if can go to the next step.
Returns
True if can go to the next step.
continue
> continue: (props, options?) => Promise<StepLabelResultType>
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:136
Execute the next step and add it to the history. If a step is already running, it will put the request in the queue, and when the step is finished, it will execute the next step.
Parameters
props
StepLabelProps
The props to pass to the step.
options?
The options.
runNow?
boolean
If true, ignore the running step, ignore the choice menu/required input and run the next step immediately.
steps?
number
The number of steps to advance. Must be a valid finite number greater than 0. If NaN, Infinity, or a value less than or equal to 0 is provided, the implementation will emit a warning and return early without advancing steps.
Default
1
Returns
Promise<StepLabelResultType>
StepLabelResultType or undefined.
Example
function nextOnClick() {
setLoading(true)
narration.continue(yourParams)
.then((result) => {
setUpdate((p) => p + 1)
setLoading(false)
if (result) {
// your code
}
})
.catch((e) => {
setLoading(false)
console.error(e)
})
}
currentLabel
> readonly currentLabel: LabelAbstract<any, { }, number> | undefined
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:59
currentLabel is the current label that occurred during the progression of the steps.
currentStepTimesCounter
> currentStepTimesCounter: number
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:27
Counter of execution times of the current step. Current execution is also included. Starts from 1.
Attention: if the step index is edited or the code of step is edited, the counter will be reset.
You can restart the counter in this way:
narration.currentStepTimesCounter = 0
dialogGlue
> dialogGlue: boolean
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:274
If true, the next dialogue text will be added to the current dialogue text.
inputType
> readonly inputType: string | undefined
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:283
inputValue
> inputValue: StorageElementType
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:278
The input value to be inserted by the player.
isCurrentStepAlreadyOpened
> readonly isCurrentStepAlreadyOpened: boolean
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:87
Check if the current step is already completed.
Returns
True if the current step is already completed.
isRequiredInput
> readonly isRequiredInput: boolean
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:282
If true, the player must enter a value.
openedLabels
> readonly openedLabels: OpenedLabel[]
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:55
The stack of the opened labels.
stepCounter
> readonly stepCounter: number
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:51
This counter corresponds to the total number of steps that have been executed so far.
Not is the history.stepsHistory.length - 1.
Accessors
choices
Get Signature
> get choices(): StoredIndexedChoiceInterface[] | undefined
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:255
The options to be shown in the game
Example
narration.choices = [
newChoiceOption("Events Test", EventsTestLabel, {}),
newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
newChoiceOption("Ticker Test", TickerTestLabel, {}),
newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
]
Returns
StoredIndexedChoiceInterface[] | undefined
Set Signature
> set choices(data): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:270
The options to be shown in the game
Throws
when a choice contains functions or class instances that cannot be serialized to JSON.
Example
narration.choices = [
newChoiceOption("Events Test", EventsTestLabel, {}),
newChoiceOption("Show Image Test", ShowImageTest, { image: "imageId" }, "call"),
newChoiceOption("Ticker Test", TickerTestLabel, {}),
newChoiceOption("Tinting Test", TintingTestLabel, {}, "jump"),
newChoiceOption("Base Canvas Element Test", BaseCanvasElementTestLabel, {})
]
Parameters
data
StoredChoiceInterface[] | undefined
Returns
void
dialogue
Get Signature
> get dialogue(): DialogueInterface | undefined
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:236
Dialogue to be shown in the game
Returns
DialogueInterface | undefined
Set Signature
> set dialogue(props): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:241
Dialogue to be shown in the game
Throws
when the dialogue contains functions or class instances that cannot be serialized to JSON.
Parameters
props
string | string[] | DialogueInterface | undefined
Returns
void
Methods
addCurrentStepToHistory()
> addCurrentStepToHistory(): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:102
Save the current step to the history.
Returns
void
call()
> call<T>(label, props): Promise<StepLabelResultType>
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:173
Execute the label and add it to the history. (It's similar to Ren'Py's call function)
Type Parameters
T
T extends object = { }
Parameters
label
string | LabelAbstract<any, T, number>
The label to execute or the id of the label
props
The props to pass to the label.
Returns
Promise<StepLabelResultType>
StepLabelResultType or undefined.
Throws
when the label is not found in the registered labels.
Examples
narration.call(startLabel, yourParams).then((result) => {
if (result) {
// your code
}
})
// if you use it in a step label you should return the result.
return narration.call(startLabel).then((result) => {
return result
})
clear()
> clear(): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:298
Clear all narration data
Returns
void
closeAllLabels()
> closeAllLabels(): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:71
Close all labels and add them to the history. Attention: This method can cause an unhandled game ending.
Returns
void
closeCurrentLabel()
> closeCurrentLabel(): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:67
Close the current label and add it to the history.
Returns
void
export()
> export(): NarrationGameState
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:306
Export the narration to an object.
Returns
The narration in an object.
getRandomNumber()
> getRandomNumber(min, max, options?): number | undefined
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:35
Get a random number between min and max.
Parameters
min
number
The minimum number.
max
number
The maximum number.
options?
The options.
onceOnly?
boolean
If true, the number will be generated only once on the current step of the label.
Default
false
Returns
number | undefined
The random number or undefined. If options.onceonly is true and all numbers between min and max have already been generated, it will return undefined.
getTimesChoiceMade()
> getTimesChoiceMade(index): number
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:98
Get times a choice has been made in the current step.
Parameters
index
number
The index of the choice.
Returns
number
The number of times the choice has been made.
getTimesLabelOpened()
> getTimesLabelOpened(label): number
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:92
Get times a label has been opened
Parameters
label
string
Returns
number
times a label has been opened
isLabelAlreadyCompleted()
> isLabelAlreadyCompleted(label): boolean
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:77
Check if the label is already completed.
Parameters
label
string | LabelAbstract<any, { }, number>
The label to check.
Returns
boolean
True if the label is already completed.
jump()
> jump<T>(label, props): Promise<StepLabelResultType>
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:199
Execute the label, close the current label, execute the new label and add the new label to the history. (It's similar to Ren'Py's jump function)
Type Parameters
T
T extends object
Parameters
label
string | LabelAbstract<any, T, number>
The label to execute.
props
The props to pass to the label or the id of the label
Returns
Promise<StepLabelResultType>
StepLabelResultType or undefined.
Throws
when the label is not found in the registered labels.
Examples
narration.jump(startLabel, yourParams).then((result) => {
if (result) {
// your code
}
})
// if you use it in a step label you should return the result.
return narration.jump(startLabel).then((result) => {
return result
})
removeInputRequest()
> removeInputRequest(): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:293
Remove the input request.
Returns
void
requestInput()
> requestInput(info, defaultValue?): void
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:289
Request input from the player.
Parameters
info
Omit<InputInfo, "isRequired">
The input value to be inserted by the player.
defaultValue?
The default value to be inserted.
Returns
void
restore()
> restore(data, lastHistoryStep): Promise<void>
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:311
Restore the narration from an object.
Parameters
data
object
The narration in an object.
lastHistoryStep
Omit<HistoryStep, "diff"> | null
Returns
Promise<void>
selectChoice()
> selectChoice<T>(item, props): Promise<StepLabelResultType>
Defined in: src/narration/interfaces/NarrationManagerInterface.ts:224
Select a choice from the choice menu. and close the choice menu.
Type Parameters
T
T extends object
Parameters
item
props
Returns
Promise<StepLabelResultType>
Throws
when the choice type is not "call", "jump", or "close".
Example
narration.selectChoice(item, {
navigate: navigate,
// your props
...item.props
})
.then(() => {
// your code
})
.catch((e) => {
// your code
})