LogoPixi’VN
indexInterfaces

Interface: NarrationManagerInterface

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:20

Properties

alreadyCurrentStepMadeChoices

> readonly alreadyCurrentStepMadeChoices: number[] | undefined

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:92

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.

Deprecated

Use queries.alreadyCurrentStepMadeChoices instead.


canContinue

> readonly canContinue: boolean

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:138

Return if can go to the next step. It's false when:

  • A step is running
  • The player must "make a choice"
  • The player must "enter a value"

Returns

True if can go to the next step.


continue

> continue: (props, options?) => Promise<StepLabelResultType>

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:164

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:65

currentLabel is the current label that occurred during the progression of the steps.

Deprecated

Use labels.current instead.


currentStepTimesCounter

> currentStepTimesCounter: number

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:31

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:293

If true, the next dialogue text will be added to the current dialogue text.


input

> readonly input: NarrationInputInterface

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:119

Namespace for operations on the input requested to the player.


inputType

> readonly inputType: string | undefined

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:308

Returns the type of input prompt requested.

Deprecated

Use input.type instead.


inputValue

> inputValue: StorageElementType

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:298

The input value to be inserted by the player.

Deprecated

Use input.value instead.


isCurrentStepAlreadyOpened

> readonly isCurrentStepAlreadyOpened: boolean

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:98

Check if the current step is already completed.

Returns

True if the current step is already completed.

Deprecated

Use queries.isCurrentStepAlreadyOpened instead.


isRequiredInput

> readonly isRequiredInput: boolean

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:303

If true, the player must enter a value.

Deprecated

Use input.isRequired instead.


labels

> readonly labels: NarrationLabelsInterface

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:123

Namespace for operations on the opened labels.


openedLabels

> readonly openedLabels: OpenedLabel[]

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:60

The stack of the opened labels.

Deprecated

Use labels.opened instead.


queries

> readonly queries: NarrationQueriesInterface

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:127

Namespace for queries about the current state of the narration.


stepCounter

> readonly stepCounter: number

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:55

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(): NarrationChoicesInterface

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:274

Namespace for operations on the choices to be shown in the game.

Returns

NarrationChoicesInterface

Set Signature

> set choices(data): void

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:289

Shortcut for NarrationChoicesInterface.list.

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:265

Dialogue to be shown in the game

Returns

DialogueInterface | undefined

Set Signature

> set dialogue(props): void

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:270

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:115

Save the current step to the history.

Returns

void


call()

> call<T>(label, props): Promise<StepLabelResultType>

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:201

Execute the label, add the label to the history and execute the next step of the label.

Type Parameters

T

T extends object = { }

Parameters

label

string | LabelAbstract<any, T, number>

The label to execute or the id of the label

props

StepLabelPropsType<T>

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:325

Clear all narration data

Returns

void


closeAllLabels()

> closeAllLabels(): void

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:79

Close all labels and add them to the history. Attention: This method can cause an unhandled game ending.

Returns

void

Deprecated

Use labels.closeAll instead.


closeCurrentLabel()

> closeCurrentLabel(): void

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:74

Close the current label and add it to the history.

Returns

void

Deprecated

Use labels.closeCurrent instead.


export()

> export(): NarrationGameState

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:333

Export the narration to an object.

Returns

NarrationGameState

The narration in an object.


getRandomNumber()

> getRandomNumber(min, max, options?): number | undefined

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:39

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 for the current step of the label (default: false). Note: min and max affect the storage of already generated numbers.

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:111

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.

Deprecated

Use queries.timesChoiceMade instead.


getTimesLabelOpened()

> getTimesLabelOpened(label): number

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:104

Get times a label has been opened

Parameters

label

string

Returns

number

times a label has been opened

Deprecated

Use queries.timesLabelOpened instead.


isLabelAlreadyCompleted()

> isLabelAlreadyCompleted(label): boolean

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:86

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.

Deprecated

Use queries.isLabelAlreadyCompleted instead.


jump()

> jump<T>(label, props): Promise<StepLabelResultType>

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:227

Execute the label, replace the current label in the history with the new label and execute the next step of the label.

Type Parameters

T

T extends object

Parameters

label

string | LabelAbstract<any, T, number>

The label to execute.

props

StepLabelPropsType<T>

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:320

Remove the input request.

Returns

void

Deprecated

Use input.removeRequest instead.


requestInput()

> requestInput(info?, defaultValue?): void

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:315

Returns true if the player must enter a value.

Parameters

info?

Omit<InputInfo, "isRequired">

The input value to be inserted by the player.

defaultValue?

StorageElementType

The default value to be inserted.

Returns

void

Deprecated

Use input.request instead.


restore()

> restore(data, lastHistoryStep): Promise<void>

Defined in: src/narration/interfaces/NarrationManagerInterface.ts:338

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:253

Select a choice from the choice menu. and close the choice menu.

Type Parameters

T

T extends object

Parameters

item

StoredIndexedChoiceInterface

props

StepLabelPropsType<T>

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
    })

Deprecated

Use choices.select instead.

On this page