DatingEventSceneModel.ts 1.91 KB
import { ConfigManager } from "../../common/gameplay/managers/ConfigManager";
import { dateSceneConfig } from "../../config/DateSceneConfig";
import { GameRecord } from "../../avg/game-data/GameRecord";
import { ReadonlyPlot } from "../../avg/model/PlotModel";
import { getPlot } from "../../avg/game-data/PlotsData";
import { DateType } from "../../avg/EditorEnums";

export enum DatingEventStatus {
    Locked = 1,
    New,
    InProgress,
    Completed
}

export class DatingEventSceneModel {
    private _id: number;
    get id() { return this._id }
    get config() { return ConfigManager.getConfig(dateSceneConfig, this._id); }

    private _status: DatingEventStatus;
    get status() { return this._status; }
    set status(v: DatingEventStatus) {
        if (this._status !== v) {
            this._status = v;
            GameRecord.recordVariables[this._recordKey + ".s"] = v;
        }
    }

    private _firstPlot: ReadonlyPlot;
    get firstPlot() { return this._firstPlot; }
    set firstPlot(plot: ReadonlyPlot) {
        this._firstPlot = plot;
        GameRecord.recordVariables[this._recordKey + ".f"] = plot.id;
    }

    private _bg: string;
    get background() { return this._bg; }
    set background(bg: string) {
        this._bg = bg;
        GameRecord.recordVariables[this._recordKey + ".bg"] = bg;
    }

    private _recordKey: string;

    constructor(id: number) {
        this._id = id;
        this._recordKey = "de" + this._id;
        this._bg = "";
    }

    async initFromRecords() {
        this._status = GameRecord.recordVariables[this._recordKey + ".s"] as number || DatingEventStatus.Locked;
        let firstPlotId = this.config.DateType === DateType.Date_Normal ? GameRecord.recordVariables[this._recordKey + ".f"] as number : this.config.start_plot_id;
        this._firstPlot = (await getPlot(firstPlotId))!;
        this._bg = GameRecord.recordVariables[this._recordKey + ".bg"] as string || "";
    }
}