flooferland

tardistrainer

Aug 21st, 2024 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.42 KB | None | 0 0
  1. -- Launcher and installer for the trainer
  2. -- Has to be regularly updated over on https://pastebin.com/wQq755Nd
  3.  
  4. -- Paths
  5. local paths = {}
  6. paths.folders = {}
  7. paths.folders.install = "/TardisTrainer/"
  8. paths.folders.sources = fs.combine(paths.folders.install)
  9. paths.folders.assets = fs.combine(paths.folders.install, "assets/")
  10. paths.folders.libs = fs.combine(paths.folders.install, "lib/")
  11. paths.entry = fs.combine(paths.folders.sources, "entry.lua")
  12.  
  13. -- Data
  14. local sources = {
  15.     "audio.lua",
  16.     "entry.lua",
  17.     "eventTraining.lua",
  18.     "library.lua",
  19.     "program.lua",
  20.     "theme.lua",
  21.  
  22.     "README.txt"
  23. }
  24. local assets = {
  25.     "Button.dfpwm",
  26.     "FlightLoop.dfpwm",
  27.     "FlightTakeoff.dfpwm",
  28.     "spinnyTardis_0.nimg",
  29.     "spinnyTardis_1.nimg",
  30.     "themeSong.dfpwm",
  31. }
  32. local libraries = {
  33.     {
  34.         name = "json.lua",
  35.         url = "https://gist.githubusercontent.com/tylerneylon/59f4bcf316be525b30ab/raw/7f69cc2cea38bf68298ed3dbfc39d197d53c80de/json.lua"
  36.     },
  37.     {
  38.         name = "nimg.lua",
  39.         url = "https://pastebin.com/raw/2nbDhRXC"
  40.     }
  41. }
  42.  
  43. -- Utility
  44. ---@param path string
  45. ---@param link string
  46. ---@param isBinary boolean|nil
  47. local function install(path, link, isBinary)
  48.     if isBinary == nil then
  49.         isBinary = false
  50.     end
  51.     local req = http.get(link, nil, isBinary)
  52.     local f = fs.open(path, isBinary and "wb" or "w")
  53.     f.write(req.readAll())
  54.     f.close()
  55.     req.close()
  56. end
  57.  
  58. -- Making the folders
  59. for i, path in pairs(paths.folders) do
  60.     if not fs.isDir(path) then
  61.         print("Making '"..path.."' folder..")
  62.         fs.makeDir(path)
  63.     end
  64. end
  65.  
  66. -- Install libraries
  67. if not (fs.exists(".devenv") or fs.exists(fs.combine(paths.folders.install, ".devenv"))) then
  68.     for _, filename in pairs(sources) do
  69.         local git = "https://raw.githubusercontent.com/FlooferLand/cc-tardisflightsim/main/" .. paths.folders.install .. "/"
  70.         install(fs.combine(paths.folders.install, filename), git .. filename)
  71.     end
  72.     for _, filename in pairs(assets) do
  73.         local git = "https://raw.githubusercontent.com/FlooferLand/cc-tardisflightsim/main/" .. paths.folders.install .. "/assets/"
  74.         local isBinary = string.find(filename, ".dfpwm", 1, true) ~= nil
  75.         install(fs.combine(paths.folders.assets, filename), git .. filename, isBinary)
  76.     end
  77. else
  78.     print("Dev env detected")
  79. end
  80. for _, lib in pairs(libraries) do
  81.     install(fs.combine(paths.folders.libs, lib.name), lib.url)
  82. end
  83. sleep(0.1)
  84.  
  85. -- Nimg
  86. print("Initializing NimG")
  87. shell.run(fs.combine(paths.folders.libs, "nimg.lua") .. " update")
  88. print("Moving NimG dependency 'ButtonG'")
  89. local buttonH = {}
  90. buttonH.initial = "/ButtonH"
  91. buttonH.newFolder = fs.combine(paths.folders.install, "ButtonH")
  92. buttonH.new = fs.combine(buttonH.newFolder, "init.lua")
  93. buttonH.new2 = fs.combine(paths.folders.libs, "ButtonH.lua")
  94. if not fs.exists(buttonH.newFolder) then
  95.     fs.makeDir(buttonH.newFolder)
  96. end
  97. if fs.exists(buttonH.initial) and not fs.exists(buttonH.new) then
  98.     fs.move(buttonH.initial, buttonH.new)
  99. end
  100. if fs.exists(buttonH.new) and not fs.exists(buttonH.new2) then
  101.     fs.copy(buttonH.new, buttonH.new2)
  102. end
  103. term.clear()
  104.  
  105. -- Running the system
  106. if not (fs.exists(".owner") or fs.exists(fs.combine(paths.folders.install, ".owner"))) then
  107.     print("Starting TARDIS flight trainer")
  108.     sleep(0.8)
  109. end
  110. print("Executing \"" .. paths.entry .. "\"")
  111. shell.run(paths.entry)
  112.  
  113.  
Advertisement
Add Comment
Please, Sign In to add comment