knowyt/server/src/application/loadGames.go

28 lines
488 B
Go
Raw Normal View History

2021-08-04 22:12:28 +00:00
package application
import (
"os"
"path"
"sirlab.de/go/knyt/game"
)
func (app Application) loadGames() error {
dirName := path.Join(app.config.DataDir, "games")
files, err := os.ReadDir(dirName)
if err != nil {
return err
}
for _, file := range files {
fileName := path.Join(dirName, file.Name(), "game.json")
if gm, err := game.NewGameFromFile(fileName); err != nil {
return err
} else {
2021-08-04 22:40:31 +00:00
gm.SetId(file.Name())
app.games[gm.GetId()] = gm
2021-08-04 22:12:28 +00:00
}
}
return nil
}