Class: Factorix::Runtime::Base
- Inherits:
-
Object
- Object
- Factorix::Runtime::Base
- Includes:
- UserConfigurable
- Defined in:
- lib/factorix/runtime/base.rb
Overview
Abstract base class for platform-specific runtime environments
This class defines the interface that all platform-specific runtime implementations must provide. It provides common implementations for derived paths and XDG Base Directory specification support.
Class Method Summary collapse
-
.inherited(subclass) ⇒ void
Hook called when Base is subclassed.
Instance Method Summary collapse
-
#current_log_path ⇒ Pathname
Get the path of the current Factorio log file.
-
#data_dir ⇒ Pathname
Get the Factorio data directory path.
-
#executable_path ⇒ Pathname
Get the Factorio executable path.
-
#factorix_cache_dir ⇒ Pathname
Get the Factorix cache directory.
-
#factorix_config_path ⇒ Pathname
Get the Factorix configuration file path.
-
#factorix_log_path ⇒ Pathname
Get the Factorix log file path.
-
#launch(async: true) ⇒ void
Launch Factorio with the specified options.
-
#lock_path ⇒ Pathname
Get the Factorio lock file path.
-
#mod_dir ⇒ Pathname
Get the MOD directory path of Factorio.
-
#mod_list_path ⇒ Pathname
Get the path of the mod-list.json file.
-
#mod_settings_path ⇒ Pathname
Get the path of the mod-settings.dat file.
-
#player_data_path ⇒ Pathname
Get the path of the player-data.json file.
-
#previous_log_path ⇒ Pathname
Get the path of the previous Factorio log file.
-
#running? ⇒ Boolean
Check if Factorio is currently running.
-
#save_dir ⇒ Pathname
Get the save directory path of Factorio.
-
#script_output_dir ⇒ Pathname
Get the script-output directory path of Factorio.
-
#user_dir ⇒ Pathname
Get the Factorio user directory path.
-
#xdg_cache_home_dir ⇒ Pathname
Get the XDG cache home directory.
-
#xdg_config_home_dir ⇒ Pathname
Get the XDG config home directory.
-
#xdg_data_home_dir ⇒ Pathname
Get the XDG data home directory.
-
#xdg_state_home_dir ⇒ Pathname
Get the XDG state home directory.
Class Method Details
.inherited(subclass) ⇒ void
This method returns an undefined value.
Hook called when Base is subclassed
Automatically prepends UserConfigurable to all subclasses to ensure configuration support is available across all platform implementations.
22 23 24 25 |
# File 'lib/factorix/runtime/base.rb', line 22 def self.inherited(subclass) super subclass.prepend(UserConfigurable) end |
Instance Method Details
#current_log_path ⇒ Pathname
Get the path of the current Factorio log file
This file contains the log output from the current Factorio session.
103 |
# File 'lib/factorix/runtime/base.rb', line 103 def current_log_path = user_dir + "factorio-current.log" |
#data_dir ⇒ Pathname
Get the Factorio data directory path
This directory contains the base game data and built-in expansion MODs. Each MOD (base, space-age, etc.) has its own subdirectory with info.json.
52 |
# File 'lib/factorix/runtime/base.rb', line 52 def data_dir = raise NotImplementedError, "#{self.class}#data_dir is not implemented" |
#executable_path ⇒ Pathname
Get the Factorio executable path
Returns the path to the Factorio executable file. The exact location varies by platform and installation method (Steam, GOG, etc.).
34 |
# File 'lib/factorix/runtime/base.rb', line 34 def executable_path = raise NotImplementedError, "#{self.class}#executable_path is not implemented" |
#factorix_cache_dir ⇒ Pathname
Get the Factorix cache directory
Returns the directory where Factorix stores its cache data.
153 |
# File 'lib/factorix/runtime/base.rb', line 153 def factorix_cache_dir = xdg_cache_home_dir / "factorix" |
#factorix_config_path ⇒ Pathname
Get the Factorix configuration file path
Returns the path to the Factorix configuration file.
160 |
# File 'lib/factorix/runtime/base.rb', line 160 def factorix_config_path = xdg_config_home_dir / "factorix" / "config.rb" |
#factorix_log_path ⇒ Pathname
Get the Factorix log file path
Returns the path to the Factorix log file.
167 |
# File 'lib/factorix/runtime/base.rb', line 167 def factorix_log_path = xdg_state_home_dir / "factorix" / "factorix.log" |
#launch(async: true) ⇒ void
This method returns an undefined value.
Launch Factorio with the specified options
192 193 194 195 196 197 198 |
# File 'lib/factorix/runtime/base.rb', line 192 def launch(*, async: true) if async spawn([executable_path.to_s, "factorio"], *, out: IO::NULL) else system([executable_path.to_s, "factorio"], *) end end |
#lock_path ⇒ Pathname
Get the Factorio lock file path
The lock file is created by Factorio when the game is running and is used to detect if the game is already running.
175 |
# File 'lib/factorix/runtime/base.rb', line 175 def lock_path = user_dir / ".lock" |
#mod_dir ⇒ Pathname
Get the MOD directory path of Factorio
This directory contains all installed MODs and MOD configuration files such as mod-list.json and mod-settings.dat.
60 |
# File 'lib/factorix/runtime/base.rb', line 60 def mod_dir = user_dir + "mods" |
#mod_list_path ⇒ Pathname
Get the path of the mod-list.json file
This file contains the list of installed MODs and their enabled/disabled states.
81 |
# File 'lib/factorix/runtime/base.rb', line 81 def mod_list_path = mod_dir + "mod-list.json" |
#mod_settings_path ⇒ Pathname
Get the path of the mod-settings.dat file
This file contains the MOD settings for startup, runtime-global, and runtime-per-user.
88 |
# File 'lib/factorix/runtime/base.rb', line 88 def mod_settings_path = mod_dir + "mod-settings.dat" |
#player_data_path ⇒ Pathname
Get the path of the player-data.json file
This file contains player-specific data including authentication credentials, preferences, and game statistics.
96 |
# File 'lib/factorix/runtime/base.rb', line 96 def player_data_path = user_dir + "player-data.json" |
#previous_log_path ⇒ Pathname
Get the path of the previous Factorio log file
This file contains the log output from the previous Factorio session.
110 |
# File 'lib/factorix/runtime/base.rb', line 110 def previous_log_path = user_dir + "factorio-previous.log" |
#running? ⇒ Boolean
Check if Factorio is currently running
Because the game becomes daemonized on launch, we cannot use the process ID or process groups to check if the game is running. Instead, we check the existence of the lock file.
184 |
# File 'lib/factorix/runtime/base.rb', line 184 def running? = lock_path.exist? |
#save_dir ⇒ Pathname
Get the save directory path of Factorio
This directory contains all save game files.
67 |
# File 'lib/factorix/runtime/base.rb', line 67 def save_dir = user_dir + "saves" |
#script_output_dir ⇒ Pathname
Get the script-output directory path of Factorio
This directory contains output files generated by Factorio Lua scripts.
74 |
# File 'lib/factorix/runtime/base.rb', line 74 def script_output_dir = user_dir + "script-output" |
#user_dir ⇒ Pathname
Get the Factorio user directory path
This directory contains user-specific Factorio data including mods, saves, configuration files, and player data.
43 |
# File 'lib/factorix/runtime/base.rb', line 43 def user_dir = raise NotImplementedError, "#{self.class}#user_dir is not implemented" |
#xdg_cache_home_dir ⇒ Pathname
Get the XDG cache home directory
Returns the base directory for user-specific cache data according to the XDG Base Directory Specification. On platforms that don’t follow XDG conventions, this returns the platform-appropriate equivalent.
119 |
# File 'lib/factorix/runtime/base.rb', line 119 def xdg_cache_home_dir = Pathname(ENV.fetch("XDG_CACHE_HOME") { default_cache_home_dir }) |
#xdg_config_home_dir ⇒ Pathname
Get the XDG config home directory
Returns the base directory for user-specific configuration files according to the XDG Base Directory Specification. On platforms that don’t follow XDG conventions, this returns the platform-appropriate equivalent.
128 |
# File 'lib/factorix/runtime/base.rb', line 128 def xdg_config_home_dir = Pathname(ENV.fetch("XDG_CONFIG_HOME") { default_config_home_dir }) |
#xdg_data_home_dir ⇒ Pathname
Get the XDG data home directory
Returns the base directory for user-specific data files according to the XDG Base Directory Specification. On platforms that don’t follow XDG conventions, this returns the platform-appropriate equivalent.
137 |
# File 'lib/factorix/runtime/base.rb', line 137 def xdg_data_home_dir = Pathname(ENV.fetch("XDG_DATA_HOME") { default_data_home_dir }) |
#xdg_state_home_dir ⇒ Pathname
Get the XDG state home directory
Returns the base directory for user-specific state files (logs, history, etc.) according to the XDG Base Directory Specification. On platforms that don’t follow XDG conventions, this returns the platform-appropriate equivalent.
146 |
# File 'lib/factorix/runtime/base.rb', line 146 def xdg_state_home_dir = Pathname(ENV.fetch("XDG_STATE_HOME") { default_state_home_dir }) |