Files
rougelike-demo/client/assets/scripts/App/AppStatus/AppStatusManager.ts

108 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-12-14 22:41:10 +08:00
import { FSM } from "../../Framework/FSM/FSM";
import { AppStatusBoot } from "./AppStatusBoot";
import { AppStatusLogin } from "./AppStatusLogin";
import { AppStatusGame } from "./AppStatusGame";
/**
*
* :
* -
* - 访
* -
*
* 状态流程: Boot -> Login -> Game
*/
export class AppStatusManager {
private static _instance: AppStatusManager | null = null;
private _fsm: FSM;
/**
* ()
*/
private constructor() {
this._fsm = new FSM();
this.initStates();
}
/**
*
*/
static getInstance(): AppStatusManager {
if (!this._instance) {
this._instance = new AppStatusManager();
}
return this._instance;
}
/**
*
*/
private initStates(): void {
console.log("[AppStatusManager] 初始化应用状态...");
// 添加应用状态: Boot -> Login -> Game
this._fsm.addState(new AppStatusBoot(this._fsm));
this._fsm.addState(new AppStatusLogin(this._fsm));
this._fsm.addState(new AppStatusGame(this._fsm));
console.log("[AppStatusManager] 应用状态初始化完成");
}
/**
*
* Boot状态开始
*/
start(): void {
console.log("[AppStatusManager] 启动应用...");
this._fsm.changeState("Boot");
}
/**
*
* @param stateName
* @param params
*/
changeState(stateName: string, params?: any): void {
this._fsm.changeState(stateName, params);
}
/**
*
*/
getCurrentStateName(): string | null {
return this._fsm.getCurrentStateName();
}
/**
*
*/
getCurrentState(): any {
return this._fsm.getCurrentState();
}
/**
* ()
* @param dt ()
*/
update(dt: number): void {
this._fsm.update(dt);
}
/**
*
*
*/
getFSM(): FSM {
return this._fsm;
}
/**
*
*/
destroy(): void {
console.log("[AppStatusManager] 销毁应用状态管理器");
this._fsm.clear();
AppStatusManager._instance = null;
}
}