2020-05-11 01:09:01 +00:00
|
|
|
package tins2020
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
import (
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
"opslag.de/schobers/zntg"
|
|
|
|
)
|
|
|
|
|
2020-05-11 01:09:01 +00:00
|
|
|
type FlowerState struct {
|
|
|
|
ID string
|
2020-05-17 08:56:56 +00:00
|
|
|
Location geom.Point
|
2020-05-11 01:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GameState struct {
|
|
|
|
Balance int
|
|
|
|
Speed GameSpeed
|
|
|
|
Herbarium HerbariumState
|
|
|
|
Terrain TerrainState
|
|
|
|
View ViewState
|
|
|
|
}
|
|
|
|
|
|
|
|
type HerbariumState struct {
|
|
|
|
Flowers []HerbariumFlowerState
|
|
|
|
}
|
|
|
|
|
|
|
|
type HerbariumFlowerState struct {
|
|
|
|
ID string
|
|
|
|
Unlocked bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type TerrainState struct {
|
|
|
|
Temperature int64
|
|
|
|
Humidity int64
|
|
|
|
Variant int64
|
|
|
|
PlaceX int64
|
|
|
|
PlaceY int64
|
|
|
|
Flowers []FlowerState
|
|
|
|
}
|
|
|
|
|
|
|
|
type ViewState struct {
|
2020-05-17 08:56:56 +00:00
|
|
|
Center geom.Point
|
2020-05-11 01:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *GameState) Serialize(name string) error {
|
|
|
|
path, err := UserFile(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-17 08:56:56 +00:00
|
|
|
return zntg.EncodeJSON(path, &s)
|
2020-05-11 01:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *GameState) Deserialize(name string) error {
|
|
|
|
path, err := UserFile(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-17 08:56:56 +00:00
|
|
|
return zntg.DecodeJSON(path, &s)
|
2020-05-11 01:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func SaveGameName() string { return "savegame.json" }
|