31 lines
720 B
TypeScript
Raw Normal View History

2022-12-08 21:14:02 +08:00
import State from "./State";
import StateMachine from "./StateMachine";
2022-11-27 23:23:47 +08:00
/***
*
* idle的statestate都封装在子状态机中
*/
export default abstract class SubStateMachine {
2022-12-08 21:14:02 +08:00
private _currentState: State = null;
stateMachines: Map<string, State> = new Map();
2022-11-27 23:23:47 +08:00
constructor(public fsm: StateMachine) {}
get currentState() {
2022-12-08 21:14:02 +08:00
return this._currentState;
2022-11-27 23:23:47 +08:00
}
set currentState(newState) {
if (!newState) {
2022-12-08 21:14:02 +08:00
return;
2022-11-27 23:23:47 +08:00
}
2022-12-08 21:14:02 +08:00
this._currentState = newState;
this._currentState.run();
2022-11-27 23:23:47 +08:00
}
/***
*
*/
2022-12-08 21:14:02 +08:00
abstract run(): void;
2022-11-27 23:23:47 +08:00
}