Skip to content

Commit

Permalink
Handle show_werewolves packet and make werewolf vote button not appea…
Browse files Browse the repository at this point in the history
…r for other werewolves
  • Loading branch information
Solirs committed Jul 5, 2023
1 parent ba9641e commit 08be159
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion freefang_qt/gameloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Game_loop(QObject):
up = ""
role = ""
players = []
werewolves = [] #Only used if the player is a werewolf
game_started = False


Expand Down Expand Up @@ -125,6 +126,16 @@ def handle_witch_send_dead(self, packet):
self.chatupdate.emit(f"Would you like to revive someone, kill someone else, or pass?")

self.witchaction.emit(packet.dead)

# Handle the packet that is sent to all werewolves on game start
# Which contains the names of all other werewolves
def handle_show_werewolves(self, packet):
for i in packet.headers.werewolves:
if i != self.playername:
self.werewolves.append(i)

if len(self.werewolves) > 0:
self.chatupdate.emit(f"Your fellow werewolves are {' '.join(self.werewolves)}")


def getplayerbyname(self, player):
Expand All @@ -151,7 +162,8 @@ def handle_packet(self, packet):
"town_vote_begin": self.begin_town_vote,
"player_leave": self.handle_leave,
"werewolf_vote": self.handle_werewolf_vote,
"witch_send_dead": self.handle_witch_send_dead
"witch_send_dead": self.handle_witch_send_dead,
"show_werewolves": self.handle_show_werewolves
}
if packet_to_func.get(packet.action):
packet_to_func[packet.action](packet)
Expand Down Expand Up @@ -243,3 +255,6 @@ def witch_revive(self, player):
packet = utils.object_to_json(packets.Witch_revive(player))
net.send_packet(packet, global_data.socket)

@Slot(str, result=bool)
def iswerewolf(self, player):
return player in self.werewolves
3 changes: 3 additions & 0 deletions freefang_qt/qml/Game_UI.qml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ RowLayout{
if (playermodel.get(i).player != game_loop.playername && game_loop.isalive(playermodel.get(i).player)){
playermodel.get(i).buttonsrc = btn;
}
if (act == "Werewolfvote" && game_loop.iswerewolf(playermodel.get(i).player)){
playermodel.get(i).buttonsrc = "";
}
}
}
function onRemove_buttons(){
Expand Down

0 comments on commit 08be159

Please sign in to comment.