Skip to content

Commit

Permalink
Request game when start spectate
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetenstad committed Jan 30, 2024
1 parent 66a5402 commit 4283562
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/stores/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
16 changes: 13 additions & 3 deletions src/stores/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const useOnlineStore = defineStore('online', {
}
}
})
.on('broadcast', { event: 'refresh' }, () => {
this.sendGame()
})
.subscribe()
},

Expand All @@ -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() {
Expand All @@ -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',
Expand Down

0 comments on commit 4283562

Please sign in to comment.