tins2020/settings.go

42 lines
637 B
Go
Raw Normal View History

2020-05-08 16:38:26 +00:00
package tins2020
2020-05-17 08:56:56 +00:00
import (
"os"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg"
)
2020-05-08 16:38:26 +00:00
type Settings struct {
Window WindowSettings
}
func SettingsPath() (string, error) {
return UserFile("settings.json")
}
func (s *Settings) Init() error {
path, err := SettingsPath()
if err != nil {
return err
}
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil
}
2020-05-17 08:56:56 +00:00
return zntg.DecodeJSON(path, s)
2020-05-08 16:38:26 +00:00
}
func (s *Settings) Store() error {
path, err := SettingsPath()
if err != nil {
return err
}
2020-05-17 08:56:56 +00:00
return zntg.EncodeJSON(path, s)
2020-05-08 16:38:26 +00:00
}
type WindowSettings struct {
2020-05-17 08:56:56 +00:00
Location *geom.Point
Size *geom.Point
2020-05-10 23:20:23 +00:00
VSync *bool
2020-05-08 16:38:26 +00:00
}