Files
ordoor/internal/config/config.go

70 lines
1.3 KiB
Go
Raw Normal View History

2018-10-13 03:23:55 +01:00
package config
import (
"os"
2018-10-13 03:23:55 +01:00
"path/filepath"
"github.com/BurntSushi/toml"
)
2020-03-22 17:56:24 +00:00
type Ordoor struct {
2018-10-13 03:23:55 +01:00
DataDir string `toml:"data_dir"`
VideoPlayer []string `toml:"video_player"`
}
// Things set
type Options struct {
PlayMovies bool `toml:"play_movies"`
Animations bool `toml:"animations"`
PlayMusic bool `toml:"play_music"`
CombatVoices bool `toml:"combat_voices"`
ShowGrid bool `toml:"show_grid"`
ShowPaths bool `toml:"show_paths"`
PointSaving bool `toml:"point_saving"`
AutoCutLevel bool `toml:"auto_cut_level"`
XRes int `toml:"x_resolution"`
YRes int `toml:"y_resolution"`
MusicVolume int `toml:"music_volume"`
SFXVolume int `toml:"sfx_volume"`
UnitSpeed int `toml:"unit_speed"`
AnimSpeed int `toml:"animation_speed"`
}
2018-10-13 03:23:55 +01:00
type Config struct {
filename string `toml:"-"`
Ordoor `toml:"ordoor"`
Options `toml:"options"`
2018-10-13 03:23:55 +01:00
}
func Load(filename string) (*Config, error) {
var out Config
_, err := toml.DecodeFile(filename, &out)
if err != nil {
return nil, err
}
out.filename = filename
2018-10-13 03:23:55 +01:00
return &out, err
}
func (c *Config) Save() error {
f, err := os.OpenFile(c.filename, os.O_WRONLY, 0644)
if err != nil {
return err
}
defer f.Close()
return toml.NewEncoder(f).Encode(c)
}
2018-10-13 03:23:55 +01:00
// TODO: case-insensitive lookup
func (c *Config) DataFile(path string) string {
return filepath.Join(c.DataDir, path)
}