31 lines
611 B
Go
31 lines
611 B
Go
package game
|
|
|
|
import (
|
|
"fmt"
|
|
"sirlab.de/go/knowyt/user"
|
|
)
|
|
|
|
func (gm *Game) SaveSelection(usr *user.User, selection string) {
|
|
gm.updateSelection(usr, selection)
|
|
gm.notifyClients()
|
|
}
|
|
|
|
func (gm *Game) updateSelection(usr *user.User, selection string) {
|
|
gm.mu.Lock()
|
|
defer gm.mu.Unlock()
|
|
|
|
if selection == PLAYER_SELECTION_NONE {
|
|
gm.round.selections[usr.GetId()] = PLAYER_SELECTION_NONE
|
|
return
|
|
}
|
|
|
|
for _, source := range gm.round.sources {
|
|
if source.id == selection {
|
|
gm.round.selections[usr.GetId()] = selection
|
|
return
|
|
}
|
|
}
|
|
|
|
fmt.Printf("%s invalid selection id \"%s\"\n", gm.id, selection)
|
|
}
|