Advertisement
Xelostar

Fireworks 3D Installer

Dec 30th, 2023 (edited)
1,482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. local width, height = term.getSize()
  2.  
  3. local totalDownloaded = 0
  4.  
  5. local function update(text)
  6.     term.setBackgroundColor(colors.black)
  7.     term.setTextColor(colors.white)
  8.     term.setCursorPos(1, 9)
  9.     term.clearLine()
  10.     term.setCursorPos(math.floor(width/2 - string.len(text)/2 + 0.5), 9)
  11.     write(text)
  12. end
  13.  
  14. local function bar(ratio)
  15.     term.setBackgroundColor(colors.gray)
  16.     term.setTextColor(colors.lime)
  17.     term.setCursorPos(1, 11)
  18.  
  19.     for i = 1, width do
  20.         if (i/width < ratio) then
  21.             write("]")
  22.         else
  23.             write(" ")
  24.         end
  25.     end
  26. end
  27.  
  28. local function download(path, attempt)
  29.     local rawData = http.get("https://raw.githubusercontent.com/Xella37/CC-Fireworks/master/"..path)
  30.     update("Downloaded " .. path .. "!")
  31.     if not rawData then
  32.         if attempt == 3 then
  33.             error("Failed to download " .. path .. " after 3 attempts!")
  34.         end
  35.         update("Failed to download " .. path .. ". Trying again (attempt " .. (attempt+1) .. "/3)")
  36.         return download(path, attempt+1)
  37.     end
  38.     local data = rawData.readAll()
  39.     local file = fs.open(path, "w")
  40.     file.write(data)
  41.     file.close()
  42. end
  43.  
  44. local function downloadAll(downloads, total)
  45.     local nextFile = table.remove(downloads, 1)
  46.     if nextFile then
  47.         sleep(0.1)
  48.         parallel.waitForAll(function()
  49.             downloadAll(downloads, total)
  50.         end, function()
  51.             download(nextFile, 1)
  52.             totalDownloaded = totalDownloaded + 1
  53.             bar(totalDownloaded / total)
  54.         end)
  55.     end
  56. end
  57.  
  58. function install()
  59.     term.setBackgroundColor(colors.black)
  60.     term.setTextColor(colors.yellow)
  61.     term.clear()
  62.  
  63.     local str = "Fireworks 3D Installer"
  64.     term.setCursorPos(math.floor(width/2 - #str / 2 + 0.5), 2)
  65.     write(str)
  66.  
  67.     update("Installing...")
  68.     bar(0)
  69.  
  70.     local folders = {
  71.         "models",
  72.         "modules"
  73.     }
  74.  
  75.     local downloads = {
  76.         "fireworks.lua",
  77.         "PineWorks.lua",
  78.         "Pine3D.lua",
  79.         "betterblittle.lua",
  80.         "models/bush",
  81.         "models/pinetree",
  82.         "modules/audio.lua",
  83.         "modules/camera.lua",
  84.         "modules/cameraControllers.lua",
  85.         "modules/effects.lua",
  86.         "modules/hudManager.lua",
  87.         "modules/loaders.lua",
  88.         "modules/scene.lua",
  89.         "modules/util.lua",
  90.     }
  91.  
  92.     local total = #folders + #downloads
  93.  
  94.     for i = 1, #folders do
  95.         local folder = folders[i]
  96.         update("Creating " .. folder .. " folder...")
  97.         fs.makeDir(folder)
  98.         bar(i/total)
  99.     end
  100.  
  101.     totalDownloaded = #folders
  102.     downloadAll(downloads, total)
  103.  
  104.     update("Installation finished!")
  105.  
  106.     sleep(1)
  107.  
  108.     term.setBackgroundColor(colors.black)
  109.     term.setTextColor(colors.white)
  110.     term.clear()
  111.  
  112.     term.setCursorPos(1, 1)
  113.     write("Finished installation!\nPress any key to close...")
  114.  
  115.     os.pullEventRaw()
  116.  
  117.     term.clear()
  118.     term.setCursorPos(1, 1)
  119. end
  120.  
  121. install()
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement