Skip to content

Commit

Permalink
trigger onActivePlayerChange when last player exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pejosonic committed Aug 14, 2024
1 parent ed2d5d7 commit d34c684
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { initQueueDisplay }
/**
* listeners.onActivePlayerChange = (player) => player.address
*/
export const listeners: { onActivePlayerChange: (player: PlayerType) => void } = {
export const listeners: { onActivePlayerChange: (player: PlayerType | null) => void } = {
onActivePlayerChange: () => {}
}
let initializedQueue = false
Expand Down Expand Up @@ -121,9 +121,10 @@ export function setNextPlayer() {
lastActivePlayer = nextPlayer.player.address
Player.getMutable(nextPlayer.entity).active = true
Player.getMutable(nextPlayer.entity).startPlayingAt = Date.now()
if (listeners.onActivePlayerChange) {
listeners.onActivePlayerChange(Player.get(nextPlayer.entity))
}
}

if (listeners.onActivePlayerChange) {
listeners.onActivePlayerChange(Player.getOrNull(nextPlayer?.entity))
}
}

Expand Down

0 comments on commit d34c684

Please sign in to comment.