populate round's sources (WIP)
This commit is contained in:
parent
e5d13e1ff0
commit
47199bb6eb
17
server/src/game/getPlayer.go
Normal file
17
server/src/game/getPlayer.go
Normal file
@ -0,0 +1,17 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (gm *Game) getPlayerById(id string) (*playerInfo, error) {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
plInfo := gm.players[id]
|
||||
if plInfo.id == id {
|
||||
return &plInfo, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("player id \"%s\" not found in game\n", id)
|
||||
}
|
18
server/src/game/getQuote.go
Normal file
18
server/src/game/getQuote.go
Normal file
@ -0,0 +1,18 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sirlab.de/go/knyt/quote"
|
||||
)
|
||||
|
||||
func (gm *Game) getQuoteById(id string) (*quote.Quote, error) {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
quote := gm.quotes[id]
|
||||
if quote == nil {
|
||||
return nil, fmt.Errorf("player id \"%s\" not found in game\n", id)
|
||||
}
|
||||
|
||||
return quote, nil
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (gm *Game) setupRound() {
|
||||
gm.round = newRound()
|
||||
gm.selectQuote()
|
||||
@ -16,19 +20,32 @@ func newRound() Round {
|
||||
}
|
||||
|
||||
func (gm *Game) selectQuote() {
|
||||
quote, err := gm.getQuoteById("455df6bc-070d-4728-83ab-481ceafa8590")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
sources := []Source{
|
||||
gm.getSourceById(quote.GetSourceId()),
|
||||
}
|
||||
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
quote := gm.quotes["455df6bc-070d-4728-83ab-481ceafa8590"]
|
||||
gm.round.quoteId = quote.GetId()
|
||||
gm.round.sources = []Source{
|
||||
gm.getSourceById(quote.GetSourceId()),
|
||||
}
|
||||
gm.round.sources = sources
|
||||
}
|
||||
|
||||
func (gm *Game) getSourceById(id string) Source {
|
||||
plInfo, err := gm.getPlayerById(id)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return Source{}
|
||||
}
|
||||
|
||||
return Source{
|
||||
id: id,
|
||||
name: "Herbert",
|
||||
name: plInfo.name,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user