e81d5e61-316c-4d22-a648-373c6b027c0b.js
3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"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();