Open equationcrunchor opened 4 years ago
Thanks for the bug report. Not sure when I'll get around to fixing this, I don't know how simple it will be.
I noticed the same issue today. Looking through your code (which is incredibly clear and well-documented btw), I think one could just add an if statement on line 208 of game.js that checks if the winnerid is set when a player is leaving in the state WAITING_FOR_PLAYERS.
if (state.state.winnerIdx != null) {
if (state.state.winnerIdx == playerIdx) {
setState({
name: stateNames.WAITING_FOR_PLAYERS,
winnerIdx: null,
playerIdx: null
});
}
else if (state.state.winnerIdx > playerIdx) {
setState({
name: stateNames.WAITING_FOR_PLAYERS,
winnerIdx: state.state.winnerIdx - 1,
playerIdx: null
});
}
}
So if the player who is leaving is the winner, the winner gets set to null (but their win will still be recorded in the game history), or if the leaving player's index is lower than the winner, the winner index is decremented.
I understand if you'd rather add a new state that differentiates between WAITING_FOR_PLAYERS and WAITING_TO_PLAY_AGAIN which would obviously be a larger change.
It appears that after the game ends, the game remembers the position of the player that won (e.g. the fourth player). However, if a player leaves, changing the order of players, the name in the banner message will change to the player who is now in that position, regardless of who actually won.