Implement the options menu, part 1
This commit implements loading and saving options from/to config, and enough UI toolkit magic to allow changes to boolean options to be persisted. We now respect the "play movies" setting and take screen resolution from the config file.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
@@ -11,8 +12,32 @@ type Ordoor struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Ordoor `toml:"ordoor"`
|
||||
filename string `toml:"-"`
|
||||
|
||||
Ordoor `toml:"ordoor"`
|
||||
Options `toml:"options"`
|
||||
}
|
||||
|
||||
func Load(filename string) (*Config, error) {
|
||||
@@ -23,9 +48,21 @@ func Load(filename string) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.filename = filename
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// TODO: case-insensitive lookup
|
||||
func (c *Config) DataFile(path string) string {
|
||||
return filepath.Join(c.DataDir, path)
|
||||
|
Reference in New Issue
Block a user