From 428356251b3b38b08abd9129fd3c281addbe0449 Mon Sep 17 00:00:00 2001 From: magnetenstad Date: Tue, 30 Jan 2024 07:17:04 +0100 Subject: [PATCH] Request game when start spectate --- src/stores/game.ts | 2 +- src/stores/online.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/stores/game.ts b/src/stores/game.ts index 86968f2..b89dc71 100644 --- a/src/stores/game.ts +++ b/src/stores/game.ts @@ -50,8 +50,8 @@ export const useGameStore = defineStore('game', { this.gameState = this.getController().getGameState() if (this.game) { this.game.result = this.gameState.rank - useOnlineStore().sendGame(this.game) } + useOnlineStore().sendGame() this.tryPlayWalkOn() return this.gameState }, diff --git a/src/stores/online.ts b/src/stores/online.ts index ccc6cd8..41c9f89 100644 --- a/src/stores/online.ts +++ b/src/stores/online.ts @@ -62,6 +62,9 @@ export const useOnlineStore = defineStore('online', { } } }) + .on('broadcast', { event: 'refresh' }, () => { + this.sendGame() + }) .subscribe() }, @@ -84,8 +87,13 @@ export const useOnlineStore = defineStore('online', { .on('broadcast', { event: 'game' }, (args) => { this.spectatingGame = args.payload as Game }) - - .subscribe() + .subscribe((status) => { + if (status != 'SUBSCRIBED') return + this.inChannel?.send({ + type: 'broadcast', + event: 'refresh', + }) + }) }, async stopSpectating() { @@ -95,7 +103,9 @@ export const useOnlineStore = defineStore('online', { this.spectatingGame = null }, - sendGame(game: Game) { + sendGame() { + const game = useGameStore().game + if (!game) return this.outChannel?.send({ type: 'broadcast', event: 'game',