38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { ReactiveScene } from "./ReactiveScene";
|
|
|
|
import type { GameHost } from "boardgame-core";
|
|
|
|
export interface GameHostSceneOptions<TState extends Record<string, unknown>> {
|
|
gameHost: GameHost<TState>;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
export abstract class GameHostScene<
|
|
TState extends Record<string, unknown>,
|
|
> extends ReactiveScene<GameHostSceneOptions<TState>> {
|
|
public get gameHost(): GameHost<TState> {
|
|
const gameHost = this.initData.gameHost as GameHost<TState>;
|
|
if (!gameHost) {
|
|
throw new Error(
|
|
`GameHostScene (${this.scene.key}): gameHost 未提供。` +
|
|
"确保在 PhaserScene 组件的 data 属性中传入 gameHost。",
|
|
);
|
|
}
|
|
return gameHost;
|
|
}
|
|
|
|
public get state(): TState {
|
|
return this.gameHost?.state.value;
|
|
}
|
|
|
|
addInterruption(promise: Promise<void>) {
|
|
this.gameHost?.addInterruption(promise);
|
|
}
|
|
|
|
addTweenInterruption(tween: Phaser.Tweens.Tween) {
|
|
this.addInterruption(
|
|
new Promise((resolve) => tween.once("complete", resolve)),
|
|
);
|
|
}
|
|
}
|