refactor: await for tween interruption
This commit is contained in:
parent
db83e89a46
commit
6c86a97c8f
|
|
@ -120,7 +120,7 @@ registration.add('turn <player>', async function(cmd) {
|
||||||
const pieceType = type === 'cat' ? 'cat' : 'kitten';
|
const pieceType = type === 'cat' ? 'cat' : 'kitten';
|
||||||
|
|
||||||
placePiece(this.context, row, col, turnPlayer, pieceType);
|
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);
|
const graduatedLines = checkGraduation(this.context, turnPlayer);
|
||||||
if (graduatedLines.length > 0) {
|
if (graduatedLines.length > 0) {
|
||||||
|
|
@ -192,7 +192,7 @@ export function placePiece(host: MutableSignal<BoopState>, row: number, col: num
|
||||||
decrementSupply(playerData, pieceType);
|
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 pieces = host.value.pieces;
|
||||||
const piecesArray = Object.values(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 board = state.board;
|
||||||
const currentPieces = state.pieces;
|
const currentPieces = state.pieces;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export class GameScene extends GameHostScene<BoopState> {
|
||||||
this.drawGrid();
|
this.drawGrid();
|
||||||
this.createSupplyUI();
|
this.createSupplyUI();
|
||||||
|
|
||||||
this.disposables.add(spawnEffect(new BoopPartSpawner(this, this.gameHost.state as MutableSignal<BoopState>)));
|
this.disposables.add(spawnEffect(new BoopPartSpawner(this)));
|
||||||
|
|
||||||
this.watch(() => {
|
this.watch(() => {
|
||||||
const winner = this.state.winner;
|
const winner = this.state.winner;
|
||||||
|
|
@ -447,13 +447,12 @@ class BoopPartSpawner implements Spawner<BoopPart, Phaser.GameObjects.Container>
|
||||||
|
|
||||||
// 添加落子动画
|
// 添加落子动画
|
||||||
container.setScale(0);
|
container.setScale(0);
|
||||||
this.scene.tweens.add({
|
this.scene.addTweenInterruption(this.scene.tweens.add({
|
||||||
targets: container,
|
targets: container,
|
||||||
scale: 1,
|
scale: 1,
|
||||||
duration: 200,
|
duration: 200,
|
||||||
ease: 'Back.easeOut',
|
ease: 'Back.easeOut',
|
||||||
});
|
}));
|
||||||
this.state.addInterruption(new Promise(resolve => setTimeout(resolve, 200)));
|
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,12 @@ export abstract class GameHostScene<TState extends Record<string, unknown>>
|
||||||
this.gameHost?.addInterruption(promise);
|
this.gameHost?.addInterruption(promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addTweenInterruption(tween: Phaser.Tweens.Tween){
|
||||||
|
this.addInterruption(new Promise(
|
||||||
|
resolve => tween.once('complete', resolve)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
init(data: GameHostSceneOptions<TState>): void {
|
init(data: GameHostSceneOptions<TState>): void {
|
||||||
this.gameHost = data.gameHost;
|
this.gameHost = data.gameHost;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue