Slash-The-Hordes/assets/Scripts/Services/ModalWindowSystem/ModalWindow.ts

29 lines
780 B
TypeScript
Raw Normal View History

2022-11-23 08:01:01 +00:00
import { Animation, Component, _decorator } from "cc";
2022-11-17 17:28:39 +00:00
import { delay } from "../Utils/AsyncUtils";
2022-11-23 08:01:01 +00:00
const { property } = _decorator;
2022-11-17 17:28:39 +00:00
export abstract class ModalWindow<TParam, TResult> extends Component {
2022-11-23 08:01:01 +00:00
@property(Animation) private animation: Animation;
2022-11-17 17:28:39 +00:00
private result: TResult;
private isDismissed = false;
public async runAsync(params?: TParam): Promise<TResult> {
this.setup(params);
2022-11-23 08:01:01 +00:00
this.animation?.play("open");
2022-11-17 17:28:39 +00:00
while (!this.isDismissed) await delay(100);
2022-11-23 08:01:01 +00:00
this.animation?.play("close");
2022-11-17 17:28:39 +00:00
2022-11-23 08:01:01 +00:00
await delay(500);
2022-11-17 17:28:39 +00:00
return this.result;
}
protected abstract setup(params?: TParam): void;
protected dismiss(result?: TResult): void {
this.result = result;
this.isDismissed = true;
}
}