Skip to content

Commit

Permalink
improve maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
fc92 committed Jan 30, 2023
1 parent 4194a2e commit 84a7924
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions internal/common/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,8 @@ func (room *Room) UpdateFromParticipant(voterReceived Participant) {
for i, voter := range room.Voters {
// update room with data received from player
if voter.Id == voterReceived.Id {
room.Voters[i] = &voterReceived
log.Debug().Msgf("last command from %s: %s, vote: %s", room.Voters[i].Name, voterReceived.LastCommand, voterReceived.Vote)
switch voterReceived.LastCommand {
case CommandStartVote:
room.OpenVote()
case CommandCloseVote:
// update status of the received voter based on existing vote existence
if voterReceived.Vote == VoteNotReceived {
voterReceived.LastCommand = VoteNotReceived
} else {
voterReceived.LastCommand = VoteReceived
}
room.CloseVote()
}
// update status of the received voter based on existing vote existence
updateRoomFromReceivedPlayer(room, i, voterReceived)
break
}

Expand All @@ -213,6 +201,23 @@ func (room *Room) UpdateFromParticipant(voterReceived Participant) {
room.updateFromVotes()
}

func updateRoomFromReceivedPlayer(room *Room, i int, voterReceived Participant) {
room.Voters[i] = &voterReceived
log.Debug().Msgf("last command from %s: %s, vote: %s", room.Voters[i].Name, voterReceived.LastCommand, voterReceived.Vote)
switch voterReceived.LastCommand {
case CommandStartVote:
room.OpenVote()
case CommandCloseVote:

if voterReceived.Vote == VoteNotReceived {
voterReceived.LastCommand = VoteNotReceived
} else {
voterReceived.LastCommand = VoteReceived
}
room.CloseVote()
}
}

func updateCommandMenu(room *Room, i int, voterReceived Participant) {
if room.RoomStatus == VoteOpen {
for k := range room.TurnStartedCommands() {
Expand Down

0 comments on commit 84a7924

Please sign in to comment.