MessageSceneModel.ts
1.4 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
import { ReadonlyPlot, GameRecord, getPlot } from "../../avg/AVG";
import { ConfigManager } from "simba-config-manager";
import { messageSceneConfig } from "../../config/MessageSceneConfig";
export class MessageSceneModel {
private _id: number;
get id() { return this._id }
get config() { return ConfigManager.getConfig(messageSceneConfig, this._id); }
private _firstPlot: ReadonlyPlot;
get firstPlot() { return this._firstPlot; }
set firstPlot(plot: ReadonlyPlot) {
this._firstPlot = plot;
GameRecord.recordVariables[this._recordKey + ".f"] = plot.id;
}
private _lastPlot?: ReadonlyPlot;
get lastPlot() { return this._lastPlot; }
set lastPlot(plot: ReadonlyPlot | undefined) {
if (this._lastPlot === plot) return;
this._lastPlot = plot;
if (plot) {
GameRecord.recordVariables[this._recordKey + ".l"] = plot.id;
}
}
private _recordKey: string;
constructor(id: number) {
this._id = id;
this._recordKey = "m" + this._id;
}
async initFromRecords() {
let firstPlotId = GameRecord.recordVariables[this._recordKey + ".f"] as number;
let lastPlotId = GameRecord.recordVariables[this._recordKey + ".l"] as number;
this._firstPlot = (await getPlot(firstPlotId))!;
if (lastPlotId !== undefined) {
this._lastPlot = await getPlot(lastPlotId);
}
}
}