async function continueSession(sessionData, choiceIndex=null) {

    // Reload the session
    var inkStory = await FoundryInk.loadStory(sessionData.sourcefile);
    if (sessionData.state !== null) {
        inkStory.state.LoadJson(sessionData.state);
    }
    Hooks.callAll('foundry-ink.loadSession', sessionData);

    // Rebind the default external bindings if enabled
    if (FoundryInk.settings("useDefaultBindings")) {
        bindFunctions(inkStory);
        /** Allow modules to bind external functions when the story is being re-instantiated */
        await Hooks.callAll("foundry-ink.bindExternalFunctions", inkStory, sessionData);
    }

    // Prepare a 'page' to hold all lines delivered by ink
    var page = { frames: [], choices: [] };

    // If a choice is being made, do it first
    if (choiceIndex !== null) {
        inkStory.ChooseChoiceIndex(choiceIndex);
    }

    // Deliver one line at a time for parsing reasons
    while (inkStory.canContinue) {

        // Deliver line & ensure sessionData is up to date
        var line = inkStory.Continue();
        sessionData.state = inkStory.state.toJson();
        Hooks.callAll('foundry-ink.deliverLine', line, sessionData);

        // Deliver tags
        var tags = inkStory.currentTags;
        Hooks.callAll('foundry-ink.currentTags', tags, sessionData);

        // Deliver frame (line + tags)
        var frame = { line: line, tags: tags};
        Hooks.callAll('foundry-ink.deliverFrame', frame, sessionData);
        page.frames.push(frame);
    }

    // Collect and deliver choices. Now the story is either presenting choices or `-> END`
    if (FoundryInk.settings('hookSyntax')) {
        page.choices = choiceParse(inkStory.currentChoices, sessionData);
    } else {        
        page.choices = Object.entries(inkStory.currentChoices).map(choice => {
            return {
                index: choice[0],
                text: choice[1].text
            };
        });
    }
    Hooks.callAll('foundry-ink.deliverChoices', page.choices, sessionData);

    // Deliver page
    Hooks.callAll('foundry-ink.deliverPage', page, sessionData);
    
    // Warn developers that saving right now will cause bugs
    if (inkStory.state.callstackDepth > 1) {
        console.warn(FoundryInk.i18n('warnings.tunnel-saves'));
    }

    // Save and dispose session. Second parameter warns devs if saving would cause problems.
    // Issues can be evaded by tracking the last valid state + choices since then to 'replay' the story.
    sessionData.visited = false;
    Hooks.callAll('foundry-ink.saveSession', sessionData, inkStory.state.callstackDepth > 1);
}
/**
 * Steps an inkStory forward, notifying any listeners by calling hooks to send them new data. 
 * 
 * @param {Object | serde.SessionData } sessionData - Information about the story being resumed
 * @param {String} sessionData.name - the name of the binding in ink by the when
 *     bound by the EXTERNAL command or called as a function.
 * @param {SessionData} sessionData.sessionData - information about the session
 *     that will be used to rebind the external function.
 * @param {Function} sessionData.externalFn - the binding to be serialized
 *     (deserializing this is effectively `eval` running at the privilege of a
 *     macro).
 * 
 * @fires foundry-ink.loadSession
 * @fires foundry-ink.bindExternalFunctions
 * @fires foundry-ink.deliverLines
 * @fires foundry-ink.currentTags
 * @fires foundry-ink.deliverFrame
 * @fires foundry-ink.deliverChoices
 * @fires foundry-ink.deliverPage
 * @fires foundry-ink.saveSession
 */
Steps an inkStory forward, notifying any listeners by calling hooks to send them new data.

@param {Object | serde.SessionData } sessionData - Information about the story being resumed
@param {String} sessionData.name - the name of the binding in ink by the when
bound by the EXTERNAL command or called as a function.
@param {SessionData} sessionData.sessionData - information about the session
that will be used to rebind the external function.
@param {Function} sessionData.externalFn - the binding to be serialized
(deserializing this is effectively `eval` running at the privilege of a
macro).


