Start reorganising for multiple games
This commit is contained in:
@@ -2,15 +2,16 @@ package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type Ordoor struct {
|
||||
DataDir string `toml:"data_dir"`
|
||||
VideoPlayer []string `toml:"video_player"`
|
||||
type Engine struct {
|
||||
DataDir string `toml:"data_dir"`
|
||||
Palette string `toml:"palette"`
|
||||
}
|
||||
|
||||
// Things set in the options hash
|
||||
@@ -38,12 +39,40 @@ type Options struct {
|
||||
type Config struct {
|
||||
filename string `toml:"-"`
|
||||
|
||||
VideoPlayer []string `toml:"video_player"`
|
||||
Engines map[string]Engine `toml:"engines"`
|
||||
|
||||
DefaultEngineName string `toml:"default_engine"`
|
||||
|
||||
// FIXME: options may well end up being per-engine too
|
||||
Defaults *Options `toml:"-"`
|
||||
Ordoor `toml:"ordoor"`
|
||||
Options `toml:"options"`
|
||||
}
|
||||
|
||||
func Load(filename string) (*Config, error) {
|
||||
func (c *Config) Engine(name string) *Engine {
|
||||
engine, ok := c.Engines[name]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &engine
|
||||
}
|
||||
|
||||
func (c *Config) DefaultEngine() *Engine {
|
||||
return c.Engine(c.DefaultEngineName)
|
||||
}
|
||||
|
||||
// TODO: case-insensitive lookup
|
||||
func (c *Config) DataFile(engine string, path string) string {
|
||||
cfg, ok := c.Engines[engine]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return filepath.Join(cfg.DataDir, path)
|
||||
}
|
||||
|
||||
func Load(filename string, overrideDefaultEngine string) (*Config, error) {
|
||||
var out Config
|
||||
|
||||
_, err := toml.DecodeFile(filename, &out)
|
||||
@@ -53,7 +82,15 @@ func Load(filename string) (*Config, error) {
|
||||
|
||||
out.filename = filename
|
||||
|
||||
return &out, err
|
||||
if overrideDefaultEngine != "" {
|
||||
out.DefaultEngineName = overrideDefaultEngine
|
||||
}
|
||||
|
||||
if out.DefaultEngine() == nil {
|
||||
return nil, fmt.Errorf("Default engine %q not configured", out.DefaultEngineName)
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *Config) HasUnsetOptions() bool {
|
||||
@@ -72,11 +109,6 @@ func (c *Config) Save() error {
|
||||
return toml.NewEncoder(f).Encode(c)
|
||||
}
|
||||
|
||||
// TODO: case-insensitive lookup
|
||||
func (c *Config) DataFile(path string) string {
|
||||
return filepath.Join(c.DataDir, path)
|
||||
}
|
||||
|
||||
func (c *Config) ResetDefaults() error {
|
||||
if c.Defaults == nil {
|
||||
return errors.New("Defaults not available")
|
||||
|
Reference in New Issue
Block a user