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