2021-08-06 22:00:18 +00:00
|
|
|
package tins2021
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
"opslag.de/schobers/zntg"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Settings struct {
|
2021-08-10 20:36:42 +00:00
|
|
|
Controls ControlsSettings
|
|
|
|
Window WindowSettings
|
2021-08-06 22:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
return zntg.DecodeJSON(path, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Settings) Store() error {
|
|
|
|
path, err := SettingsPath()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return zntg.EncodeJSON(path, s)
|
|
|
|
}
|
|
|
|
|
2021-08-10 20:36:42 +00:00
|
|
|
type ControlsSettings struct {
|
|
|
|
Type string
|
|
|
|
MoveDownRight string
|
|
|
|
MoveDownLeft string
|
|
|
|
MoveUpLeft string
|
|
|
|
MoveUpRight string
|
|
|
|
}
|
|
|
|
|
2021-08-06 22:00:18 +00:00
|
|
|
type WindowSettings struct {
|
|
|
|
Location *geom.Point
|
|
|
|
Size *geom.Point
|
|
|
|
VSync *bool
|
|
|
|
}
|