DatingEventSceneModel.ts 2.42 KB
import { ConfigManager } from "simba-config-manager";
import { GameRecord, getPlot, ReadonlyPlot } from "../../avg/AVG";
import { DateType } from "../../avg/EditorEnums";
import { dateSceneConfig } from "../../config/DateSceneConfig";
import { GameModelManager } from "./GameModelManager";

/**
 * 剧情状态
 */
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 inProgress = GameModelManager.checkBranchIsInProgress(this.id);
        if (inProgress) {
            this._status = DatingEventStatus.InProgress;
        }
        let comp = GameModelManager.checkBranchIsComplete(this.id);
        if (comp) {
            this._status = DatingEventStatus.Completed;
        }
        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 || "";
    }

    private _isExtra: boolean = false;
    get isExtra() { return this._isExtra; }
    set isExtra(isExtra: boolean) {
        this._isExtra = isExtra;
    }
}