SHOW:
|
|
- or go back to the newest paste.
| 1 | local monitor = peripheral.wrap("monitor_138")
| |
| 2 | local core = peripheral.wrap("draconic_rf_storage_13")
| |
| 3 | local gateBlock1 = peripheral.wrap("flux_gate_65")
| |
| 4 | local gateBlock2 = peripheral.wrap("flux_gate_63")
| |
| 5 | local gateBlock3 = peripheral.wrap("flux_gate_61")
| |
| 6 | local gateBlock4 = peripheral.wrap("flux_gate_64")
| |
| 7 | local gateBlock5 = peripheral.wrap("flux_gate_62")
| |
| 8 | local gateBlock6 = peripheral.wrap("flux_gate_60")
| |
| 9 | local gateExtra = peripheral.wrap("flux_gate_67")
| |
| 10 | local gateRecl = peripheral.wrap("flux_gate_68")
| |
| 11 | local gateRepl = peripheral.wrap("flux_gate_69")
| |
| 12 | ||
| 13 | local mon, monX, monY | |
| 14 | monX, monY = monitor.getSize() | |
| 15 | mon = {}
| |
| 16 | mon.monitor,mon.X, mon.Y = monitor, monX, monY | |
| 17 | ||
| 18 | function clear(mon) | |
| 19 | term.clear() | |
| 20 | term.setCursorPos(1,1) | |
| 21 | mon.monitor.setBackgroundColor(colors.black) | |
| 22 | mon.monitor.clear() | |
| 23 | mon.monitor.setCursorPos(1,1) | |
| 24 | end | |
| 25 | ||
| 26 | function draw_text(mon, x, y, text, text_color, bg_color) | |
| 27 | mon.monitor.setBackgroundColor(bg_color) | |
| 28 | mon.monitor.setTextColor(text_color) | |
| 29 | mon.monitor.setCursorPos(x,y) | |
| 30 | mon.monitor.write(text) | |
| 31 | end | |
| 32 | ||
| 33 | function draw_text_right(mon, offset, y, text, text_color, bg_color) | |
| 34 | mon.monitor.setBackgroundColor(bg_color) | |
| 35 | mon.monitor.setTextColor(text_color) | |
| 36 | mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y) | |
| 37 | mon.monitor.write(text) | |
| 38 | end | |
| 39 | ||
| 40 | function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color) | |
| 41 | draw_text(mon, x, y, text1, text1_color, bg_color) | |
| 42 | draw_text_right(mon, offset, y, text2, text2_color, bg_color) | |
| 43 | end | |
| 44 | ||
| 45 | function draw_line(mon, x, y, length, color) | |
| 46 | if length < 0 then | |
| 47 | length = 0 | |
| 48 | end | |
| 49 | mon.monitor.setBackgroundColor(color) | |
| 50 | mon.monitor.setCursorPos(x,y) | |
| 51 | mon.monitor.write(string.rep(" ", length))
| |
| 52 | end | |
| 53 | ||
| 54 | function progress_bar(mon, x, y, length, minVal, maxVal, bar_color, bg_color) | |
| 55 | draw_line(mon, x, y, length, bg_color) | |
| 56 | local barSize = math.floor((minVal/maxVal) * length) | |
| 57 | draw_line(mon, x, y, barSize, bar_color) | |
| 58 | end | |
| 59 | ||
| 60 | function format_int(number) | |
| 61 | if number == nil then number = 0 end | |
| 62 | local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
| |
| 63 | int = int:reverse():gsub("(%d%d%d)", "%1,")
| |
| 64 | return minus .. int:reverse():gsub("^,", "") .. fraction
| |
| 65 | end | |
| 66 | ||
| 67 | local blockTweak = 1 | |
| 68 | ||
| 69 | function save_config() | |
| 70 | sw = fs.open("config.txt", "w")
| |
| 71 | sw.writeLine(blockTweak) | |
| 72 | sw.close() | |
| 73 | end | |
| 74 | ||
| 75 | function load_config() | |
| 76 | sr = fs.open("config.txt", "r")
| |
| 77 | blockTweak = tonumber(sr.readLine()) | |
| 78 | sr.close() | |
| 79 | end | |
| 80 | ||
| 81 | if fs.exists("config.txt") == false then
| |
| 82 | save_config() | |
| 83 | else | |
| 84 | load_config() | |
| 85 | end | |
| 86 | ||
| 87 | ||
| 88 | ||
| 89 | local eFlowOption = 0 | |
| 90 | ||
| 91 | function buttons() | |
| 92 | while true do | |
| 93 | - | draw_text_lr(mon, 2, 2, 0, "Main Energy Core", "Tier 7", colors.orange, colors.orange, colors.black) |
| 93 | + | event, side, xPos, yPos = os.pullEvent("monitor_touch")
|
| 94 | if yPos == 18 then | |
| 95 | local cFlow = gateExtra.getSignalLowFlow() | |
| 96 | if xPos >= 2 and xPos <= 4 then cFlow = cFlow-10000 | |
| 97 | elseif xPos >= 6 and xPos <= 8 then cFlow = cFlow-100000 | |
| 98 | elseif xPos >= 10 and xPos <= 12 then cFlow = cFlow-1000000 | |
| 99 | elseif xPos >= 18 and xPos <= 20 then cFlow = cFlow+1000000 | |
| 100 | elseif xPos >= 22 and xPos <= 24 then cFlow = cFlow+100000 | |
| 101 | elseif xPos >= 26 and xPos <= 28 then cFlow = cFlow+10000 | |
| 102 | end | |
| 103 | gateExtra.setSignalLowFlow(cFlow) | |
| 104 | end | |
| 105 | ||
| 106 | if yPos == 6 and xPos == 28 then | |
| 107 | if eFlowOption == 1 then | |
| 108 | eFlowOption = 0 | |
| 109 | else | |
| 110 | eFlowOption = 1 | |
| 111 | end | |
| 112 | end | |
| 113 | ||
| 114 | if yPos == 9 and (xPos == 27 or xPos == 28) then | |
| 115 | if blockTweak == 1 then | |
| 116 | blockTweak = 0 | |
| 117 | else | |
| 118 | blockTweak = 1 | |
| 119 | end | |
| 120 | - | draw_text_lr(mon, 2, 7, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.white, energyUpDown, colors.black) |
| 120 | + | end |
| 121 | ||
| 122 | - | draw_text_lr(mon, 2, 7, 0, "Energy flow", format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.white, energyUpDown, colors.black) |
| 122 | + | if blockTweak == 0 then |
| 123 | if (xPos >= 7 and xPos <= 9) and yPos == 10 then | |
| 124 | if gateBlock1.getSignalLowFlow() > 0 then | |
| 125 | gateBlock1.setSignalLowFlow(0) | |
| 126 | - | draw_text_lr(mon, 2, 7, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.white, energyUpDown, colors.black) |
| 126 | + | else |
| 127 | gateBlock1.setSignalLowFlow(6000000) | |
| 128 | - | draw_text_lr(mon, 2, 7, 0, "Energy flow", format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.white, energyUpDown, colors.black) |
| 128 | + | end |
| 129 | end | |
| 130 | if (xPos >= 7 and xPos <= 9) and yPos == 12 then | |
| 131 | if gateBlock2.getSignalLowFlow() > 0 then | |
| 132 | - | draw_text_lr(mon, 2, 7, 0, "Energy flow", "+" .. format_int(eFlow) .. " rf/t", colors.white, energyUpDown, colors.black) |
| 132 | + | gateBlock2.setSignalLowFlow(0) |
| 133 | else | |
| 134 | - | draw_text_lr(mon, 2, 7, 0, "Energy flow", format_int(eFlow) .. " rf/t", colors.white, energyUpDown, colors.black) |
| 134 | + | gateBlock2.setSignalLowFlow(6000000) |
| 135 | end | |
| 136 | - | end |
| 136 | + | |
| 137 | if (xPos >= 7 and xPos <= 9) and yPos == 14 then | |
| 138 | if gateBlock3.getSignalLowFlow() > 0 then | |
| 139 | gateBlock3.setSignalLowFlow(0) | |
| 140 | else | |
| 141 | gateBlock3.setSignalLowFlow(6000000) | |
| 142 | - | parallel.waitForAny(update) |
| 142 | + | end |
| 143 | end | |
| 144 | if (xPos >= 16 and xPos <= 18) and yPos == 10 then | |
| 145 | if gateBlock4.getSignalLowFlow() > 0 then | |
| 146 | gateBlock4.setSignalLowFlow(0) | |
| 147 | else | |
| 148 | gateBlock4.setSignalLowFlow(6000000) | |
| 149 | end | |
| 150 | end | |
| 151 | if (xPos >= 16 and xPos <= 18) and yPos == 12 then | |
| 152 | if gateBlock5.getSignalLowFlow() > 0 then | |
| 153 | gateBlock5.setSignalLowFlow(0) | |
| 154 | else | |
| 155 | gateBlock5.setSignalLowFlow(6000000) | |
| 156 | end | |
| 157 | end | |
| 158 | if (xPos >= 16 and xPos <= 18) and yPos == 14 then | |
| 159 | if gateBlock6.getSignalLowFlow() > 0 then | |
| 160 | gateBlock6.setSignalLowFlow(0) | |
| 161 | else | |
| 162 | gateBlock6.setSignalLowFlow(6000000) | |
| 163 | end | |
| 164 | end | |
| 165 | if (xPos >= 25 and xPos <= 27) and yPos == 10 then | |
| 166 | if gateRecl.getSignalLowFlow() > 0 then | |
| 167 | gateRecl.setSignalLowFlow(0) | |
| 168 | else | |
| 169 | gateRecl.setSignalLowFlow(6000000) | |
| 170 | end | |
| 171 | end | |
| 172 | if (xPos >= 25 and xPos <= 27) and yPos == 12 then | |
| 173 | if gateRepl.getSignalLowFlow() > 0 then | |
| 174 | gateRepl.setSignalLowFlow(0) | |
| 175 | else | |
| 176 | gateRepl.setSignalLowFlow(6000000) | |
| 177 | end | |
| 178 | end | |
| 179 | end | |
| 180 | end | |
| 181 | end | |
| 182 | ||
| 183 | function drawButtons(y) | |
| 184 | draw_text(mon, 2, y, " <", colors.white, colors.gray) | |
| 185 | draw_text(mon, 6, y, " <<", colors.white, colors.gray) | |
| 186 | draw_text(mon, 10, y, "<<<", colors.white, colors.gray) | |
| 187 | draw_text(mon, 18, y, ">>>", colors.white, colors.gray) | |
| 188 | draw_text(mon, 22, y, ">> ", colors.white, colors.gray) | |
| 189 | draw_text(mon, 26, y, "> ", colors.white, colors.gray) | |
| 190 | end | |
| 191 | ||
| 192 | local eMax | |
| 193 | local eNow | |
| 194 | local ePercent | |
| 195 | local eLast = 0 | |
| 196 | local eFlow | |
| 197 | ||
| 198 | function update() | |
| 199 | while true do | |
| 200 | clear(mon) | |
| 201 | ||
| 202 | eMax = core.getMaxEnergyStored() | |
| 203 | eNow = core.getEnergyStored() | |
| 204 | ePercent = (math.floor(eNow/eMax*10000))/100 | |
| 205 | eFlow = math.floor((eNow-eLast)/2) | |
| 206 | eLast = eNow | |
| 207 | ||
| 208 | -- terminal display | |
| 209 | print(" Capacity: " .. eMax .. " rf")
| |
| 210 | print(" Energy: " .. eNow .. " rf ... " .. ePercent .. " %")
| |
| 211 | print() | |
| 212 | if (eFlow > 0) then | |
| 213 | print("Avg. flow: +" .. eFlow .. " rf/t")
| |
| 214 | else | |
| 215 | print("Avg. flow: " .. eFlow .. " rf/t")
| |
| 216 | end | |
| 217 | print() | |
| 218 | ||
| 219 | -- monitor display | |
| 220 | draw_text_lr(mon, 2, 2, 0, "Main Energy Core", "Tier 7", colors.lightBlue, colors.blue, colors.black) | |
| 221 | ||
| 222 | local energyColor | |
| 223 | if ePercent >= 75 then energyColor = colors.orange end | |
| 224 | if ePercent < 75 and ePercent >= 50 then energyColor = colors.red end | |
| 225 | if ePercent < 50 and ePercent >= 25 then energyColor = colors.purple end | |
| 226 | if ePercent < 25 then energyColor = colors.cyan end | |
| 227 | ||
| 228 | if eNow >= 1000000000000 then | |
| 229 | draw_text_lr(mon, 2, 4, 0, format_int((math.floor(eNow/1000000000))/1000) .. " T rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 230 | elseif eNow < 1000000000000 and eNow >= 1000000000 then | |
| 231 | draw_text_lr(mon, 2, 4, 0, format_int((math.floor(eNow/1000000))/1000) .. " B rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 232 | elseif eNow < 1000000000 and eNow >= 1000000 then | |
| 233 | draw_text_lr(mon, 2, 4, 0, format_int((math.floor(eNow/1000))/1000) .. " M rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 234 | else | |
| 235 | draw_text_lr(mon, 2, 4, 0, format_int(eNow) .. " rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 236 | end | |
| 237 | ||
| 238 | progress_bar(mon, 2, 5, mon.X-2, ePercent, 100, energyColor, colors.gray) | |
| 239 | ||
| 240 | draw_text(mon, 28, 6, "*", colors.gray, colors.black) | |
| 241 | if eFlowOption == 1 then | |
| 242 | draw_text_right(mon, 0, 6, format_int(eFlow) .. " *", colors.gray, colors.black) | |
| 243 | end | |
| 244 | ||
| 245 | local energyUpDown | |
| 246 | if eFlow > 0 then energyUpDown = colors.lime end | |
| 247 | if eFlow == 0 then energyUpDown = colors.gray end | |
| 248 | if eFlow < 0 then energyUpDown = colors.red end | |
| 249 | ||
| 250 | if eFlow >= math.abs(1000000000) then | |
| 251 | if eFlow > 0 then | |
| 252 | draw_text_lr(mon, 2, 7, 0, "Energy Flow", "+" .. format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.white, energyUpDown, colors.black) | |
| 253 | else | |
| 254 | draw_text_lr(mon, 2, 7, 0, "Energy Flow", format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.white, energyUpDown, colors.black) | |
| 255 | end | |
| 256 | elseif eFlow < math.abs(1000000000) and eFlow >= math.abs(1000000) then | |
| 257 | if eFlow > 0 then | |
| 258 | draw_text_lr(mon, 2, 7, 0, "Energy Flow", "+" .. format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.white, energyUpDown, colors.black) | |
| 259 | else | |
| 260 | draw_text_lr(mon, 2, 7, 0, "Energy Flow", format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.white, energyUpDown, colors.black) | |
| 261 | end | |
| 262 | else | |
| 263 | if eFlow > 0 then | |
| 264 | draw_text_lr(mon, 2, 7, 0, "Energy Flow", "+" .. format_int(eFlow) .. " rf/t", colors.white, energyUpDown, colors.black) | |
| 265 | else | |
| 266 | draw_text_lr(mon, 2, 7, 0, "Energy Flow", format_int(eFlow) .. " rf/t", colors.white, energyUpDown, colors.black) | |
| 267 | end | |
| 268 | end | |
| 269 | ||
| 270 | draw_text(mon, 2, 9, "UU Blocks Power control", colors.purple, colors.black) | |
| 271 | ||
| 272 | draw_text(mon, 3, 10, "UU1 ", colors.white, colors.gray) | |
| 273 | draw_text(mon, 3, 12, "UU2 ", colors.white, colors.gray) | |
| 274 | draw_text(mon, 3, 14, "UU3 ", colors.white, colors.gray) | |
| 275 | draw_text(mon, 12, 10, "UU4 ", colors.white, colors.gray) | |
| 276 | draw_text(mon, 12, 12, "UU5 ", colors.white, colors.gray) | |
| 277 | draw_text(mon, 12, 14, "UU6 ", colors.white, colors.gray) | |
| 278 | draw_text(mon, 21, 10, "RCC ", colors.white, colors.gray) | |
| 279 | draw_text(mon, 21, 12, "RPL ", colors.white, colors.gray) | |
| 280 | ||
| 281 | if blockTweak == 1 then | |
| 282 | draw_text_right(mon, 0, 9, "AU", colors.white, colors.gray) | |
| 283 | if ePercent > 45 then gateRepl.setSignalLowFlow(6000000) end | |
| 284 | if ePercent > 50 then gateRecl.setSignalLowFlow(6000000) end | |
| 285 | if ePercent > 55 then gateBlock1.setSignalLowFlow(6000000) end | |
| 286 | if ePercent > 60 then gateBlock2.setSignalLowFlow(6000000) end | |
| 287 | if ePercent > 65 then gateBlock3.setSignalLowFlow(6000000) end | |
| 288 | if ePercent > 70 then gateBlock4.setSignalLowFlow(6000000) end | |
| 289 | if ePercent > 75 then gateBlock5.setSignalLowFlow(6000000) end | |
| 290 | if ePercent > 80 then gateBlock6.setSignalLowFlow(6000000) end | |
| 291 | ||
| 292 | if ePercent < 40 then gateRepl.setSignalLowFlow(0) end | |
| 293 | if ePercent < 45 then gateRecl.setSignalLowFlow(0) end | |
| 294 | if ePercent < 50 then gateBlock1.setSignalLowFlow(0) end | |
| 295 | if ePercent < 55 then gateBlock2.setSignalLowFlow(0) end | |
| 296 | if ePercent < 60 then gateBlock3.setSignalLowFlow(0) end | |
| 297 | if ePercent < 65 then gateBlock4.setSignalLowFlow(0) end | |
| 298 | if ePercent < 70 then gateBlock5.setSignalLowFlow(0) end | |
| 299 | if ePercent < 75 then gateBlock6.setSignalLowFlow(0) end | |
| 300 | ||
| 301 | if gateRepl.getSignalLowFlow() > 0 then | |
| 302 | draw_text(mon, 25, 12, " ON", colors.lime, colors.gray) | |
| 303 | else | |
| 304 | draw_text(mon, 25, 12, "OFF", colors.red, colors.gray) | |
| 305 | end | |
| 306 | if gateRecl.getSignalLowFlow() > 0 then | |
| 307 | draw_text(mon, 25, 10, " ON", colors.lime, colors.gray) | |
| 308 | else | |
| 309 | draw_text(mon, 25, 10, "OFF", colors.red, colors.gray) | |
| 310 | end | |
| 311 | if gateBlock1.getSignalLowFlow() > 0 then | |
| 312 | draw_text(mon, 7, 10, " ON", colors.lime, colors.gray) | |
| 313 | else | |
| 314 | draw_text(mon, 7, 10, "OFF", colors.red, colors.gray) | |
| 315 | end | |
| 316 | if gateBlock2.getSignalLowFlow() > 0 then | |
| 317 | draw_text(mon, 7, 12, " ON", colors.lime, colors.gray) | |
| 318 | else | |
| 319 | draw_text(mon, 7, 12, "OFF", colors.red, colors.gray) | |
| 320 | end | |
| 321 | if gateBlock3.getSignalLowFlow() > 0 then | |
| 322 | draw_text(mon, 7, 14, " ON", colors.lime, colors.gray) | |
| 323 | else | |
| 324 | draw_text(mon, 7, 14, "OFF", colors.red, colors.gray) | |
| 325 | end | |
| 326 | if gateBlock4.getSignalLowFlow() > 0 then | |
| 327 | draw_text(mon, 16, 10, " ON", colors.lime, colors.gray) | |
| 328 | else | |
| 329 | draw_text(mon, 16, 10, "OFF", colors.red, colors.gray) | |
| 330 | end | |
| 331 | if gateBlock5.getSignalLowFlow() > 0 then | |
| 332 | draw_text(mon, 16, 12, " ON", colors.lime, colors.gray) | |
| 333 | else | |
| 334 | draw_text(mon, 16, 12, "OFF", colors.red, colors.gray) | |
| 335 | end | |
| 336 | if gateBlock6.getSignalLowFlow() > 0 then | |
| 337 | draw_text(mon, 16, 14, " ON", colors.lime, colors.gray) | |
| 338 | else | |
| 339 | draw_text(mon, 16, 14, "OFF", colors.red, colors.gray) | |
| 340 | end | |
| 341 | ||
| 342 | else | |
| 343 | draw_text_right(mon, 0, 9, "MA", colors.white, colors.gray) | |
| 344 | if gateRepl.getSignalLowFlow() > 0 then | |
| 345 | draw_text(mon, 25, 12, " ON", colors.white, colors.green) | |
| 346 | else | |
| 347 | draw_text(mon, 25, 12, "OFF", colors.white, colors.red) | |
| 348 | end | |
| 349 | if gateRecl.getSignalLowFlow() > 0 then | |
| 350 | draw_text(mon, 25, 10, " ON", colors.white, colors.green) | |
| 351 | else | |
| 352 | draw_text(mon, 25, 10, "OFF", colors.white, colors.red) | |
| 353 | end | |
| 354 | if gateBlock1.getSignalLowFlow() > 0 then | |
| 355 | draw_text(mon, 7, 10, " ON", colors.white, colors.green) | |
| 356 | else | |
| 357 | draw_text(mon, 7, 10, "OFF", colors.white, colors.red) | |
| 358 | end | |
| 359 | if gateBlock2.getSignalLowFlow() > 0 then | |
| 360 | draw_text(mon, 7, 12, " ON", colors.white, colors.green) | |
| 361 | else | |
| 362 | draw_text(mon, 7, 12, "OFF", colors.white, colors.red) | |
| 363 | end | |
| 364 | if gateBlock3.getSignalLowFlow() > 0 then | |
| 365 | draw_text(mon, 7, 14, " ON", colors.white, colors.green) | |
| 366 | else | |
| 367 | draw_text(mon, 7, 14, "OFF", colors.white, colors.red) | |
| 368 | end | |
| 369 | if gateBlock4.getSignalLowFlow() > 0 then | |
| 370 | draw_text(mon, 16, 10, " ON", colors.white, colors.green) | |
| 371 | else | |
| 372 | draw_text(mon, 16, 10, "OFF", colors.white, colors.red) | |
| 373 | end | |
| 374 | if gateBlock5.getSignalLowFlow() > 0 then | |
| 375 | draw_text(mon, 16, 12, " ON", colors.white, colors.green) | |
| 376 | else | |
| 377 | draw_text(mon, 16, 12, "OFF", colors.white, colors.red) | |
| 378 | end | |
| 379 | if gateBlock6.getSignalLowFlow() > 0 then | |
| 380 | draw_text(mon, 16, 14, " ON", colors.white, colors.green) | |
| 381 | else | |
| 382 | draw_text(mon, 16, 14, "OFF", colors.white, colors.red) | |
| 383 | end | |
| 384 | end | |
| 385 | ||
| 386 | draw_text(mon, 2, 16, "Energy ExtraOUT", colors.yellow, colors.black) | |
| 387 | draw_text_lr(mon, 2, 17, 0, "MaxFlow", format_int(gateExtra.getSignalLowFlow()) .. " rf/t", colors.lightGray, colors.lightGray, colors.black) | |
| 388 | drawButtons(18) | |
| 389 | ||
| 390 | sleep(0.1) | |
| 391 | end | |
| 392 | end | |
| 393 | ||
| 394 | parallel.waitForAny(buttons, update) |