refactor: await for tween interruption

This commit is contained in:
hypercross 2026-04-04 15:43:50 +08:00
parent db83e89a46
commit 6c86a97c8f
3 changed files with 12 additions and 7 deletions

View File

@ -120,7 +120,7 @@ registration.add('turn <player>', async function(cmd) {
const pieceType = type === 'cat' ? 'cat' : 'kitten';
placePiece(this.context, row, col, turnPlayer, pieceType);
applyBoops(this.context, row, col, pieceType);
await applyBoops(this.context, row, col, pieceType);
const graduatedLines = checkGraduation(this.context, turnPlayer);
if (graduatedLines.length > 0) {
@ -192,7 +192,7 @@ export function placePiece(host: MutableSignal<BoopState>, row: number, col: num
decrementSupply(playerData, pieceType);
}
export function applyBoops(host: MutableSignal<BoopState>, placedRow: number, placedCol: number, placedType: PieceType) {
export async function applyBoops(host: MutableSignal<BoopState>, placedRow: number, placedCol: number, placedType: PieceType) {
const pieces = host.value.pieces;
const piecesArray = Object.values(pieces);
@ -215,7 +215,7 @@ export function applyBoops(host: MutableSignal<BoopState>, placedRow: number, pl
}
}
host.produce(state => {
await host.produceAsync(state => {
const board = state.board;
const currentPieces = state.pieces;

View File

@ -39,7 +39,7 @@ export class GameScene extends GameHostScene<BoopState> {
this.drawGrid();
this.createSupplyUI();
this.disposables.add(spawnEffect(new BoopPartSpawner(this, this.gameHost.state as MutableSignal<BoopState>)));
this.disposables.add(spawnEffect(new BoopPartSpawner(this)));
this.watch(() => {
const winner = this.state.winner;
@ -447,13 +447,12 @@ class BoopPartSpawner implements Spawner<BoopPart, Phaser.GameObjects.Container>
// 添加落子动画
container.setScale(0);
this.scene.tweens.add({
this.scene.addTweenInterruption(this.scene.tweens.add({
targets: container,
scale: 1,
duration: 200,
ease: 'Back.easeOut',
});
this.state.addInterruption(new Promise(resolve => setTimeout(resolve, 200)));
}));
return container;
}

View File

@ -19,6 +19,12 @@ export abstract class GameHostScene<TState extends Record<string, unknown>>
addInterruption(promise: Promise<void>){
this.gameHost?.addInterruption(promise);
}
addTweenInterruption(tween: Phaser.Tweens.Tween){
this.addInterruption(new Promise(
resolve => tween.once('complete', resolve)
));
}
init(data: GameHostSceneOptions<TState>): void {
this.gameHost = data.gameHost;