knowyt/server/src/game/saveSelection.go

31 lines
599 B
Go
Raw Normal View History

2021-08-30 08:55:07 +00:00
package game
import (
2021-08-30 16:21:14 +00:00
"fmt"
2021-08-30 08:55:07 +00:00
"sirlab.de/go/knyt/user"
)
2021-08-30 10:24:28 +00:00
func (gm *Game) SaveSelection(usr *user.User, selection string) {
gm.updateSelection(usr, selection)
gm.notifyClients()
}
func (gm *Game) updateSelection(usr *user.User, selection string) {
2021-08-30 08:55:07 +00:00
gm.mu.Lock()
defer gm.mu.Unlock()
2021-08-30 16:21:14 +00:00
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("invalid selection id \"%s\"\n", selection)
2021-08-30 08:55:07 +00:00
}