Advertisement
TangentFox

ksp.lua (basic mod manager)

Apr 20th, 2022
1,592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. #!/usr/bin/env luajit
  2.  
  3. -- NOTE it is assumed all mods use ModuleManager and that it remains in place
  4.  
  5. local installed_location = "GameData"
  6. local disabled_location = "GameData.disabled"
  7.  
  8. local mods = {
  9.   ["stock"] = { "Squad", },
  10.   ["DLC"] = { "SquadExpansion", },
  11.  
  12.   ["Airplane Plus"] = { "AirplanePlus", "Firespitter", },
  13.   ["Atmosphere Autopilot"] = { "AtmosphereAutopilot", "KSPUpgradeScriptFix.dll", },
  14.   ["Environmental Visual Enhancements"] = { "BoulderCo", "EnvironmentalVisualEnhancements", },
  15.   ["Feline Utility Rover"] = { "KerbetrotterLtd", "KSPModFileLocalizer.dll", },
  16.   ["Kerbal Construction Time"] = {
  17.     "000_ClickThroughBlocker", "001_ToolbarControl", "KerbalConstructionTime",
  18.     "MagiCore", "SpaceTuxLibrary",
  19.   },
  20.   ["Kerbal Insurance Agency"] = { "Guard13007", "SlowCPU", },
  21.   ["KerbinSide"] = {
  22.     "CustomPreLaunchChecks", "KerbalKonstructs", "KerbinSideRemastered",
  23.   },
  24.   ["OhScrap!"] = { "OhScrap", "ScrapYard" },
  25.   ["Scatterer"] = { "Scatterer", "ScattererAtmosphereCache", }, -- 2nd item is generated on first run
  26.   ["Snacks"] = { "WildBlueIndustries" },
  27.   ["Stockalike Station Parts Expansion Redux"] = {
  28.     "B9PartSwitch", "NearFutureProps", "StationPartsExpansionRedux",
  29.     "StationPartsExpansionReduxIVAs",
  30.   },
  31.   ["Waterfall FX"] = { "StockWaterfallEffects", "Waterfall", },
  32. }
  33. local lists = {
  34.   ["default"] = {
  35.     -- "stock", "DLC",
  36.     "Atmosphere Autopilot", "Environmental Visual Enhancements",
  37.     "KerbalKrashSystem", "Scatterer", "Trajectories", "Waterfall FX",
  38.   },
  39.   ["daily career"] = {
  40.     -- "stock", "DLC",
  41.     "Atmosphere Autopilot", "Environmental Visual Enhancements",
  42.     "KerbalKrashSystem", "Scatterer", "Trajectories", "Waterfall FX",
  43.  
  44.     "Airplane Plus", "CommunityTechTree", "Grounded",
  45.     "Kerbal Construction Time", "Kerbal Insurance Agency", "KSPSecondaryMotion",
  46.     "OhScrap!", "ScienceAlert", "Snacks",
  47.  
  48.     -- "DMagicOrbitalScience", "ESLDBeacons", "Feline Utility Rover", "KerbinSide", "kOS",
  49.   },
  50. }
  51.  
  52. local selected_list = table.concat(arg, " ")
  53. local list = lists[selected_list]
  54. assert(list, "'" .. selected_list .. "' is not a valid list.")
  55.  
  56. -- convert list selection into a hashtable of names for all needed files
  57. --  (this handles duplicated names from dependencies)
  58. local file_names_hashtable = {}
  59. for _, mod_name in ipairs(list) do
  60.   local mod_list = mods[mod_name]
  61.   if mod_list then
  62.     for _, mod_name in ipairs(mod_list) do
  63.       file_names_hashtable[mod_name] = true
  64.     end
  65.   else
  66.     file_names_hashtable[mod_name] = true
  67.   end
  68. end
  69.  
  70. local file_names_list = {}
  71. for mod_name in pairs(file_names_hashtable) do
  72.   table.insert(file_names_list, mod_name)
  73. end
  74.  
  75. local function move_list(list, a, b)
  76.   local function os_move(a, b)
  77.     os.execute("mv \"" .. a .. "\" \"" .. b .. "\"")
  78.   end
  79.  
  80.   for _, mod_name in ipairs(list) do
  81.     os_move(a .. "/" .. mod_name, b .. "/")
  82.   end
  83. end
  84.  
  85. move_list(file_names_list, disabled_location, installed_location)
  86. os.execute("./KSP.app/Contents/MacOS/KSP")
  87. move_list(file_names_list, installed_location, disabled_location)
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement