Config
The Scar::Config
module provides an easy way of storing key-value configuration. It uses Util to save and load the config file.
To use it, you have to declare your configuration structure. To do that, you can use the Scar::Config#define_standards
macro at toplevel. Just provide a hash with names and default values for every config entry. The values have to be of any type in the YAML::Any
union.
Scar::Config.define_standards({
resolution_w: 1600,
resolution_h: 900,
name: "ProPlayer9001",
skills: [false, true, false, false],
})
There are methods for all sorts of config manipulation. You can..
reset(key)
any value by key to its standardload_standards
to reset all values[](key)
to access a value by key (returns the default value if it is not present)[]=(key, value)
to set a valuesave(fname)
to save the current configuration to a file (via Util#write_file)load(fname)
to load a configuration from a file (via Util#read_file)dump
the yaml representation of the current configuration for debugging.
Config.load("config.yml")
Logger.info "the window width is #{Config[:resolution_w]}"
Config[:name] = "ProPlayer1337"
Config.reset(:skills)
Config.save("config.yml")
Last updated
Was this helpful?