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