Skip to content

Commit

Permalink
allow keeping owner
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoxamin committed Oct 29, 2024
1 parent b2b9eac commit b45d04b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend/bang/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, name):
self.rpc_log = []
self.is_replay = False
self.replay_speed = 1
self.owner: str | None = None

def shuffle_players(self):
if not self.started:
Expand Down Expand Up @@ -254,6 +255,7 @@ def notify_room(self, sid=None):
"available_expansions": self.available_expansions,
"is_replay": self.is_replay,
"characters_to_distribute": self.characters_to_distribute,
"owner": self.owner,
},
)
G.sio.emit("debug", room=self.name, data=self.debug)
Expand Down Expand Up @@ -308,6 +310,8 @@ def add_player(self, player: pl.Player):
if player.is_admin():
self.feature_flags()
self.players.append(player)
if len(self.players) == 1:
self.owner = player.name
if len(self.players) > 7:
if "dodge_city" not in self.expansions:
self.expansions.append("dodge_city")
Expand Down Expand Up @@ -989,6 +993,8 @@ def handle_disconnect(self, player: pl.Player):
self.deck = None
return True
else:
self.owner = next((p.name for p in self.players if not p.is_bot), None)
self.notify_room()
return False

def player_death(self, player: pl.Player, disconnected=False):
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/components/Lobby.vue
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export default {
fullScreenEffects: [],
showPopup: false,
selectedExpansionInfo: {},
owner: undefined,
}),
sockets: {
expansion_info(data) {
Expand All @@ -503,6 +504,7 @@ export default {
this.togglable_expansions = data.available_expansions;
this.expansions = data.expansions;
this.is_replay = data.is_replay;
this.owner = data.owner;
this.characters_to_distribute = data.characters_to_distribute;
this.players = data.players.map((x) => {
return {
Expand Down Expand Up @@ -729,11 +731,7 @@ export default {
return "";
},
isRoomOwner() {
if (this.players.length > 0) {
let pls = this.players.filter((x) => !x.is_bot);
return pls.length > 0 && pls[0].name == this.username;
}
return false;
return this.owner === this.username;
},
startGameCard() {
if (!this.started && this.players.length > 2 && this.isRoomOwner) {
Expand Down

0 comments on commit b45d04b

Please sign in to comment.