Spaces:
Running
Running
File size: 1,012 Bytes
e6b949c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import { InputMode } from "./InputMode";
class ModeManager {
private static _instance: ModeManager;
private static _modeFactories: Map<string, () => InputMode> = new Map();
private static _currentMode: InputMode | null = null;
public static get instance(): ModeManager {
if (!ModeManager._instance) {
ModeManager._instance = new ModeManager();
}
return ModeManager._instance;
}
public static registerMode(name: string, factory: () => InputMode) {
this._modeFactories.set(name, factory);
}
public static enterMode(name: string) {
const factory = this._modeFactories.get(name);
if (factory) {
this._currentMode?.exit();
this._currentMode = factory();
} else {
console.error(`No mode registered with name ${name}.`);
}
}
public static exitCurrentMode() {
this._currentMode?.exit();
this._currentMode = null;
}
}
export { ModeManager };
|