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,uBAAU,CAAC,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAChD,OAAO,gBAAgB,EAAE,CAAC;IAC9B,CAAC;IAHe,2BAAe,kBAG9B,CAAA;IAED,KAAK,UAAU,gBAAgB;QAC3B,IAAI,WAAW,GAAG,uBAAU,CAAC,qBAAqB,EAAE,CAAC;QACrD,cAAc,GAAG,EAAE,CAAC;QACpB,KAAK,IAAI,CAAC,IAAI,WAAW,EAAE;YACvB,IAAI,CAAC,CAAC,CAAC,EAAE;gBACL,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBACjC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;wBACtB,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBACnC;iBACJ;aACJ;SACJ;QACD,IAAI,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAO,CAAC,CAAC,CAAC,CAAC,CAAmB,CAAC;QAC/E,YAAA,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtC,OAAO,YAAY,CAAC;IACxB,CAAC;AACL,CAAC,EA5NgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QA4N3B","file":"","sourceRoot":"/","sourcesContent":["import { Emitter } from \"simba-eventkit\";\nimport { ActionManager } from \"./ActionManager\";\nimport { EditorEvents } from \"./EditorEvents\";\nimport { GameRecord } from \"./game-data/GameRecord\";\nimport { getPlot, initPlotsData, initCustomPlots, addCustomPlotData, getChapterPlots } from \"./game-data/PlotsData\";\nimport { PlotJumpType, ReadonlyPlot, ReadonlyPlots, SpecialPlotId, Plot } from \"./model/PlotModel\";\nimport { evalConditionExpr } from \"./utils/PlotUtils\";\n\nexport namespace PlotManager {\n    let emitter = new Emitter;\n    let currentPlots: ReadonlyPlot[] = [];\n\n    export function getCurrentPlots(): ReadonlyPlots {\n        return currentPlots;\n    }\n\n    // 剧情开始,需要在特定场景展现、执行Action等\n    export const PlotStartEvent = emitter.createEvent<(plots: ReadonlyPlots) => void>();\n\n    // 剧情将要开始,可根据将要开始的剧情修改存档数据保存\n    export const PlotWillStart = emitter.createEvent<(plot: ReadonlyPlot | undefined, branch: number) => void>();\n\n    export const PlotsRollbackEvent = emitter.createEvent<(plots: ReadonlyPlots) => void>();\n\n    let customPlotId = SpecialPlotId.CustomPlotStart;\n\n    let plotSelections: { [key: number]: number };\n\n    export function getPlotSelection(plotId: number) {\n        return plotSelections[plotId];\n    }\n\n    export async function init() {\n        await initPlotsData();\n        GameRecord.initRecords();\n        customPlotId = GameRecord.globalVariables.customPlotId;\n        initCustomPlots(GameRecord.globalVariables.customPlots);\n\n        EditorEvents.START_PLOT_BRANCH.on((param: string) => {\n            let plotId = parseInt(param);\n            return startNewPlotBranch(plotId);\n        });\n    }\n\n    // Add custom plot and return plot id\n    export function addCustomPlot(plot: Plot): void {\n        plot.id = customPlotId--;\n        addCustomPlotData(plot);\n        GameRecord.globalVariables.customPlotId = customPlotId;\n        GameRecord.globalVariables.customPlots = getChapterPlots(-100);\n        GameRecord.autoSave();\n    }\n\n    export function addCustomPlots(plots: Plot[]): void {\n        for (let plot of plots) {\n            plot.id = customPlotId--;\n            addCustomPlotData(plot);\n        }\n        GameRecord.globalVariables.customPlotId = customPlotId;\n        GameRecord.globalVariables.customPlots = getChapterPlots(-100);\n        GameRecord.autoSave();\n    }\n\n    export async function start(recordIndex: number = 0) {\n        let plots = GameRecord.startGameWithRecord(recordIndex);\n        currentPlots = await Promise.all(plots.map(v => getPlot(v))) as ReadonlyPlot[];\n\n        plotSelections = {};\n\n        let items = GameRecord.getCurrentRecordItems();\n\n        for (let p of items) {\n            if (p.s) {\n                for (let i = 0; i < p.p.length; i++) {\n                    if (p.s[i] !== undefined) {\n                        plotSelections[p.p[i]] = p.s[i];\n                    }\n                }\n            }\n        }\n\n        // 检查未完待续剧情,如有新剧情修改存档数据\n        for (let i = 0; i < plots.length; i++) {\n            let plotId = plots[i];\n            if (plotId === SpecialPlotId.ToBeContinued) {\n                let index = items.length - 2;\n                for (; index >= 0; index--) {\n                    if (items[index].p[i] >= 0) {\n                        plotId = items[index].p[i];\n                        break;\n                    }\n                }\n                if (plotId < 0) throw new Error(\"Record error.\");\n                let plot = (await getPlot(plotId))!;\n                let sels = items[index].s;\n                let nextPlot = (await getNextPlot(plot, sels ? sels[i] : undefined))!;\n                if (nextPlot.id >= 0) {\n                    for (let j = index + 1; j < items.length; j++) { // 修改存档数据\n                        (items[index].p as number[])[i] = nextPlot.id;\n                    }\n                }\n                currentPlots[i] = nextPlot as ReadonlyPlot;\n            }\n        }\n\n        PlotStartEvent.emit(currentPlots);\n        return currentPlots;\n    }\n\n    export async function startNewPlotBranch(plotId: number) {\n        let index = currentPlots.findIndex(v => v && v.id === plotId);\n        if (index >= 0) {\n            console.warn(\"startNewPlotBranch: plot already exist.\", plotId);\n            return -1;\n        }\n        let plot = await getPlot(plotId);\n        await Promise.all(PlotWillStart.emit(plot, index));\n        let history = GameRecord.getCurrentRecordItems();\n        index = history[history.length - 1].p.length;\n        let plots = GameRecord.startPlot(plotId, index);\n        currentPlots = await Promise.all(plots.map(v => getPlot(v))) as ReadonlyPlot[];\n        PlotStartEvent.emit(currentPlots);\n        return index;\n    }\n\n    export async function getNextPlot(plot: ReadonlyPlot, selectOption?: number) {\n        let id = getNextPlotId(plot, selectOption);\n        return getPlot(id);\n    }\n\n    function getNextPlotId(plot: ReadonlyPlot, selectOption?: number | string, saveToRecord?: boolean) {\n        let nextPlotId: number;\n        if (selectOption !== undefined && selectOption !== null) {\n            if (plot.jump.type !== PlotJumpType.Select) {\n                throw new Error(\"Plot jump type error\");\n            }\n            let selectIndex: number;\n            if (typeof selectOption === \"string\") {\n                for (let i = 0; i < plot.jump.jumps.length; i++) {\n                    if (plot.jump.jumps[i].id == selectOption) {\n                        selectIndex = i;\n                    }\n                }\n            } else {\n                selectIndex = selectOption;\n            }\n            if (selectIndex! >= plot.jump.jumps.length) {\n                throw new Error(\"Invalid option\");\n\n            }\n            if (saveToRecord) {\n                GameRecord.setSelectOptionForPlot(plot.id, selectIndex!);\n            }\n            nextPlotId = plot.jump.jumps[selectIndex!].toPlot;\n        } else {\n            if (plot.jump.type !== PlotJumpType.Condition) {\n                throw new Error(\"Plot jump type error\");\n            }\n            let conditions = plot.jump.conditionBranches;\n            if (conditions) {\n                try {\n                    for (let cond of conditions) {\n                        if (cond.condition && evalConditionExpr(cond.condition)) {\n                            nextPlotId = cond.toPlot;\n                            break;\n                        }\n                    }\n                } catch (e) {\n\n                }\n            }\n            if (nextPlotId! === undefined) nextPlotId = plot.jump.toPlot;\n        }\n        return nextPlotId;\n    }\n\n    export async function completePlot(plot: ReadonlyPlot, selectOption?: number | string, customData?: object) {\n        let plotIndex = currentPlots.findIndex(v => v && v.id === plot.id);\n        if (plotIndex < 0) throw new Error(\"Invalid plot\");\n        GameRecord.startTransaction();\n        if (selectOption !== undefined) {\n            await Promise.all(EditorEvents.emitter.emit(\"SELECT_OPTION_\" + ((typeof selectOption === \"number\") ? selectOption + 1 : selectOption)));\n        }\n        await Promise.all(EditorEvents.PLOT_END.emit(plot.id.toString()));\n        ActionManager.stop();\n        let nextPlotId: number = getNextPlotId(plot, selectOption, true);\n        if (customData) {\n            GameRecord.setPlotCustomData(plotIndex, customData);\n        }\n        let nextPlot = await getPlot(nextPlotId);\n        await Promise.all(PlotWillStart.emit(nextPlot, plotIndex));\n        let plots = GameRecord.startPlot(nextPlotId, plotIndex);\n        GameRecord.endTransaction();\n        if (typeof selectOption === \"number\") {\n            plotSelections[plot.id] = selectOption;\n        }\n        currentPlots = await Promise.all(plots.map(v => getPlot(v))) as ReadonlyPlot[];\n        PlotStartEvent.emit(currentPlots);\n        return currentPlots;\n    }\n\n    export async function rollbackToPlot(plot: number, reverseFind = false, preserveVars?: string[]) {\n        GameRecord.rollbackToPlot(plot, reverseFind, preserveVars);\n        return rollbackFinished();\n    }\n\n    export function rollbackToIndex(index: number, preserveVars?: string[]) {\n        GameRecord.rollbackToIndex(index, preserveVars);\n        return rollbackFinished();\n    }\n\n    async function rollbackFinished() {\n        let recordItems = GameRecord.getCurrentRecordItems();\n        plotSelections = {};\n        for (let p of recordItems) {\n            if (p.s) {\n                for (let i = 0; i < p.p.length; i++) {\n                    if (p.s[i] !== undefined) {\n                        plotSelections[p.p[i]] = p.s[i];\n                    }\n                }\n            }\n        }\n        let plots = recordItems[recordItems.length - 1].p;\n        currentPlots = await Promise.all(plots.map(v => getPlot(v))) as ReadonlyPlot[];\n        PlotsRollbackEvent.emit(currentPlots);\n        return currentPlots;\n    }\n}"]}