send game state to client

This commit is contained in:
Settel 2021-08-12 23:41:47 +02:00
parent ab5416a547
commit 58eafa9e6a
4 changed files with 10 additions and 0 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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 {

View File

@ -8,6 +8,7 @@ type PlayerInfo struct {
type GameInfo struct {
GameId string `json:"id"`
State string `json:"state"`
Players []PlayerInfo `json:"players"`
}