timeline.js 89,2 КБ
Newer Older
Nikitos's avatar
ф  
Nikitos включено в состав коммита
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
            location: last_run.location,
            waiting: null,
            beats: last_run.beats,
            ticks: last_run.ticks,
            time: last_run.time,
            depth: 0,
            label: null,
            actors: [],
            choices: [],
            text: '',
            auto: runtime.auto,
            flags: api && api.store && api.store.all ? api.store.all() : {},
        };
    }
    const frame = run.frames[run.frames.length - 1];
    const actors = [];
    for (const [who, rig] of run.rigs) {
        actors.push({
            who,
            pose: rig.pose,
            visible: !!rig.el.visible,
            x: Math.round(rig.el.x),
            y: Math.round(rig.el.y),
            alpha: Number(rig.alpha.toFixed(3)),
            scale: Number(rig.scale.toFixed(3)),
        });
    }
    return {
        running: true,
        id: run.def.id,
        scene: run.def.scene,
        ending: run.ending ? run.ending.id : null,
        ended: run.ended,
        location: run.location,
        waiting: run.wait ? run.wait.kind : null,
        wait_left: run.wait && run.wait.left !== undefined ? Math.round(run.wait.left) : (run.wait ? run.wait.ms : null),
        timers: run.timers.length,
        beats: run.beats,
        ticks: run.ticks,
        time: Math.round(run.time),
        depth: run.frames.length,
        label: labelAt(run, frame),
        actors,
        choices: api && api.dialog && api.dialog.choices ? api.dialog.choices() : [],
        text: api && api.dialog && api.dialog.text ? api.dialog.text() : '',
        auto: runtime.auto,
        flags: api && api.store && api.store.all ? api.store.all() : {},
    };
}

/** Ближайшая метка позади текущей позиции — читаемое «где мы в сценарии». */
function labelAt(state, frame) {
    if (!frame) return null;
    let best = null;
    for (const [name, beat] of state.def.labels) {
        const index = state.def.script.indexOf(beat);
        if (index >= 0 && index < frame.index && (best === null || index > best.index)) best = { name, index };
    }
    return best ? best.name : null;
}

function playTimeline(id, opts) {
    const def = definitions.get(id);
    if (!def) {
        if (ctx && typeof ctx.log === 'function') ctx.log(`$.timeline.play: таймлайн "${id}" не объявлен — см. $.timeline.list()`);
        return false;
    }
    const transition = opts && opts.transition !== undefined ? opts.transition : 'fade';
    if (api.scene && api.scene.current && api.scene.current() !== def.scene) {
        def.pending = { opts: opts || {} };
        api.scene.load(def.scene, { transition });
        return true;
    }
    startRun(def, opts || {});
    return true;
}
Для ускорения просмотра не вся история отображается Просмотреть всю вину