28 lines
481 B
Go
28 lines
481 B
Go
|
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 {
|
||
|
gm.Id = file.Name()
|
||
|
app.games[gm.Id] = gm
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|