View difference between Paste ID: SNhCbPGA and kgTH67Ly
SHOW: | | - or go back to the newest paste.
1
local githubPath = "https://raw.githubusercontent.com/CodingButter/beastcraft/main"
2
local files = {
3
    beastcraft = {
4
        core = {"class.lua", "shape.lua", "utils.lua", "workloop.lua"},
5
        dom = {
6
            elements = {"body.lua", "button.lua", "div.lua", "element.lua", "init.lua", "input.lua", "ul.lua"},
7
            "init.lua",
8
            "selector.lua",
9
            "style.lua"
10
        },
11
        managers = {"listeners.lua", "state.lua"},
12
        ui = {"domrenderer.lua", "init.lua"},
13
        "init.lua"
14
    },
15
    src = {
16
        components = {"button.lua", "menu.lua","input.lua"},
17
        context = {"menucontext.lua"},
18
        "app.lua"
19
    },
20
    "startup.lua",
21
	"main.lua"
22
}
23
local totalFiles = 0
24
local downloaded = 0
25
local function calculateFiles(_tbl)
26
    for k, v in pairs(_tbl) do
27
        if type(v) == "table" then
28
            calculateFiles(v)
29
        else
30
            totalFiles = totalFiles + 1
31
        end
32
    end
33
end
34
35
local fileColors = {
36
	colors.white,
37
	colors.lightGray,
38
	colors.gray
39
}
40
local fileNames = {}
41
local function downloadFiles(_tbl, dir)
42
	local WIDTH,HEIGHT = term.getSize()
43
    for k, v in pairs(_tbl) do
44
        if type(v) == "table" then
45
            downloadFiles(v, dir .. "/" .. k)
46
        else
47
            local path = dir .. "/" .. v
48-
			fs.delete(path)
48+
            shell.run("wget", githubPath .. path, "/disk/"..path)
49-
            shell.run("wget", githubPath .. path, path)
49+
50
            downloaded = downloaded + 1
51
			term.clear()
52
			
53
			term.setTextColor(colors.white)
54
			local installText  = "--[[ Installing BeastCraft ]]--"
55
			local progressText = downloaded .. " of " .. totalFiles .. "(" .. math.ceil(100 * (downloaded / totalFiles)) .. "%)"
56
			term.setCursorPos(WIDTH/2-#installText/2,2)
57
			term.write(installText)
58
			term.setCursorPos(WIDTH/2-#progressText/2,3)
59
            term.write(progressText)
60
			for i=1,3 do
61
				if fileNames[i] then
62
					term.setCursorPos(WIDTH/2-#fileNames[i]/2,i+3)
63
					term.setTextColor(fileColors[i])
64
					term.write(fileNames[i])
65
				end
66
			end
67
        end
68
    end
69
	term.setCursorPos(WIDTH/2-3,7)
70
end
71
72
calculateFiles(files)
73
downloadFiles(files, "")
74
shell.run("/disk/main")