2020-01-31 23:18:11 -05:00
|
|
|
package d2config
|
|
|
|
|
|
|
|
import (
|
2020-07-08 09:16:16 -04:00
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"path"
|
2020-11-03 07:54:15 -05:00
|
|
|
"path/filepath"
|
2020-01-31 23:18:11 -05:00
|
|
|
)
|
|
|
|
|
2020-02-01 18:55:56 -05:00
|
|
|
// Configuration defines the configuration for the engine, loaded from config.json
|
|
|
|
type Configuration struct {
|
2020-07-08 09:16:16 -04:00
|
|
|
MpqLoadOrder []string
|
|
|
|
MpqPath string
|
|
|
|
TicksPerSecond int
|
|
|
|
FpsCap int
|
|
|
|
SfxVolume float64
|
|
|
|
BgmVolume float64
|
|
|
|
FullScreen bool
|
|
|
|
RunInBackground bool
|
|
|
|
VsyncEnabled bool
|
|
|
|
Backend string
|
refactored logging in d2loader, d2record, and d2asset (#898)
* refactored logging in d2config, d2record, and d2asset
* asset manager, record manager, and file loader now utilitize d2util.Logger
* added colored logging to d2util.Logger (excluding windows platforms)
* removed mpq file verification from d2config; d2loader handles this
* record loaders now use the record manager's logger for printing info
* added command line argument for setting log level (`--loglevel 4`, `-l4`, or `-l 4`
* added `LogLevel` parameter to config file
* default log level will show errors, warnings, and info log messages
* specifying log level as an argument overrides setting from config file
* fixed log level tests
2020-11-02 21:23:07 -05:00
|
|
|
path string
|
2020-07-04 00:49:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save saves the configuration object to disk
|
|
|
|
func (c *Configuration) Save() error {
|
2020-11-03 07:54:15 -05:00
|
|
|
configDir := path.Dir(c.path)
|
2020-07-08 09:16:16 -04:00
|
|
|
if err := os.MkdirAll(configDir, 0750); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-03 07:54:15 -05:00
|
|
|
configFile, err := os.Create(c.path)
|
2020-07-08 09:16:16 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-03 07:54:15 -05:00
|
|
|
buf, err := json.MarshalIndent(c, "", " ")
|
2020-07-08 09:16:16 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
|
|
|
|
2020-07-08 09:16:16 -04:00
|
|
|
if _, err := configFile.Write(buf); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return configFile.Close()
|
|
|
|
}
|
|
|
|
|
2020-11-03 07:54:15 -05:00
|
|
|
// Dir returns the directory component of the path
|
|
|
|
func (c *Configuration) Dir() string {
|
|
|
|
return filepath.Dir(c.path)
|
refactored logging in d2loader, d2record, and d2asset (#898)
* refactored logging in d2config, d2record, and d2asset
* asset manager, record manager, and file loader now utilitize d2util.Logger
* added colored logging to d2util.Logger (excluding windows platforms)
* removed mpq file verification from d2config; d2loader handles this
* record loaders now use the record manager's logger for printing info
* added command line argument for setting log level (`--loglevel 4`, `-l4`, or `-l 4`
* added `LogLevel` parameter to config file
* default log level will show errors, warnings, and info log messages
* specifying log level as an argument overrides setting from config file
* fixed log level tests
2020-11-02 21:23:07 -05:00
|
|
|
}
|
|
|
|
|
2020-11-03 07:54:15 -05:00
|
|
|
// Base returns the base component of the path
|
|
|
|
func (c *Configuration) Base() string {
|
|
|
|
return filepath.Base(c.path)
|
|
|
|
}
|
2020-07-08 09:16:16 -04:00
|
|
|
|
2020-11-03 07:54:15 -05:00
|
|
|
// Path returns the config file path
|
|
|
|
func (c *Configuration) Path() string {
|
|
|
|
return c.path
|
2020-07-08 09:16:16 -04:00
|
|
|
}
|
|
|
|
|
2020-11-03 07:54:15 -05:00
|
|
|
// SetPath sets where the config file is saved to (a full path)
|
|
|
|
func (c *Configuration) SetPath(p string) {
|
|
|
|
c.path = p
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|