diff --git a/backend/bang/game.py b/backend/bang/game.py index d6db2e2..119b75c 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -80,6 +80,11 @@ class Game: self.rpc_log = [] self.is_replay = False + def shuffle_players(self): + if not self.started: + random.shuffle(self.players) + self.notify_room() + def reset(self): for p in self.players: if (p.sid == p.name): diff --git a/backend/server.py b/backend/server.py index ee4dc7f..02b8b58 100644 --- a/backend/server.py +++ b/backend/server.py @@ -330,6 +330,12 @@ def start_game(sid): ses.game.start_game() advertise_lobbies() +@sio.event +@bang_handler +def shuffle_players(sid): + ses: Player = sio.get_session(sid) + ses.game.shuffle_players() + @sio.event @bang_handler def set_character(sid, name): diff --git a/frontend/src/components/Lobby.vue b/frontend/src/components/Lobby.vue index 98cd654..82031d8 100644 --- a/frontend/src/components/Lobby.vue +++ b/frontend/src/components/Lobby.vue @@ -70,6 +70,7 @@ 🤖 +
@@ -240,7 +241,7 @@ export default { return '' }, isRoomOwner() { - return this.players.length > 0 && this.players[0].name == this.username + return this.players.length > 0 && this.players.filter(x => !x.is_bot)[0].name == this.username }, startGameCard() { if (!this.started && this.players.length > 2 && this.isRoomOwner) { @@ -253,6 +254,16 @@ export default { } return null; }, + shufflePlayersCard() { + if (!this.started && this.players.length > 2 && this.isRoomOwner) { + return { + name: this.$t('shuffle_players'), + icon: '🔀', + is_equipment: true, + } + } + return null; + }, playersTable() { if (Vue.config.devtools) console.log('update players') @@ -302,11 +313,12 @@ export default { }, getPlayerCard(player) { let icon = '' + let owner = this.players.filter(x => !x.is_bot)[0]; if (!this.started) icon = '🤠' else icon = player.ready !== undefined ? ((player.ready)?'👍': '🤔') : (player.is_sheriff ? '⭐' : player.icon) return { name: player.name, - number: ((this.username == player.name) ? this.$t('you') : (this.players[0].name == player.name) ? this.$t('owner') :'') + (player.dist ? `${player.dist}⛰` : ''), + number: ((this.username == player.name) ? this.$t('you') : (owner.name == player.name) ? this.$t('owner') :'') + (player.dist ? `${player.dist}⛰` : ''), icon: icon, is_character: true, avatar: player.avatar, @@ -316,6 +328,10 @@ export default { this.started = true; this.$socket.emit('start_game') }, + shufflePlayers() { + this.started = true; + this.$socket.emit('shuffle_players') + }, choose(player_name) { if (Vue.config.devtools) console.log('choose from' + player_name) diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index dfb6546..c9264a1 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -9,6 +9,7 @@ "tip_7": "If you want to help us translate the game in your language, ping us on discord!", "tip_8": "If you disconnect during in an ongoing game you will be replaced by a bot (while you are gone)!", "online_players": "Online players: ", + "shuffle_players": "Shuffle Players", "choose_username": "Pick an username:", "report_bug": "Write what the bug consists of", "report": "Report a bug", diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json index 1c0b00e..81ac1ca 100644 --- a/frontend/src/i18n/it.json +++ b/frontend/src/i18n/it.json @@ -9,6 +9,7 @@ "tip_7": "Se vuoi aiutarci a tradurre il gioco nella tua lingua scrivicelo su discord!", "tip_8": "Se ti disconnetti durante una partita verrai sostituito da un bot (durante la tua assenza)!", "online_players": "Giocatori online: ", + "shuffle_players": "Riordina Giocatori", "choose_username": "Scegli un username:", "report_bug":"Scrivi in cosa consiste il bug", "report":"Segnala un bug",