TangentFox

ksp.lua (basic mod manager)

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