SHOW:
|
|
- or go back to the newest paste.
1 | - | local githubPath = "https://raw.githubusercontent.com/CodingButter/beastcraft/main" |
1 | + | local githubPath = "https://raw.githubusercontent.com/CodingButter/beastcraft/dev" |
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) | |
49 | shell.run("wget", githubPath .. path, path) | |
50 | table.insert(fileNames,1,path) | |
51 | downloaded = downloaded + 1 | |
52 | term.clear() | |
53 | ||
54 | term.setTextColor(colors.white) | |
55 | local installText = "--[[ Installing BeastCraft ]]--" | |
56 | local progressText = downloaded .. " of " .. totalFiles .. "(" .. math.ceil(100 * (downloaded / totalFiles)) .. "%)" | |
57 | term.setCursorPos(WIDTH/2-#installText/2,2) | |
58 | term.write(installText) | |
59 | term.setCursorPos(WIDTH/2-#progressText/2,3) | |
60 | term.write(progressText) | |
61 | for i=1,3 do | |
62 | if fileNames[i] then | |
63 | term.setCursorPos(WIDTH/2-#fileNames[i]/2,i+3) | |
64 | term.setTextColor(fileColors[i]) | |
65 | term.write(fileNames[i]) | |
66 | end | |
67 | end | |
68 | end | |
69 | end | |
70 | term.setCursorPos(WIDTH/2-3,7) | |
71 | end | |
72 | ||
73 | calculateFiles(files) | |
74 | downloadFiles(files, "") | |
75 | shell.run("main") |