Advertisement
Xelostar

WatermelonGame3D-installer

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