Steps an inkStory forward notifying any listeners by calling hooks to send them new data . @param { Object | serde . SessionData } sessionData - Information about the story being resumed @param { String } sessionData . name - the name of the binding in ink by the when bound by the EXTERNAL command or called as a function . @param { SessionData } sessionData . sessionData - information about the session that will be used to rebind the external function . @param { Function } sessionData . externalFn - the binding to be serialized ( deserializing this is effectively ` eval ` running at the privilege of a macro ) .
async function continueSession(sessionData, choiceIndex=null) {
    var inkStory = await FoundryInk.loadStory(sessionData.sourcefile);
    if (sessionData.state !== null) {
        inkStory.state.LoadJson(sessionData.state);
    }
    Hooks.callAll('foundry-ink.loadSession', sessionData);
    if (FoundryInk.settings("useDefaultBindings")) {
        bindFunctions(inkStory);
        await Hooks.callAll("foundry-ink.bindExternalFunctions", inkStory, sessionData);
    }
    var page = { frames: [], choices: [] };
    if (choiceIndex !== null) {
        inkStory.ChooseChoiceIndex(choiceIndex);
    }
    while (inkStory.canContinue) {
        var line = inkStory.Continue();
        sessionData.state = inkStory.state.toJson();
        Hooks.callAll('foundry-ink.deliverLine', line, sessionData);
        var tags = inkStory.currentTags;
        Hooks.callAll('foundry-ink.currentTags', tags, sessionData);
        var frame = { line: line, tags: tags};
        Hooks.callAll('foundry-ink.deliverFrame', frame, sessionData);
        page.frames.push(frame);
    }
    if (FoundryInk.settings('hookSyntax')) {
        page.choices = choiceParse(inkStory.currentChoices, sessionData);
    } else {        
        page.choices = Object.entries(inkStory.currentChoices).map(choice => {
            return {
                index: choice[0],
                text: choice[1].text
            };
        });
    }
    Hooks.callAll('foundry-ink.deliverChoices', page.choices, sessionData);
    Hooks.callAll('foundry-ink.deliverPage', page, sessionData);
    if (inkStory.state.callstackDepth > 1) {
        console.warn(FoundryInk.i18n('warnings.tunnel-saves'));
    }
    sessionData.visited = false;
    Hooks.callAll('foundry-ink.saveSession', sessionData, inkStory.state.callstackDepth > 1);
}
async function continueSession ( sessionData , choiceIndex = null ) { var inkStory = await FoundryInk . loadStory ( sessionData . sourcefile ) ; if ( sessionData . state !== null ) { inkStory . state . LoadJson ( sessionData . state ) ; } Hooks . callAll ( 'foundry-ink.loadSession' , sessionData ) ; if ( FoundryInk . settings ( "useDefaultBindings" ) ) { bindFunctions ( inkStory ) ; await Hooks . callAll ( "foundry-ink.bindExternalFunctions" , inkStory , sessionData ) ; } var page = { frames : [ ] , choices : [ ] } ; if ( choiceIndex !== null ) { inkStory . ChooseChoiceIndex ( choiceIndex ) ; } while ( inkStory . canContinue ) { var line = inkStory . Continue ( ) ; sessionData . state = inkStory . state . toJson ( ) ; Hooks . callAll ( 'foundry-ink.deliverLine' , line , sessionData ) ; var tags = inkStory . currentTags ; Hooks . callAll ( 'foundry-ink.currentTags' , tags , sessionData ) ; var frame = { line : line , tags : tags } ; Hooks . callAll ( 'foundry-ink.deliverFrame' , frame , sessionData ) ; page . frames . push ( frame ) ; } if ( FoundryInk . settings ( 'hookSyntax' ) ) { page . choices = choiceParse ( inkStory . currentChoices , sessionData ) ; } else { page . choices = Object . entries ( inkStory . currentChoices ) . map ( choice => { return { index : choice [ 0 ] , text : choice [ 1 ] . text } ; } ) ; } Hooks . callAll ( 'foundry-ink.deliverChoices' , page . choices , sessionData ) ; Hooks . callAll ( 'foundry-ink.deliverPage' , page , sessionData ) ; if ( inkStory . state . callstackDepth > 1 ) { console . warn ( FoundryInk . i18n ( 'warnings.tunnel-saves' ) ) ; } sessionData . visited = false ; Hooks . callAll ( 'foundry-ink.saveSession' , sessionData , inkStory . state . callstackDepth > 1 ) ; }
Steps an inkStory forward, notifying any listeners by calling hooks to send them new data.
Steps an inkStory forward notifying any listeners by calling hooks to send them new data .
// Reload the session // Rebind the default external bindings if enabled /** Allow modules to bind external functions when the story is being re-instantiated */ // Prepare a 'page' to hold all lines delivered by ink // If a choice is being made, do it first // Deliver one line at a time for parsing reasons // Deliver line & ensure sessionData is up to date // Deliver tags // Deliver frame (line + tags) // Collect and deliver choices. Now the story is either presenting choices or `-> END` // Deliver page // Warn developers that saving right now will cause bugs // Save and dispose session. Second parameter warns devs if saving would cause problems. // Issues can be evaded by tracking the last valid state + choices since then to 'replay' the story.