forked from aedan/drmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.lua
171 lines (150 loc) · 3.79 KB
/
install.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
-- drmon installation script
--
--
local libURL = "https://raw.githubusercontent.com/The-Tech-Revolutioner/drmon/master/lib/f.lua"
local reactorURL = "https://raw.githubusercontent.com/The-Tech-Revolutioner/drmon/master/drmon.lua"
local batURL = "https://raw.githubusercontent.com/The-Tech-Revolutioner/drmon/master/bat.lua"
local lib, reactor, bat, libFile, reactorFile, batFile, selected, monType, flowIn, FlowOut, rSide, monitor, first, second
local version = "1.0.0"
fs.makeDir("lib")
lib = http.get(libURL)
libFile = lib.readAll()
local file1 = fs.open("lib/f", "w")
file1.write(libFile)
file1.close()
reactor = http.get(reactorURL)
reactorFile = reactor.readAll()
local file2 = fs.open("reactor", "w")
file2.write(reactorFile)
file2.close()
bat = http.get(batURL)
batFile = bat.readAll()
local file3 = fs.open("bat", "w")
file3.write(batFile)
file3.close()
selected = 1
function save_config()
sw = fs.open("config.txt", "w")
sw.writeLine(version)
sw.writeLine(monType)
sw.writeLine(rSide)
sw.writeLine(flowIn)
sw.writeLine(flowOut)
sw.writeLine(monitor)
sw.writeLine("0")
sw.writeLine("222000")
sw.writeLine("1")
sw.close()
end
function load_config()
sr = fs.open("config.txt", "r")
version = sr.readLine()
monType = sr.readLine()
sr.close()
end
local function bwOc(c,bw)
return term.isColor() and c or bw
end
function detect()
first = ""
second = ""
local p = peripheral.getNames()
if table.getn(p) == 0 then
term.clear()
term.write("No devices detected")
exit()
end
for i = 1, #p do
if string.find(p[i],"monitor") then
monitor = p[i]
end
if string.find(p[i],"flux") then
first = p[i]
end
if p[i] == "back" or p[i] == "left" or p[i] == "right" or p[i] == "up" or p[i] == "down" then
subp = peripheral.getMethods(p[i])
if #subp > 0 then
for a = 1, #subp do
if string.find(subp[a], "Reactor") then
rSide = p[i]
elseif string.find(subp[a], "flux") then
out = p[i]
end
end
end
end
end
end
local function typeMenu()
width,height=term.getSize()
term.setBackgroundColor(colors.black)
term.setTextColor(bwOc(colors.red,colors.white))
term.clear()
local cx,cy=math.floor(width/2),math.floor(height/2)
term.setCursorPos(cx-6,cy-3)
term.write("Initial Setup")
term.setCursorPos(1,cy-1)
term.write("What monitor are you configuring?")
term.setCursorPos(3,cy+1)
if selected==1 then
term.setTextColor(bwOc(colors.blue,colors.black))
term.setBackgroundColor(bwOc(colors.lightGray,colors.white))
else
term.setTextColor(bwOc(colors.lightBlue,colors.white))
term.setBackgroundColor(colors.black)
end
term.write("Reactor")
term.setCursorPos(3,cy+3)
if selected==2 then
term.setTextColor(bwOc(colors.blue,colors.black))
term.setBackgroundColor(bwOc(colors.lightGray,colors.white))
else
term.setTextColor(bwOc(colors.lightBlue,colors.white))
term.setBackgroundColor(colors.black)
end
term.write("Battery")
end
local function runMenu()
typeMenu()
while true do
local event={os.pullEvent()}
if event[1]=="key" then
local key=event[2]
if key==keys.up or key==keys.w then
selected=selected-1
if selected==0 then
selected=2
end
typeMenu()
elseif key==keys.down or key==keys.s then
selected=selected%2+1
typeMenu()
elseif key==keys.enter or key==keys.space then
break
end
end
end
if selected==2 then
monType = "bat"
else
monType = "reactor"
end
if monType == "reactor" then
flowOut = first
flowIn = second
end
end
if fs.exists("config.txt") == false then
detect()
runMenu()
save_config()
else
load_config()
if version ~= "1.0.0" then
version = "1.0.0"
detect()
runMenu()
save_config()
end
end
require(monType)