SHOW:
|
|
- or go back to the newest paste.
| 1 | local reactor = peripheral.wrap("left")
| |
| 2 | local gate = peripheral.wrap("flux_gate_58")
| |
| 3 | local monitor = peripheral.wrap("monitor_136")
| |
| 4 | local core = peripheral.wrap("draconic_rf_storage_11")
| |
| 5 | ||
| 6 | local mon, monX, monY | |
| 7 | monX, monY = monitor.getSize() | |
| 8 | mon = {}
| |
| 9 | mon.monitor,mon.X, mon.Y = monitor, monX, monY | |
| 10 | ||
| 11 | function clear(mon) | |
| 12 | term.clear() | |
| 13 | term.setCursorPos(1,1) | |
| 14 | mon.monitor.setBackgroundColor(colors.black) | |
| 15 | mon.monitor.clear() | |
| 16 | mon.monitor.setCursorPos(1,1) | |
| 17 | end | |
| 18 | ||
| 19 | function draw_text(mon, x, y, text, text_color, bg_color) | |
| 20 | mon.monitor.setBackgroundColor(bg_color) | |
| 21 | mon.monitor.setTextColor(text_color) | |
| 22 | mon.monitor.setCursorPos(x,y) | |
| 23 | mon.monitor.write(text) | |
| 24 | end | |
| 25 | ||
| 26 | function draw_text_right(mon, offset, y, text, text_color, bg_color) | |
| 27 | mon.monitor.setBackgroundColor(bg_color) | |
| 28 | mon.monitor.setTextColor(text_color) | |
| 29 | mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y) | |
| 30 | mon.monitor.write(text) | |
| 31 | end | |
| 32 | ||
| 33 | function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color) | |
| 34 | draw_text(mon, x, y, text1, text1_color, bg_color) | |
| 35 | draw_text_right(mon, offset, y, text2, text2_color, bg_color) | |
| 36 | end | |
| 37 | ||
| 38 | function draw_line(mon, x, y, length, color) | |
| 39 | if length < 0 then | |
| 40 | length = 0 | |
| 41 | end | |
| 42 | mon.monitor.setBackgroundColor(color) | |
| 43 | mon.monitor.setCursorPos(x,y) | |
| 44 | mon.monitor.write(string.rep(" ", length))
| |
| 45 | end | |
| 46 | ||
| 47 | function progress_bar(mon, x, y, length, minVal, maxVal, bar_color, bg_color) | |
| 48 | draw_line(mon, x, y, length, bg_color) | |
| 49 | local barSize = math.floor((minVal/maxVal) * length) | |
| 50 | draw_line(mon, x, y, barSize, bar_color) | |
| 51 | end | |
| 52 | ||
| 53 | function format_int(number) | |
| 54 | if number == nil then number = 0 end | |
| 55 | local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
| |
| 56 | int = int:reverse():gsub("(%d%d%d)", "%1,")
| |
| 57 | return minus .. int:reverse():gsub("^,", "") .. fraction
| |
| 58 | end | |
| 59 | ||
| 60 | function buttons() | |
| 61 | while true do | |
| 62 | event, side, xPos, yPos = os.pullEvent("monitor_touch")
| |
| 63 | if yPos == 9 then | |
| 64 | local cFlow = gate.getSignalLowFlow() | |
| 65 | - | if xPos >= 2 and xPos <= 4 then cFlow = cFlow-1000 |
| 65 | + | if xPos >= 2 and xPos <= 4 then cFlow = cFlow-10000 |
| 66 | - | elseif xPos >= 6 and xPos <= 8 then cFlow = cFlow-10000 |
| 66 | + | elseif xPos >= 6 and xPos <= 8 then cFlow = cFlow-100000 |
| 67 | - | elseif xPos >= 10 and xPos <= 12 then cFlow = cFlow-100000 |
| 67 | + | elseif xPos >= 10 and xPos <= 12 then cFlow = cFlow-1000000 |
| 68 | - | elseif xPos >= 18 and xPos <= 20 then cFlow = cFlow+100000 |
| 68 | + | elseif xPos >= 18 and xPos <= 20 then cFlow = cFlow+1000000 |
| 69 | - | elseif xPos >= 22 and xPos <= 24 then cFlow = cFlow+10000 |
| 69 | + | elseif xPos >= 22 and xPos <= 24 then cFlow = cFlow+100000 |
| 70 | - | elseif xPos >= 26 and xPos <= 28 then cFlow = cFlow+1000 |
| 70 | + | elseif xPos >= 26 and xPos <= 28 then cFlow = cFlow+10000 |
| 71 | end | |
| 72 | gate.setSignalLowFlow(cFlow) | |
| 73 | end | |
| 74 | end | |
| 75 | end | |
| 76 | ||
| 77 | function drawButtons(y) | |
| 78 | draw_text(mon, 2, y, " <", colors.white, colors.gray) | |
| 79 | draw_text(mon, 6, y, " <<", colors.white, colors.gray) | |
| 80 | draw_text(mon, 10, y, "<<<", colors.white, colors.gray) | |
| 81 | draw_text(mon, 18, y, ">>>", colors.white, colors.gray) | |
| 82 | draw_text(mon, 22, y, ">> ", colors.white, colors.gray) | |
| 83 | draw_text(mon, 26, y, "> ", colors.white, colors.gray) | |
| 84 | end | |
| 85 | ||
| 86 | local ri | |
| 87 | ||
| 88 | local eMax | |
| 89 | local eNow | |
| 90 | local ePercent | |
| 91 | local eLast = 0 | |
| 92 | local eFlow | |
| 93 | ||
| 94 | function update() | |
| 95 | while true do | |
| 96 | clear(mon) | |
| 97 | ||
| 98 | --terminal | |
| 99 | ri = reactor.getReactorInfo() | |
| 100 | for k, v in pairs (ri) do | |
| 101 | print(k.. ": ".. v) | |
| 102 | end | |
| 103 | print("Output Gate: ", gate.getSignalLowFlow())
| |
| 104 | ||
| 105 | --monitor | |
| 106 | local statusColor | |
| 107 | statusColor = colors.red | |
| 108 | if ri.status == "online" or ri.status == "charged" then | |
| 109 | statusColor = colors.green | |
| 110 | elseif ri.status == "offline" then | |
| 111 | statusColor = colors.gray | |
| 112 | elseif ri.status == "charging" then | |
| 113 | statusColor = colors.orange | |
| 114 | end | |
| 115 | ||
| 116 | draw_text_lr(mon, 2, 2, 0, "Reactor I Status", string.upper(ri.status), colors.white, statusColor, colors.black) | |
| 117 | draw_text_lr(mon, 2, 4, 0, "Generation", format_int(ri.generationRate) .. " rf/t", colors.white, colors.lime, colors.black) | |
| 118 | ||
| 119 | local tempColor = colors.red | |
| 120 | if ri.temperature <= 5000 then tempColor = colors.green end | |
| 121 | if ri.temperature >= 5000 and ri.temperature <= 6500 then tempColor = colors.orange end | |
| 122 | ||
| 123 | draw_text_lr(mon, 2, 6, 0, "Temperature", format_int(ri.temperature) .. " C", colors.white, tempColor, colors.black) | |
| 124 | ||
| 125 | draw_text_lr(mon, 2, 8, 0, "Output Gate", format_int(gate.getSignalLowFlow()) .. " rf/t", colors.white, colors.blue, colors.black) | |
| 126 | drawButtons(9) | |
| 127 | ||
| 128 | local fuelPercent, fuelColor | |
| 129 | fuelPercent = 100 - math.ceil(ri.fuelConversion / ri.maxFuelConversion * 10000)*.01 | |
| 130 | fuelColor = colors.red | |
| 131 | if fuelPercent >= 40 then fuelColor = colors.green end | |
| 132 | if fuelPercent < 40 and fuelPercent > 20 then fuelColor = colors.orange end | |
| 133 | ||
| 134 | draw_text_lr(mon, 2, 11, 0, "Fuel", fuelPercent .. " %", colors.white, fuelColor, colors.black) | |
| 135 | progress_bar(mon, 2, 12, mon.X-2, fuelPercent, 100, fuelColor, colors.gray) | |
| 136 | ||
| 137 | eMax = core.getMaxEnergyStored() | |
| 138 | eNow = core.getEnergyStored() | |
| 139 | ePercent = (math.floor(eNow/eMax*10000))/100 | |
| 140 | eFlow = math.floor((eNow-eLast)/2) | |
| 141 | eLast = eNow | |
| 142 | ||
| 143 | local energyColor | |
| 144 | if ePercent >= 75 then energyColor = colors.orange end | |
| 145 | if ePercent < 75 and ePercent >= 50 then energyColor = colors.red end | |
| 146 | if ePercent < 50 and ePercent >= 25 then energyColor = colors.purple end | |
| 147 | if ePercent < 25 then energyColor = colors.cyan end | |
| 148 | ||
| 149 | draw_text_lr(mon, 2, 15, 0, "Supply Core", "Tier 7", colors.white, colors.white, colors.black) | |
| 150 | ||
| 151 | if eNow >= 1000000000000 then | |
| 152 | draw_text_lr(mon, 2, 16, 0, (math.floor(eNow/1000000000))/1000 .. " T rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 153 | elseif eNow < 1000000000000 and eNow >= 1000000000 then | |
| 154 | draw_text_lr(mon, 2, 16, 0, (math.floor(eNow/1000000))/1000 .. " B rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 155 | elseif eNow < 1000000000 and eNow >= 1000000 then | |
| 156 | draw_text_lr(mon, 2, 16, 0, (math.floor(eNow/1000))/1000 .. " M rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 157 | else | |
| 158 | draw_text_lr(mon, 2, 16, 0, format_int(eNow) .. " rf", ePercent .. " %", colors.lightGray, energyColor, colors.black) | |
| 159 | end | |
| 160 | ||
| 161 | progress_bar(mon, 2, 17, mon.X-2, ePercent, 100, energyColor, colors.gray) | |
| 162 | ||
| 163 | local energyUpDown | |
| 164 | if eFlow > 0 then energyUpDown = colors.lime end | |
| 165 | if eFlow == 0 then energyUpDown = colors.gray end | |
| 166 | if eFlow < 0 then energyUpDown = colors.red end | |
| 167 | ||
| 168 | if eFlow >= math.abs(1000000000) then | |
| 169 | if eFlow > 0 then | |
| 170 | draw_text_lr(mon, 2, 18, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.lightGray, energyUpDown, colors.black) | |
| 171 | else | |
| 172 | draw_text_lr(mon, 2, 18, 0, "Energy flow", format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.lightGray, energyUpDown, colors.black) | |
| 173 | end | |
| 174 | elseif eFlow < math.abs(1000000000) and eFlow >= math.abs(1000000) then | |
| 175 | if eFlow > 0 then | |
| 176 | draw_text_lr(mon, 2, 18, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.lightGray, energyUpDown, colors.black) | |
| 177 | else | |
| 178 | draw_text_lr(mon, 2, 18, 0, "Energy flow", format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.lightGray, energyUpDown, colors.black) | |
| 179 | end | |
| 180 | else | |
| 181 | if eFlow > 0 then | |
| 182 | draw_text_lr(mon, 2, 18, 0, "Energy flow", "+" .. format_int(eFlow) .. " rf/t", colors.lightGray, energyUpDown, colors.black) | |
| 183 | else | |
| 184 | draw_text_lr(mon, 2, 18, 0, "Energy flow", format_int(eFlow) .. " rf/t", colors.lightGray, energyUpDown, colors.black) | |
| 185 | end | |
| 186 | end | |
| 187 | ||
| 188 | sleep(0.1) | |
| 189 | end | |
| 190 | end | |
| 191 | ||
| 192 | parallel.waitForAny(buttons, update) |