

import { EventTouch, Node, Toggle, _decorator } from "cc";
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { UIID } from "../../common/config/GameUIConfig";
import { SingletonModuleComp } from "../../common/SingletonModuleComp";
import { InitCheckpointComp } from "../bll/InitCheckpoint";


const { ccclass, property } = _decorator;

/** 角色信息界面 */
@ccclass('CheckpointLevelFailComp')
@ecs.register('CheckpointLevelFailView', false)
export class CheckpointLevelFailViewComp extends CCComp {

    private btnRestart

    onAdded(args: any) {
        console.log(args);
    }

    onLoad() {
        this.btnRestart = this.node.getChildByPath("btn_start")
        this.btnRestart.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    private onTouchEnd(event: EventTouch) {
        switch (event.target.name) {
            case "btn_start":
                oops.gui.remove(UIID.LevelFail);
                const checkpoint = ecs.getSingleton(SingletonModuleComp).account.checkpoint;
                checkpoint.add(InitCheckpointComp)
                break;
        }

        event.propagationStopped = true;
    }

    reset() {
        this.node.destroy();
    }
}