diff --git a/packages/boop-game/src/scenes/GameScene.ts b/packages/boop-game/src/scenes/GameScene.ts index 821765d..d0f036e 100644 --- a/packages/boop-game/src/scenes/GameScene.ts +++ b/packages/boop-game/src/scenes/GameScene.ts @@ -4,6 +4,7 @@ import { GameHostScene } from 'boardgame-phaser'; import { spawnEffect, type Spawner } from 'boardgame-phaser'; import type { ReadonlySignal } from '@preact/signals-core'; import {commands} from "@/game/boop"; +import {MutableSignal} from "boardgame-core"; const BOARD_SIZE = 6; const CELL_SIZE = 80; @@ -38,7 +39,7 @@ export class GameScene extends GameHostScene { this.drawGrid(); this.createSupplyUI(); - this.disposables.add(spawnEffect(new BoopPartSpawner(this, this.gameHost.state))); + this.disposables.add(spawnEffect(new BoopPartSpawner(this, this.gameHost.state as MutableSignal))); this.watch(() => { const winner = this.state.winner; @@ -393,10 +394,10 @@ export class GameScene extends GameHostScene { } class BoopPartSpawner implements Spawner { - constructor(public readonly scene: GameScene, public readonly state: ReadonlySignal) {} + constructor(public readonly scene: GameHostScene) {} *getData() { - for (const part of Object.values(this.state.value.pieces)) { + for (const part of Object.values(this.scene.state.pieces)) { yield part; } } @@ -452,6 +453,7 @@ class BoopPartSpawner implements Spawner duration: 200, ease: 'Back.easeOut', }); + this.state.addInterruption(new Promise(resolve => setTimeout(resolve, 200))); return container; } diff --git a/packages/framework/src/scenes/GameHostScene.ts b/packages/framework/src/scenes/GameHostScene.ts index 185cbe9..540cdad 100644 --- a/packages/framework/src/scenes/GameHostScene.ts +++ b/packages/framework/src/scenes/GameHostScene.ts @@ -15,6 +15,10 @@ export abstract class GameHostScene> { protected disposables = new DisposableBag(); protected gameHost!: GameHost; + + addInterruption(promise: Promise){ + this.gameHost?.addInterruption(promise); + } init(data: GameHostSceneOptions): void { this.gameHost = data.gameHost; @@ -29,7 +33,7 @@ export abstract class GameHostScene> } /** 获取当前状态的只读快照 */ - protected get state(): TState { + public get state(): TState { return this.gameHost.state.value; }