populate round's sources (WIP)

This commit is contained in:
Settel 2021-09-06 23:31:09 +02:00
parent e5d13e1ff0
commit 47199bb6eb
3 changed files with 57 additions and 5 deletions

View 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)
}

View 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
}

View File

@ -1,5 +1,9 @@
package game package game
import (
"fmt"
)
func (gm *Game) setupRound() { func (gm *Game) setupRound() {
gm.round = newRound() gm.round = newRound()
gm.selectQuote() gm.selectQuote()
@ -16,19 +20,32 @@ func newRound() Round {
} }
func (gm *Game) selectQuote() { 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() gm.mu.Lock()
defer gm.mu.Unlock() defer gm.mu.Unlock()
quote := gm.quotes["455df6bc-070d-4728-83ab-481ceafa8590"]
gm.round.quoteId = quote.GetId() gm.round.quoteId = quote.GetId()
gm.round.sources = []Source{ gm.round.sources = sources
gm.getSourceById(quote.GetSourceId()),
}
} }
func (gm *Game) getSourceById(id string) Source { func (gm *Game) getSourceById(id string) Source {
plInfo, err := gm.getPlayerById(id)
if err != nil {
fmt.Println(err)
return Source{}
}
return Source{ return Source{
id: id, id: id,
name: "Herbert", name: plInfo.name,
} }
} }