2021-08-06 22:00:18 +00:00
|
|
|
package tins2021
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
|
|
|
|
2021-08-11 06:03:02 +00:00
|
|
|
const settingsFileName = "settings.json"
|
|
|
|
|
2021-08-17 16:22:22 +00:00
|
|
|
type AudioSettings struct {
|
|
|
|
SoundVolume float64
|
|
|
|
MusicVolume float64
|
|
|
|
}
|
|
|
|
|
|
|
|
type ControlsSettings struct {
|
|
|
|
Type string
|
|
|
|
MoveDownRight string
|
|
|
|
MoveDownLeft string
|
|
|
|
MoveUpLeft string
|
|
|
|
MoveUpRight string
|
|
|
|
}
|
|
|
|
|
2021-08-06 22:00:18 +00:00
|
|
|
type Settings struct {
|
2021-08-17 16:22:22 +00:00
|
|
|
Audio AudioSettings
|
2021-08-10 20:36:42 +00:00
|
|
|
Controls ControlsSettings
|
|
|
|
Window WindowSettings
|
2021-08-06 22:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Settings) Init() error {
|
2021-08-11 06:03:02 +00:00
|
|
|
err := LoadUserFileJSON(settingsFileName, s)
|
|
|
|
if os.IsNotExist(err) {
|
2021-08-06 22:00:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-08-11 06:03:02 +00:00
|
|
|
return err
|
2021-08-06 22:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Settings) Store() error {
|
2021-08-11 06:03:02 +00:00
|
|
|
return SaveUserFileJSON(settingsFileName, s)
|
2021-08-06 22:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type WindowSettings struct {
|
|
|
|
Location *geom.Point
|
|
|
|
Size *geom.Point
|
|
|
|
VSync *bool
|
|
|
|
}
|