refactoring

This commit is contained in:
Settel 2021-08-08 21:57:49 +02:00
parent 91d3fc9265
commit cbc7369b8d
3 changed files with 13 additions and 7 deletions

View File

@ -15,13 +15,16 @@ func NewGameFromFile(id, fileName string) (*Game, error) {
return nil, err return nil, err
} }
var gm Game var gmJson GameJson
if err := json.Unmarshal(jsonBytes, &gm); err != nil { if err := json.Unmarshal(jsonBytes, &gmJson); err != nil {
return nil, fmt.Errorf("%s: %v\n", fileName, err) return nil, fmt.Errorf("%s: %v\n", fileName, err)
} else { } else {
gm.id = id gm := Game{
gm.eng = engine.NewEngine(id) id: id,
gm.playerTimestamp = make(map[string]time.Time) name: gmJson.Name,
eng: engine.NewEngine(id),
playerTimestamp: make(map[string]time.Time),
}
go gm.eng.Run() go gm.eng.Run()

View File

@ -7,7 +7,11 @@ import (
type Game struct { type Game struct {
id string id string
Name string `json:"name"` name string
eng *engine.Engine eng *engine.Engine
playerTimestamp map[string]time.Time playerTimestamp map[string]time.Time
} }
type GameJson struct {
Name string `json:"name"`
}

View File

@ -6,6 +6,5 @@ type Gameinfo struct {
type SyncData struct { type SyncData struct {
VersionRef int `json:"version"` VersionRef int `json:"version"`
Players []string `json:"players"`
Gameinfo *Gameinfo `json:"game"` Gameinfo *Gameinfo `json:"game"`
} }