Class: Factorix::InstalledMOD
- Inherits:
-
Data
- Object
- Data
- Factorix::InstalledMOD
- Extended by:
- Enumerable
- Includes:
- Comparable
- Defined in:
- lib/factorix/installed_mod.rb,
lib/factorix/installed_mod.rb
Overview
Represents a MOD installed in the MOD directory or data directory
InstalledMOD represents an actual MOD package found in either:
-
The MOD directory (user-installed MODs as ZIP files or directories)
-
The data directory (base and expansion MODs bundled with the game)
This is distinct from MOD (which is just a name identifier) and MODState (which represents desired state in mod-list.json).
Constant Summary collapse
- ZIP_FORM =
Form constants
:zip- DIRECTORY_FORM =
:directory
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.all(handler: nil) ⇒ Array<InstalledMOD>
Get all installed MODs.
-
.each {|mod| ... } ⇒ Enumerator, Array
Enumerate over all installed MODs.
-
.from_directory(path) ⇒ InstalledMOD
Create InstalledMOD from a directory.
-
.from_zip(path) ⇒ InstalledMOD
Create InstalledMOD from a ZIP file.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare with another InstalledMOD.
-
#base? ⇒ Boolean
Check if this is the base MOD.
-
#expansion? ⇒ Boolean
Check if this is an expansion MOD.
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form
8 9 10 |
# File 'lib/factorix/installed_mod.rb', line 8 def form @form end |
#info ⇒ Object (readonly)
Returns the value of attribute info
8 9 10 |
# File 'lib/factorix/installed_mod.rb', line 8 def info @info end |
#mod ⇒ Object (readonly)
Returns the value of attribute mod
8 9 10 |
# File 'lib/factorix/installed_mod.rb', line 8 def mod @mod end |
#path ⇒ Object (readonly)
Returns the value of attribute path
8 9 10 |
# File 'lib/factorix/installed_mod.rb', line 8 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version
8 9 10 |
# File 'lib/factorix/installed_mod.rb', line 8 def version @version end |
Class Method Details
.all(handler: nil) ⇒ Array<InstalledMOD>
Get all installed MODs
45 46 47 48 49 50 51 |
# File 'lib/factorix/installed_mod.rb', line 45 def self.all(handler: nil) scanner = Scanner.new scanner.subscribe(handler) if handler result = scanner.scan scanner.unsubscribe(handler) if handler result end |
.each {|mod| ... } ⇒ Enumerator, Array
Enumerate over all installed MODs
57 |
# File 'lib/factorix/installed_mod.rb', line 57 def self.each(&) = all.each(&) |
.from_directory(path) ⇒ InstalledMOD
Create InstalledMOD from a directory
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/factorix/installed_mod.rb', line 82 def self.from_directory(path) info_path = path + "info.json" raise FileFormatError, "Missing info.json" unless info_path.file? info = InfoJSON.from_json(info_path.read) dirname = path.basename.to_s expected_unversioned = info.name expected_versioned = "#{info.name}_#{info.version}" unless dirname == expected_unversioned || dirname == expected_versioned raise FileFormatError, "Directory name mismatch: expected #{expected_unversioned} or #{expected_versioned}, got #{dirname}" end new(mod: MOD[name: info.name], version: info.version, form: DIRECTORY_FORM, path:, info:) end |
.from_zip(path) ⇒ InstalledMOD
Create InstalledMOD from a ZIP file
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/factorix/installed_mod.rb', line 64 def self.from_zip(path) info = InfoJSON.from_zip(path) expected_filename = "#{info.name}_#{info.version}.zip" actual_filename = path.basename.to_s unless actual_filename == expected_filename raise FileFormatError, "Filename mismatch: expected #{expected_filename}, got #{actual_filename}" end new(mod: MOD[name: info.name], version: info.version, form: ZIP_FORM, path:, info:) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compare with another InstalledMOD
Comparison is by version (ascending), then by form (directory > ZIP)
213 214 215 216 217 218 219 |
# File 'lib/factorix/installed_mod.rb', line 213 def <=>(other) return nil unless other.is_a?(InstalledMOD) return nil unless mod == other.mod # Compare by version (ascending), then by form priority (directory > ZIP) (version <=> other.version).nonzero? || form_priority(form) <=> form_priority(other.form) end |
#base? ⇒ Boolean
Check if this is the base MOD
224 |
# File 'lib/factorix/installed_mod.rb', line 224 def base? = mod.base? |
#expansion? ⇒ Boolean
Check if this is an expansion MOD
229 |
# File 'lib/factorix/installed_mod.rb', line 229 def expansion? = mod.expansion? |