import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;


type ResumeCallback<T> = (arg: T) => void;

@ccclass('GameState')
export class GameState extends Component {

    private static instance: GameState;

    private constructor() {
        super();
    }

    public static getInstance(): GameState {
        if (!GameState.instance) {
            GameState.instance = new GameState();
        }
        return GameState.instance;
    }


    //当前是否处于暂停状态
    PauseState: boolean = false;
    //改变暂停状态的回调函数
    ResumeCallBackFunc: ResumeCallback<any>[] = [];


    //获取暂停状态
    IsPauseState(): boolean {
        return this.PauseState;
    }

    //设置暂停状态
    SetCurrentPauseState(State: boolean) {
        //不等于时 设置一次
        if (State != this.PauseState) {
            this.PauseState = State;

            //调用恢复游戏的逻辑回调函数
            this.ResumeCallBackFunc.forEach(callback => {
                callback(State);
            });
        }
    }

    //注册恢复游戏的逻辑回调函数
    RegisterResumeCallBack(Func: ResumeCallback<any>) {
        this.ResumeCallBackFunc.push(Func);
    }


}


