-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReactorControl.lua
More file actions
237 lines (207 loc) · 5.08 KB
/
Copy pathReactorControl.lua
File metadata and controls
237 lines (207 loc) · 5.08 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
shell.run("Button")
shell.run("EventListener")
os.loadAPI("Button")
os.loadAPI("EventListener")
reactorString = "BigReactors-Reactor_0"
redstoneSide = "back"
reactor = peripheral.wrap(reactorString)
mon = peripheral.find("monitor",
function(name, object)
return object.isColour()
end
)
if not mon then
print("No monitor connected")
print("Requires Advanced Monitor")
shell.exit()
end
rightAlign, _ = mon.getSize()
rightAlign = rightAlign - 22
function drawStaticText()
mon.setCursorPos(1,1)
mon.write("Status:")
mon.setCursorPos(1,3)
mon.write("Fuel:")
mon.setCursorPos(1,4)
mon.write("Fuel Temp:")
mon.setCursorPos(rightAlign,1)
mon.write("Time:")
mon.setCursorPos(rightAlign,2)
mon.write("Energy:")
mon.setCursorPos(rightAlign,3)
mon.write("Waste:")
mon.setCursorPos(rightAlign,4)
mon.write("Case Temp:")
mon.setCursorPos(14,5)
mon.write("Energy:")
end
function drawText()
for i = 1, 4 do
mon.setCursorPos(12,i)
mon.write(" ")
mon.setCursorPos(rightAlign + 12, i)
mon.write(" ")
end
mon.setCursorPos(12, 1)
if reactor.getConnected() then
mon.setTextColour(colours.green)
mon.write("Connected")
mon.setCursorPos(12, 2)
if reactor.getActive() then
mon.setTextColour(colours.green)
mon.write("Online")
else
mon.setTextColour(colours.red)
mon.write("Offline")
end
mon.setTextColour(colours.white)
mon.setCursorPos(12, 3)
mon.write(reactor.getFuelAmount() / 1000 .. "B")
mon.setCursorPos(12, 4)
mon.write(reactor.getFuelTemperature() .. " C")
mon.setCursorPos(rightAlign + 12, 1)
mon.write(os.time())
mon.setCursorPos(rightAlign + 12, 2)
mon.write(reactor.getEnergyStored() .. " RF")
mon.setCursorPos(rightAlign + 12, 3)
mon.write(reactor.getWasteAmount() / 1000 .. "B")
mon.setCursorPos(rightAlign + 12, 4)
mon.write(reactor.getCasingTemperature() .. " C")
mon.setCursorPos(24, 5)
local energy = reactor.getEnergyProducedLastTick()
if energy > 100 then
mon.setTextColour(colours.green)
else
mon.setTextColour(colours.red)
end
mon.write(energy .. " RF")
mon.setTextColour(colours.white)
else
mon.setTextColour(colours.red)
mon.write("Disconected")
end
end
local xmid, ymid = mon.getSize()
xmid = xmid / 2
ymid = ymid / 2 - 2
-- Buttons
reactorControl = {
width = 13,
x = 4,
y = ymid,
height = 3,
monitor = mon,
text = "Reactor",
state = false,
toggle = true,
colourOn = colours.green,
colourOff = colours.red,
onClick = function(s)
reactor.setActive(s)
end
}
aePower = {
width = 13,
x = 4,
y = ymid + 4,
height = 3,
monitor = mon,
text = "AE Power",
state = false,
toggle = true,
onClick = function(s)
if s then
redstone.setBundledOutput("bottom", colours.combine(redstone.getBundledOutput("bottom"), colours.red))
else
redstone.setBundledOutput("bottom", colours.subtract(redstone.getBundledOutput("bottom"), colours.red))
end
end
}
aeCrafting = {
width = 13,
x = 4,
y = ymid + 8,
height = 3,
monitor = mon,
text = "AE Crafting",
state = false,
toggle = true,
onClick = function(s)
if s then
redstone.setBundledOutput("bottom", colours.combine(redstone.getBundledOutput("bottom"), colours.white))
else
redstone.setBundledOutput("bottom", colours.subtract(redstone.getBundledOutput("bottom"), colours.white))
end
end
}
quit = {
x = term.getSize() - 12,
text = "Quit",
colourOn = colors.red,
colourOff = colors.green,
onClick = function()
reactor.setActive(false)
stop = true
mon.clear()
term.clear()
end
}
reboot = {
x = term.getSize() - 12,
y = 2,
text = "Restart",
colourOn = colors.red,
colourOff = colors.green,
onClick = function()
reactor.setActive(false)
stop = true
mon.clear()
term.clear()
shell.run("reboot")
end
}
function main()
mon.clear()
term.clear()
redstone.setBundledOutput("bottom", 0)
reactor.setActive(false)
print("Drawing Static Text")
drawStaticText()
print("Adding Buttons")
Button:new(reactorControl)
Button:new(aePower)
Button:new(aeCrafting)
Button:new(quit)
Button:new(reboot)
Button.drawAll()
print("Adding EventListeners")
EventListener.add("monitor_touch", "ButtonTouch", Button.eventHandler)
EventListener.add("mouse_click", "ButtonClick", Button.eventHandler)
EventListener.add("redstone", "ButtonTouch", function()
reactor.setActive(redstone.getInput(redstoneSide))
reactorControl.state = reactor.getActive()
Button.drawAll()
end
)
EventListener.add("timer", "Automatic Shut Down", function()
if not reactor then
reactor = peripheral.wrap(reactorString)
end
end
)
EventListener.add("timer", "Automatic Shut Down", function()
if reactor then
if reactor.getEnergyStored() > 7500000 then
reactor.setActive(false)
reactorControl.state = false
Button.drawAll()
end
end
end
)
EventListener.updateLoop(1, stop, function()
drawText()
end
)
end
main()