refactor: expose addInterruption
This commit is contained in:
parent
0dbb4fc2ba
commit
db83e89a46
|
|
@ -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<BoopState> {
|
|||
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<BoopState>)));
|
||||
|
||||
this.watch(() => {
|
||||
const winner = this.state.winner;
|
||||
|
|
@ -393,10 +394,10 @@ export class GameScene extends GameHostScene<BoopState> {
|
|||
}
|
||||
|
||||
class BoopPartSpawner implements Spawner<BoopPart, Phaser.GameObjects.Container> {
|
||||
constructor(public readonly scene: GameScene, public readonly state: ReadonlySignal<BoopState>) {}
|
||||
constructor(public readonly scene: GameHostScene<BoopState>) {}
|
||||
|
||||
*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<BoopPart, Phaser.GameObjects.Container>
|
|||
duration: 200,
|
||||
ease: 'Back.easeOut',
|
||||
});
|
||||
this.state.addInterruption(new Promise(resolve => setTimeout(resolve, 200)));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ export abstract class GameHostScene<TState extends Record<string, unknown>>
|
|||
protected disposables = new DisposableBag();
|
||||
protected gameHost!: GameHost<TState>;
|
||||
|
||||
addInterruption(promise: Promise<void>){
|
||||
this.gameHost?.addInterruption(promise);
|
||||
}
|
||||
|
||||
init(data: GameHostSceneOptions<TState>): void {
|
||||
this.gameHost = data.gameHost;
|
||||
}
|
||||
|
|
@ -29,7 +33,7 @@ export abstract class GameHostScene<TState extends Record<string, unknown>>
|
|||
}
|
||||
|
||||
/** 获取当前状态的只读快照 */
|
||||
protected get state(): TState {
|
||||
public get state(): TState {
|
||||
return this.gameHost.state.value;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue