tins2020/gamestate.go

60 lines
973 B
Go
Raw Permalink Normal View History

2020-05-11 01:09:01 +00:00
package tins2020
import (
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg"
)
2020-05-11 01:09:01 +00:00
type FlowerState struct {
ID string
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 {
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
}
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
}
return zntg.DecodeJSON(path, &s)
2020-05-11 01:09:01 +00:00
}
func SaveGameName() string { return "savegame.json" }