package game import ( "encoding/json" "fmt" "os" "sirlab.de/go/knyt/engine" "sirlab.de/go/knyt/quote" ) func NewGameFromFile(id, fileName string) (*Game, error) { jsonBytes, err := os.ReadFile(fileName) if err != nil { return nil, err } var gmJson GameJson if err := json.Unmarshal(jsonBytes, &gmJson); err != nil { return nil, fmt.Errorf("%s: %v\n", fileName, err) } else { gm := Game{ id: id, name: gmJson.Name, eng: engine.NewEngine(), players: make(map[string]playerInfo, 0), state: STATE_IDLE, quotes: make(map[string]*quote.Quote, 0), } return &gm, nil } } func (gm *Game) StartEngine() { gm.eng.Run(gm.populateSyncDataCb) } func (gm *Game) GetId() string { gm.mu.Lock() defer gm.mu.Unlock() return gm.id } func (gm *Game) GetState() (string, string) { gm.mu.Lock() defer gm.mu.Unlock() return gm.state, gm.phase } func (gm *Game) GetName() string { gm.mu.Lock() defer gm.mu.Unlock() return gm.name } func (gm *Game) GetEngine() *engine.Engine { gm.mu.Lock() defer gm.mu.Unlock() return gm.eng }