send game state to client
This commit is contained in:
parent
ab5416a547
commit
58eafa9e6a
@ -22,6 +22,7 @@ func NewGameFromFile(id, fileName string) (*Game, error) {
|
||||
name: gmJson.Name,
|
||||
eng: engine.NewEngine(),
|
||||
players: make(map[string]playerInfo),
|
||||
state: STATE_IDLE,
|
||||
}
|
||||
|
||||
go gm.eng.Run(gm.populateSyncDataCb)
|
||||
|
@ -13,6 +13,8 @@ func (gm *Game) populatePlayers(syncData *syncdata.SyncData) {
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
syncData.GameInfo.GameId = gm.id
|
||||
syncData.GameInfo.State = gm.state
|
||||
|
||||
players := make([]syncdata.PlayerInfo, 0)
|
||||
for _, p := range gm.players {
|
||||
if p.isPlaying {
|
||||
|
@ -5,6 +5,11 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
STATE_IDLE = "idle"
|
||||
STATE_ENTER_STATEMENTS = "enter-statements"
|
||||
)
|
||||
|
||||
type playerInfo struct {
|
||||
id string
|
||||
name string
|
||||
@ -18,6 +23,7 @@ type Game struct {
|
||||
name string
|
||||
players map[string]playerInfo
|
||||
eng *engine.Engine
|
||||
state string
|
||||
}
|
||||
|
||||
type GameJson struct {
|
||||
|
@ -8,6 +8,7 @@ type PlayerInfo struct {
|
||||
|
||||
type GameInfo struct {
|
||||
GameId string `json:"id"`
|
||||
State string `json:"state"`
|
||||
Players []PlayerInfo `json:"players"`
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user