Skip to content

Commit

Permalink
refactor for maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
fc92 committed Jan 30, 2023
1 parent f5e791e commit 4194a2e
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions internal/common/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,31 @@ func (room *Room) UpdateFromParticipant(voterReceived Participant) {

// add new player
if i == len(room.Voters)-1 {
if room.RoomStatus == VoteOpen {
for k := range room.TurnStartedCommands() {
room.Voters[i].AvailableCommands[k] = room.TurnStartedCommands()[k]
}
for l := range room.VoteCommands() {
room.Voters[i].AvailableCommands[l] = room.VoteCommands()[l]
}
room.Voters = append(room.Voters, &voterReceived)
} else {
room.Voters = append(room.Voters, &voterReceived)
// update command menu
room.CloseVote()
}
// update command menu
updateCommandMenu(room, i, voterReceived)
}
}

}
room.updateFromVotes()
}

func updateCommandMenu(room *Room, i int, voterReceived Participant) {
if room.RoomStatus == VoteOpen {
for k := range room.TurnStartedCommands() {
room.Voters[i].AvailableCommands[k] = room.TurnStartedCommands()[k]
}
for l := range room.VoteCommands() {
room.Voters[i].AvailableCommands[l] = room.VoteCommands()[l]
}
room.Voters = append(room.Voters, &voterReceived)
} else {
room.Voters = append(room.Voters, &voterReceived)

room.CloseVote()
}
}

// apply vote rules
func (room *Room) updateFromVotes() {
switch room.RoomStatus {
Expand Down

0 comments on commit 4194a2e

Please sign in to comment.