import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { VM } from "../../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
import { Checkpoint } from "../../checkpoint/Checkpoint";

/** 
 * 游戏玩家数据 
 */
@ecs.register('AccountModel')
export class AccountModelComp extends ecs.Comp {

    /** 提供 VM 组件使用的数据 */
    private vm: any = {};

    checkpoint: Checkpoint = null!;

    private _name: string = "";
    private _lv: number = 1;
    private _skin: number = 1
    private _reward: boolean = false
    /** 昵称 */
    get name(): string {
        return this._name;
    }
    set name(value: string) {
        this._name = value;
        this.vm.name = value;
    }

    /** 关卡 */
    get lv(): number {
        return this._lv;
    }
    set lv(value: number) {
        this._lv = value;
        this.vm.lv = value;
        oops.storage.set("lv", value);
    }

    /** 关卡 */
    get skin(): number {
        return this._skin;
    }
    set skin(value: number) {
        this._skin = value;
        this.vm.skin = value;
        oops.storage.set("skin", value);
    }

    
    /** 关卡 */
    get reward(): boolean {
        return this._reward;
    }
    set reward(value: boolean) {
        this._reward = value;
        this.vm.reward = value;
        oops.storage.set("reward", value);
    }

    vmAdd() {
        VM.add(this.vm, "Account");
    }

    vmRemove() {
        VM.remove("Account");
    }

    reset() {
        this.vmRemove();

        this.name = "";
    }

}