e81d5e61-316c-4d22-a648-373c6b027c0b.js 3.29 KB
"use strict";
cc._RF.push(module, 'e81d55hMWxNIqZINzxrAnwL', 'PlotsData');
// script/avg/game-data/PlotsData.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getChapterPlots = exports.getChapters = exports.initPlotsData = exports.getChapter = exports.getPlot = exports.getPlotsIndex = exports.addCustomPlotData = exports.initCustomPlots = void 0;
const PlotModel_1 = require("../model/PlotModel");
const GameConfig_1 = require("../../GameConfig");
const simba_utils_1 = require("simba-utils");
const ResUtils_1 = require("../../common/utils/ResUtils");
let plotsIndex = {
    firstPlot: -1,
    entries: {}
};
let chaptersData = {};
const curPlotsData = {};
// Managed by PlotManager, do not call directly
function initCustomPlots(plots) {
    if (curPlotsData[-100]) {
        console.error("initCustomPlots already called!");
        return;
    }
    curPlotsData[-100] = plots;
}
exports.initCustomPlots = initCustomPlots;
// Managed by PlotManager, do not call directly
function addCustomPlotData(plot) {
    curPlotsData[-100][plot.id] = plot;
}
exports.addCustomPlotData = addCustomPlotData;
function getPlotsIndex() {
    return plotsIndex;
}
exports.getPlotsIndex = getPlotsIndex;
const USE_CDN_PLOTS = false;
async function getPlot(plotId) {
    if (plotId === undefined)
        return undefined;
    if (plotId <= PlotModel_1.SpecialPlotId.CustomPlotStart) {
        return curPlotsData[-100][plotId];
    }
    if (plotId < 0) {
        return { id: plotId };
    }
    let chapterId = plotsIndex.entries[plotId];
    if (!curPlotsData[chapterId]) {
        curPlotsData[plotsIndex.entries[plotId]] = await retrievePlotsForChapter(chapterId);
    }
    return curPlotsData[chapterId][plotId];
}
exports.getPlot = getPlot;
async function retrievePlotsForChapter(chapterId) {
    while (1) {
        try {
            let res;
            if (USE_CDN_PLOTS) {
                let resStr = await GameConfig_1.GameConfig.cdnServer.get(`/plots/${chapterId}.json`, 5000, { "Cache-Control": "no-cache, no-store" });
                res = JSON.parse(resStr);
            }
            else {
                res = await ResUtils_1.ResUtils.loadRes(`/plots/${chapterId}`, cc.JsonAsset);
            }
            return res;
        }
        catch (e) {
            console.error(e);
        }
    }
}
function getChapter(chapterId) {
    return chaptersData[chapterId];
}
exports.getChapter = getChapter;
async function initPlotsData() {
    while (true) {
        try {
            let res;
            if (USE_CDN_PLOTS) {
                let resStr = await GameConfig_1.GameConfig.cdnServer.get("/plots/index.json", 5000, { "Cache-Control": "no-cache, no-store" });
                res = JSON.parse(resStr);
            }
            else {
                res = await ResUtils_1.ResUtils.loadRes("plots/index", cc.JsonAsset);
            }
            plotsIndex = res.plots;
            chaptersData = res.chapters;
            break;
        }
        catch (e) {
            console.error(e);
            await simba_utils_1.delay(1);
        }
    }
}
exports.initPlotsData = initPlotsData;
function getChapters() {
    return chaptersData;
}
exports.getChapters = getChapters;
function getChapterPlots(chapterId) {
    return curPlotsData[chapterId];
}
exports.getChapterPlots = getChapterPlots;

cc._RF.pop();