c09efddb-ffe2-4ded-971e-ab6e4c8d6d4b.js 2.83 KB
"use strict";
cc._RF.push(module, 'c09ef3b/+JN7Zceq25MjW1L', 'PlotBranchManager');
// script/game/model/PlotBranchManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlotBranchManager = void 0;
const AVG_1 = require("../../avg/AVG");
const UIManager_1 = require("../../common/gameplay/managers/UIManager");
const AlertDialogViewPresenter_1 = require("../ui/presenter/AlertDialogViewPresenter");
var PlotBranchManager;
(function (PlotBranchManager) {
    /**存档Key */
    const KEY_PLOT_RECORD = 'r_save_p';
    const ONLYONE = true;
    function savePlotIdToGlobal(recordModel) {
        //如果保存的结构体不存在或者存档剧情中的id是剧情结束或者未完待续这两种特殊剧情,弹出提示并直接返回不做存档处理
        if (!recordModel || recordModel.plotId === AVG_1.SpecialPlotId.End || recordModel.plotId === AVG_1.SpecialPlotId.ToBeContinued) {
            UIManager_1.UIManager.showSceneToast("存档数据错误!");
            return;
        }
        let temp = {
            dataptr: {},
            titlecontent: "提示",
            content: "确定将当前剧情覆盖到存档位吗?",
            ishasad: true,
            istwobtn: true,
            adconfig: "inject_fruit",
            hasBanner: false,
            callback: (type, ret) => {
                if (ret) {
                    let saveAlredy = checkRecordAlredy(recordModel.plotId);
                    if (saveAlredy) {
                        UIManager_1.UIManager.showSceneToast("你已经在此处存储过存档");
                    }
                    else {
                        savePlotRecord(recordModel);
                        UIManager_1.UIManager.showSceneToast("保存成功");
                    }
                }
            }
        };
        UIManager_1.UIManager.pushPresenter(AlertDialogViewPresenter_1.default, temp);
    }
    PlotBranchManager.savePlotIdToGlobal = savePlotIdToGlobal;
    /**检测是否已经存档过当前剧情 */
    function checkRecordAlredy(pid) {
        let ret = false;
        let s = AVG_1.GameRecord.globalVariables[KEY_PLOT_RECORD];
        if (s && "" !== s.trim()) {
            let mArr = JSON.parse(s);
            ret = mArr.findIndex((v) => v.plotId === pid) !== (-1);
        }
        return ret;
    }
    /**实际存储 */
    function savePlotRecord(recordModel) {
        let mArr = [];
        if (!ONLYONE) {
            let s = AVG_1.GameRecord.globalVariables[KEY_PLOT_RECORD];
            if (s && "" !== s.trim()) {
                mArr = JSON.parse(s);
            }
        }
        mArr.push(recordModel);
        AVG_1.GameRecord.globalVariables[KEY_PLOT_RECORD] = JSON.stringify(mArr);
        AVG_1.GameRecord.saveRecord();
    }
})(PlotBranchManager = exports.PlotBranchManager || (exports.PlotBranchManager = {}));

cc._RF.pop();