Skip to content

Story

In scripts, we can obtain the story instance through functions, allowing for fine-grained control over the story.

Basic Information

The story instance records all the basic information about the current story's development. Developers can directly modify this basic information for precise control.

KeyNameDescriptionControllable
storyStoryThe current story
saveSaveThe current story's save data
themeThemeThe current story's theme
sceneSceneThe current scene
messageMessageDisplays a pop-up message prompt by assignment
mediaMediaThe currently loaded story media
mediaDomMedia DomThe currently playing media DOM element
pausedPausedWhether playback is paused
volumeVolumeThe volume of the current media
tipTipAssigning media here displays a tip
playedPlayedWhether the story media has finished playing
durationDurationThe duration of the current story media
currentTimeCurrent TimeThe current playback progress
playbackRatePlayback RateThe current playback speed
fullscreenFullscreenWhether in fullscreen mode
fnPanelSub-PageThe current sub-page

For example, displaying a prompt when a button is clicked:

js
export default {
    ...otherParameters(ignore),
    /**
     * Event Run
     *
     * @param {object} save  Save - The story save data
     * @param {object} story  Story - The story object, which allows for prompts, pop-ups, and other operations to modify the story
     * @param {object} loader Loader - The Vue node of the event loader
     * @return {Promise<Place|yinObject|undefined>}
     */
    run(save, story, loader) {
        story.message = 'Hello'

        /**
         * message
         * @typedef {object|string} message
         * @property {string} content - The message content (supports rich text) (does not support content rendering)
         * @property {string} enterAnimation - Animation class, e.g., `animate__fadeInRight`
         * @property {object} style - Message style
         * @property {number} duration - Display duration
         */
        story.message = {
            content: '<p>Hello</p>',
            enterAnimation: 'animate__fadeInRight',
            style: {
                // Move the pop-up to the top-left
                left: '21px'
            },
            duration: 2000
        }
    }
}

Functions

You can also control story behavior through some functions.

EventNameDescription
playPlay
pausePause
speedCtrlToggle Playback SpeedCycles through several speed options
speedUpFast Play3x speed
speedUpEndExit Fast Play
playToStartJump to Scene Start
playToEndJump to Scene EndJump to the time when the story finishes playing
fullscreenCtrlToggle Fullscreen
selectSaveSwitch SaveNavigate to the save selection page
logoutLogout

For example, pausing playback and adjusting the playback progress when a button is clicked:

js
export default {
    ...otherParameters(ignore),
    /**
     * Event Run
     *
     * @param {object} save  Save - The story save data
     * @param {object} story  Story - The story object, which allows for prompts, pop-ups, and other operations to modify the story
     * @param {object} loader Loader - The Vue node of the event loader
     * @return {Promise<Place|yinObject|undefined>}
     */
    run(save, story, loader) {
        story.pause()
        // The unit of `currentTime` in the media DOM is seconds
        story.mediaDom.currentTime = 5

        story.message = 'Wrong choice!\nTime stops, the cycle begins~~'
    }
}