Class: Factorix::CLI::Commands::MOD::Install
- Includes:
- DownloadSupport, PortalSupport
- Defined in:
- lib/factorix/cli/commands/mod/install.rb
Overview
Install MODs from Factorio MOD Portal
Instance Method Summary collapse
-
#call(mod_specs:, jobs: "4") ⇒ void
Execute the install command.
-
#mark_disabled_dependencies_for_enable(graph) ⇒ void
Mark disabled dependencies for enabling.
Methods inherited from Base
backup_support!, confirmable!, inherited, require_game_stopped!
Instance Method Details
#call(mod_specs:, jobs: "4") ⇒ void
This method returns an undefined value.
Execute the install command
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/factorix/cli/commands/mod/install.rb', line 43 def call(mod_specs:, jobs: "4", **) jobs = Integer(jobs) # Load current state (without validation to allow fixing issues) mod_list = MODList.load presenter = Progress::Presenter.new(title: "\u{1F50D}\u{FE0E} Scanning MOD(s)", output: err) handler = Progress::ScanHandler.new(presenter) installed_mods = InstalledMOD.all(handler:) graph = Dependency::Graph::Builder.build(installed_mods:, mod_list:) raise DirectoryNotFoundError, "MOD directory does not exist: #{runtime.mod_dir}" unless runtime.mod_dir.exist? # Plan installation (fetch info, extend graph, validate) install_targets = plan_installation(mod_specs, graph, jobs) if install_targets.empty? say "All specified MOD(s) are already installed and enabled", prefix: :info return end # Show plan show_plan(install_targets) return unless confirm?("Do you want to proceed?") # Execute installation execute_installation(install_targets, graph, mod_list, jobs) # Save mod-list.json backup_if_exists(runtime.mod_list_path) mod_list.save install_count = install_targets.count {|t| t[:operation] == :install } enable_count = install_targets.count {|t| t[:operation] == :enable } if install_count > 0 say "Installed #{install_count} MOD(s)", prefix: :success end if enable_count > 0 say "Enabled #{enable_count} disabled dependency MOD(s)", prefix: :success end say "Saved mod-list.json", prefix: :success logger.debug("Saved mod-list.json") end |
#mark_disabled_dependencies_for_enable(graph) ⇒ void
This method returns an undefined value.
Mark disabled dependencies for enabling
Recursively traverses required dependencies and marks disabled MODs for enabling.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/factorix/cli/commands/mod/install.rb', line 92 def mark_disabled_dependencies_for_enable(graph) # Find all MODs that will be installed or enabled target_operations = %i[install enable] mods_to_process = graph.nodes.filter_map {|node| node.mod if target_operations.include?(node.operation) } processed = Set.new until mods_to_process.empty? mod = mods_to_process.shift next if processed.include?(mod) processed.add(mod) graph.edges_from(mod).each do |edge| next unless edge.required? dep_node = graph.node(edge.to_mod) next unless dep_node # Skip if already has an operation or is enabled next if dep_node.operation next if dep_node.enabled? # Mark for enabling if installed but disabled next unless dep_node.installed? graph.set_node_operation(edge.to_mod, :enable) mods_to_process << edge.to_mod end end end |