2022-12-08 21:14:02 +08:00

31 lines
720 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import State from "./State";
import StateMachine from "./StateMachine";
/***
* 子有限状态机基类
* 用处例如有个idle的state但是有多个方向为了让主状态机更整洁可以把同类型的但具体不同的state都封装在子状态机中
*/
export default abstract class SubStateMachine {
private _currentState: State = null;
stateMachines: Map<string, State> = new Map();
constructor(public fsm: StateMachine) {}
get currentState() {
return this._currentState;
}
set currentState(newState) {
if (!newState) {
return;
}
this._currentState = newState;
this._currentState.run();
}
/***
* 具体类实现
*/
abstract run(): void;
}