Class: Factorix::Runtime::Base

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Linux, MacOS, Windows

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • subclass (Class)

    the subclass being created



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_pathPathname

Get the path of the current Factorio log file

This file contains the log output from the current Factorio session.

Returns:

  • (Pathname)

    the path of the current log file



103
# File 'lib/factorix/runtime/base.rb', line 103

def current_log_path = user_dir + "factorio-current.log"

#data_dirPathname

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.

Returns:

  • (Pathname)

    the Factorio data directory

Raises:

  • (NotImplementedError)

    if not implemented by the platform



52
# File 'lib/factorix/runtime/base.rb', line 52

def data_dir = raise NotImplementedError, "#{self.class}#data_dir is not implemented"

#executable_pathPathname

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.).

Returns:

  • (Pathname)

    the Factorio executable path

Raises:

  • (NotImplementedError)

    if not implemented by the platform



34
# File 'lib/factorix/runtime/base.rb', line 34

def executable_path = raise NotImplementedError, "#{self.class}#executable_path is not implemented"

#factorix_cache_dirPathname

Get the Factorix cache directory

Returns the directory where Factorix stores its cache data.

Returns:

  • (Pathname)

    the Factorix cache directory



153
# File 'lib/factorix/runtime/base.rb', line 153

def factorix_cache_dir = xdg_cache_home_dir / "factorix"

#factorix_config_pathPathname

Get the Factorix configuration file path

Returns the path to the Factorix configuration file.

Returns:

  • (Pathname)

    the Factorix configuration file path



160
# File 'lib/factorix/runtime/base.rb', line 160

def factorix_config_path = xdg_config_home_dir / "factorix" / "config.rb"

#factorix_log_pathPathname

Get the Factorix log file path

Returns the path to the Factorix log file.

Returns:

  • (Pathname)

    the Factorix log file path



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

Parameters:

  • args (Array<String>)

    command-line arguments to pass to Factorio

  • async (Boolean) (defaults to: true)

    whether to launch asynchronously (default: true)

Raises:

  • (RuntimeError)

    if the game is already running



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_pathPathname

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.

Returns:

  • (Pathname)

    the lock file path



175
# File 'lib/factorix/runtime/base.rb', line 175

def lock_path = user_dir / ".lock"

#mod_dirPathname

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.

Returns:

  • (Pathname)

    the MOD directory of Factorio



60
# File 'lib/factorix/runtime/base.rb', line 60

def mod_dir = user_dir + "mods"

#mod_list_pathPathname

Get the path of the mod-list.json file

This file contains the list of installed MODs and their enabled/disabled states.

Returns:

  • (Pathname)

    the path of the mod-list.json file



81
# File 'lib/factorix/runtime/base.rb', line 81

def mod_list_path = mod_dir + "mod-list.json"

#mod_settings_pathPathname

Get the path of the mod-settings.dat file

This file contains the MOD settings for startup, runtime-global, and runtime-per-user.

Returns:

  • (Pathname)

    the path of the mod-settings.dat file



88
# File 'lib/factorix/runtime/base.rb', line 88

def mod_settings_path = mod_dir + "mod-settings.dat"

#player_data_pathPathname

Get the path of the player-data.json file

This file contains player-specific data including authentication credentials, preferences, and game statistics.

Returns:

  • (Pathname)

    the path of the player-data.json file



96
# File 'lib/factorix/runtime/base.rb', line 96

def player_data_path = user_dir + "player-data.json"

#previous_log_pathPathname

Get the path of the previous Factorio log file

This file contains the log output from the previous Factorio session.

Returns:

  • (Pathname)

    the path of the previous log file



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.

Returns:

  • (Boolean)

    true if the game is running, false otherwise



184
# File 'lib/factorix/runtime/base.rb', line 184

def running? = lock_path.exist?

#save_dirPathname

Get the save directory path of Factorio

This directory contains all save game files.

Returns:

  • (Pathname)

    the save directory of Factorio



67
# File 'lib/factorix/runtime/base.rb', line 67

def save_dir = user_dir + "saves"

#script_output_dirPathname

Get the script-output directory path of Factorio

This directory contains output files generated by Factorio Lua scripts.

Returns:

  • (Pathname)

    the script-output directory of Factorio



74
# File 'lib/factorix/runtime/base.rb', line 74

def script_output_dir = user_dir + "script-output"

#user_dirPathname

Get the Factorio user directory path

This directory contains user-specific Factorio data including mods, saves, configuration files, and player data.

Returns:

  • (Pathname)

    the Factorio user directory

Raises:

  • (NotImplementedError)

    if not implemented by the platform



43
# File 'lib/factorix/runtime/base.rb', line 43

def user_dir = raise NotImplementedError, "#{self.class}#user_dir is not implemented"

#xdg_cache_home_dirPathname

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.

Returns:

  • (Pathname)

    the XDG cache home directory



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_dirPathname

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.

Returns:

  • (Pathname)

    the XDG config home directory



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_dirPathname

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.

Returns:

  • (Pathname)

    the XDG data home directory



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_dirPathname

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.

Returns:

  • (Pathname)

    the XDG state home directory



146
# File 'lib/factorix/runtime/base.rb', line 146

def xdg_state_home_dir = Pathname(ENV.fetch("XDG_STATE_HOME") { default_state_home_dir })