Class: Nauvisian::ModSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/nauvisian/mod_settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:, properties:) ⇒ ModSettings

Returns a new instance of ModSettings.



20
21
22
23
# File 'lib/nauvisian/mod_settings.rb', line 20

def initialize(version:, properties:)
  @version = version
  @properties = properties
end

Class Method Details

.load(from = DEFAULT_MOD_SETTINGS_PATH) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/nauvisian/mod_settings.rb', line 10

def self.load(from=DEFAULT_MOD_SETTINGS_PATH)
  File.open(from, "rb") do |stream|
    des = Nauvisian::Deserializer.new(stream)
    version = des.read_version64
    _unused = des.read_bool
    properties = des.read_property_tree
    new(version:, properties:)
  end
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
# File 'lib/nauvisian/mod_settings.rb', line 34

def [](key)
  @properties[key]
end

#[]=(key, properties) ⇒ Object



38
39
40
# File 'lib/nauvisian/mod_settings.rb', line 38

def []=(key, properties)
  @properties[key] = properties
end

#save(to = DEFAULT_MOD_SETTINGS_PATH) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/nauvisian/mod_settings.rb', line 25

def save(to=DEFAULT_MOD_SETTINGS_PATH)
  File.open(to, "wb") do |stream|
    ser = Nauvisian::Serializer.new(stream)
    ser.write_version64(@version)
    ser.write_bool(false)
    ser.write_property_tree(@properties)
  end
end

#to_json(*args) ⇒ Object



42
43
44
# File 'lib/nauvisian/mod_settings.rb', line 42

def to_json(*args)
  JSON.generate(@properties.merge(version: @version), *args)
end