diff --git a/server/src/events/RandomizeTeams.ts b/server/src/events/RandomizeTeams.ts index 76beb27..df3f009 100644 --- a/server/src/events/RandomizeTeams.ts +++ b/server/src/events/RandomizeTeams.ts @@ -16,6 +16,11 @@ export default (io: Server, socket: Socket, data: RandomizeTeams) => { }; let game = games[data.game_code]; + // Remove all players from all teams + for (var team of game.teams) { + team.removePlayers(); + }; + let players = [...game.players]; // game.log.info(players); let new_team: 1|2 = 1; @@ -39,6 +44,9 @@ export default (io: Server, socket: Socket, data: RandomizeTeams) => { player.role = `guesser`; player.team = new_team; + // Update the team object + game.teams[new_team - 1].guessers.push(player); + // Add the next player to the other team new_team = new_team == 1 ? 2 : 1; diff --git a/server/src/objects/Team.ts b/server/src/objects/Team.ts index 530cc57..30882a8 100644 --- a/server/src/objects/Team.ts +++ b/server/src/objects/Team.ts @@ -37,6 +37,27 @@ export class Team { }; + /** + * Removes all players from the team. + */ + public removePlayers() { + + // Reset the writer + if (this.writer) { + this.writer.team = null; + this.writer.role = null; + this.writer = null; + }; + + // Reset all the guessers + for (var player of this.guessers) { + player.team = null; + player.role = null; + } + this.guessers = []; + }; + + /** * Resets all the per-game data related to this team */ @@ -44,7 +65,7 @@ export class Team { this._hand.guesser = []; this._questions = []; this._answers = new Array(8).fill(``); - } + }; /** diff --git a/web/src/App.vue b/web/src/App.vue index 51dc946..c7c8102 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,5 +1,16 @@