Class: Factorix::MODSettings
- Inherits:
-
Object
- Object
- Factorix::MODSettings
- Defined in:
- lib/factorix/mod_settings.rb
Overview
Class for handling MOD settings
MODSettings manages the settings from mod-settings.dat file, which contains three sections: startup, runtime-global, and runtime-per-user.
Defined Under Namespace
Classes: Section
Constant Summary collapse
- VALID_SECTIONS =
Valid section names
%w[startup runtime-global runtime-per-user].freeze
Instance Attribute Summary collapse
-
#game_version ⇒ Factorix::GameVersion
readonly
Get the game version.
Class Method Summary collapse
-
.load(path = Container[:runtime].mod_settings_path) ⇒ MODSettings
Load MOD settings from file.
Instance Method Summary collapse
-
#[](name) ⇒ Section
Get a section by name from the MOD settings.
-
#each_section {|section| ... } ⇒ Enumerator
Iterate over all sections in the MOD settings.
-
#initialize(game_version, sections) ⇒ MODSettings
constructor
Create a new MODSettings instance.
-
#save(path = Container[:runtime].mod_settings_path) ⇒ void
Save MOD settings to file.
Constructor Details
#initialize(game_version, sections) ⇒ MODSettings
Create a new MODSettings instance
203 204 205 206 |
# File 'lib/factorix/mod_settings.rb', line 203 def initialize(game_version, sections) @game_version = game_version @sections = sections end |
Instance Attribute Details
#game_version ⇒ Factorix::GameVersion (readonly)
Get the game version
211 212 213 |
# File 'lib/factorix/mod_settings.rb', line 211 def game_version @game_version end |
Class Method Details
.load(path = Container[:runtime].mod_settings_path) ⇒ MODSettings
Load MOD settings from file
111 112 113 114 115 116 |
# File 'lib/factorix/mod_settings.rb', line 111 def self.load(path=Container[:runtime].mod_settings_path) path.open("rb") do |io| game_version, sections = load_settings_from_io(io) new(game_version, sections) end end |
Instance Method Details
#[](name) ⇒ Section
Get a section by name from the MOD settings
219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/factorix/mod_settings.rb', line 219 def [](name) unless VALID_SECTIONS.include?(name) raise MODSettingsError, "Invalid MOD section name: #{name}" end section = @sections[name] unless section raise MODSectionNotFoundError, "MOD section not found: #{name}" end section end |
#each_section {|section| ... } ⇒ Enumerator
Iterate over all sections in the MOD settings
237 238 239 240 241 |
# File 'lib/factorix/mod_settings.rb', line 237 def each_section(&) return @sections.values.to_enum(:each) unless block_given? @sections.each_value(&) end |
#save(path = Container[:runtime].mod_settings_path) ⇒ void
This method returns an undefined value.
Save MOD settings to file
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/factorix/mod_settings.rb', line 247 def save(path=Container[:runtime].mod_settings_path) path.open("wb") do |file| serializer = SerDes::Serializer.new(file) # 1. Write version serializer.write_game_version(@game_version) # 2. Write a boolean value (seems to be always false) serializer.write_bool(false) # 3. Write property tree settings_hash = build_settings_hash serializer.write_property_tree(settings_hash) end end |