Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactor = peripheral.wrap("left")
- local gate = peripheral.wrap("flux_gate_58")
- local monitor = peripheral.wrap("monitor_136")
- local core = peripheral.wrap("draconic_rf_storage_11")
- local mon, monX, monY
- monX, monY = monitor.getSize()
- mon = {}
- mon.monitor,mon.X, mon.Y = monitor, monX, monY
- function clear(mon)
- term.clear()
- term.setCursorPos(1,1)
- mon.monitor.setBackgroundColor(colors.black)
- mon.monitor.clear()
- mon.monitor.setCursorPos(1,1)
- end
- function draw_text(mon, x, y, text, text_color, bg_color)
- mon.monitor.setBackgroundColor(bg_color)
- mon.monitor.setTextColor(text_color)
- mon.monitor.setCursorPos(x,y)
- mon.monitor.write(text)
- end
- function draw_text_right(mon, offset, y, text, text_color, bg_color)
- mon.monitor.setBackgroundColor(bg_color)
- mon.monitor.setTextColor(text_color)
- mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y)
- mon.monitor.write(text)
- end
- function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color)
- draw_text(mon, x, y, text1, text1_color, bg_color)
- draw_text_right(mon, offset, y, text2, text2_color, bg_color)
- end
- function draw_line(mon, x, y, length, color)
- if length < 0 then
- length = 0
- end
- mon.monitor.setBackgroundColor(color)
- mon.monitor.setCursorPos(x,y)
- mon.monitor.write(string.rep(" ", length))
- end
- function progress_bar(mon, x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(mon, x, y, length, bg_color)
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(mon, x, y, barSize, bar_color)
- end
- function format_int(number)
- if number == nil then number = 0 end
- local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
- int = int:reverse():gsub("(%d%d%d)", "%1,")
- return minus .. int:reverse():gsub("^,", "") .. fraction
- end
- function buttons()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if yPos == 9 then
- local cFlow = gate.getSignalLowFlow()
- if xPos >= 2 and xPos <= 4 then cFlow = cFlow-1000
- elseif xPos >= 6 and xPos <= 8 then cFlow = cFlow-10000
- elseif xPos >= 10 and xPos <= 12 then cFlow = cFlow-100000
- elseif xPos >= 18 and xPos <= 20 then cFlow = cFlow+100000
- elseif xPos >= 22 and xPos <= 24 then cFlow = cFlow+10000
- elseif xPos >= 26 and xPos <= 28 then cFlow = cFlow+1000
- end
- gate.setSignalLowFlow(cFlow)
- end
- end
- end
- function drawButtons(y)
- draw_text(mon, 2, y, " <", colors.white, colors.gray)
- draw_text(mon, 6, y, " <<", colors.white, colors.gray)
- draw_text(mon, 10, y, "<<<", colors.white, colors.gray)
- draw_text(mon, 18, y, ">>>", colors.white, colors.gray)
- draw_text(mon, 22, y, ">> ", colors.white, colors.gray)
- draw_text(mon, 26, y, "> ", colors.white, colors.gray)
- end
- local ri
- local eMax
- local eNow
- local ePercent
- local eLast = 0
- local eFlow
- function update()
- while true do
- clear(mon)
- --terminal
- ri = reactor.getReactorInfo()
- for k, v in pairs (ri) do
- print(k.. ": ".. v)
- end
- print("Output Gate: ", gate.getSignalLowFlow())
- --monitor
- local statusColor
- statusColor = colors.red
- if ri.status == "online" or ri.status == "charged" then
- statusColor = colors.green
- elseif ri.status == "offline" then
- statusColor = colors.gray
- elseif ri.status == "charging" then
- statusColor = colors.orange
- end
- draw_text_lr(mon, 2, 2, 0, "Reactor I Status", string.upper(ri.status), colors.white, statusColor, colors.black)
- draw_text_lr(mon, 2, 4, 0, "Generation", format_int(ri.generationRate) .. " rf/t", colors.white, colors.lime, colors.black)
- local tempColor = colors.red
- if ri.temperature <= 5000 then tempColor = colors.green end
- if ri.temperature >= 5000 and ri.temperature <= 6500 then tempColor = colors.orange end
- draw_text_lr(mon, 2, 6, 0, "Temperature", format_int(ri.temperature) .. " C", colors.white, tempColor, colors.black)
- draw_text_lr(mon, 2, 8, 0, "Output Gate", format_int(gate.getSignalLowFlow()) .. " rf/t", colors.white, colors.blue, colors.black)
- drawButtons(9)
- local fuelPercent, fuelColor
- fuelPercent = 100 - math.ceil(ri.fuelConversion / ri.maxFuelConversion * 10000)*.01
- fuelColor = colors.red
- if fuelPercent >= 40 then fuelColor = colors.green end
- if fuelPercent < 40 and fuelPercent > 20 then fuelColor = colors.orange end
- draw_text_lr(mon, 2, 11, 0, "Fuel", fuelPercent .. " %", colors.white, fuelColor, colors.black)
- progress_bar(mon, 2, 12, mon.X-2, fuelPercent, 100, fuelColor, colors.gray)
- eMax = core.getMaxEnergyStored()
- eNow = core.getEnergyStored()
- ePercent = (math.floor(eNow/eMax*10000))/100
- eFlow = math.floor((eNow-eLast)/2)
- eLast = eNow
- local energyColor
- if ePercent >= 75 then energyColor = colors.orange end
- if ePercent < 75 and ePercent >= 50 then energyColor = colors.red end
- if ePercent < 50 and ePercent >= 25 then energyColor = colors.purple end
- if ePercent < 25 then energyColor = colors.cyan end
- draw_text_lr(mon, 2, 15, 0, "Supply Core", "Tier 7", colors.white, colors.white, colors.black)
- if eNow >= 1000000000000 then
- draw_text_lr(mon, 2, 16, 0, (math.floor(eNow/1000000000))/1000 .. " T rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
- elseif eNow < 1000000000000 and eNow >= 1000000000 then
- draw_text_lr(mon, 2, 16, 0, (math.floor(eNow/1000000))/1000 .. " B rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
- elseif eNow < 1000000000 and eNow >= 1000000 then
- draw_text_lr(mon, 2, 16, 0, (math.floor(eNow/1000))/1000 .. " M rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
- else
- draw_text_lr(mon, 2, 16, 0, format_int(eNow) .. " rf", ePercent .. " %", colors.lightGray, energyColor, colors.black)
- end
- progress_bar(mon, 2, 17, mon.X-2, ePercent, 100, energyColor, colors.gray)
- local energyUpDown
- if eFlow > 0 then energyUpDown = colors.lime end
- if eFlow == 0 then energyUpDown = colors.gray end
- if eFlow < 0 then energyUpDown = colors.red end
- if eFlow >= math.abs(1000000000) then
- if eFlow > 0 then
- draw_text_lr(mon, 2, 18, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.lightGray, energyUpDown, colors.black)
- else
- draw_text_lr(mon, 2, 18, 0, "Energy flow", format_int((math.floor(eFlow/1000000))/1000) .. " B rf/t", colors.lightGray, energyUpDown, colors.black)
- end
- elseif eFlow < math.abs(1000000000) and eFlow >= math.abs(1000000) then
- if eFlow > 0 then
- draw_text_lr(mon, 2, 18, 0, "Energy flow", "+" .. format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.lightGray, energyUpDown, colors.black)
- else
- draw_text_lr(mon, 2, 18, 0, "Energy flow", format_int((math.floor(eFlow/1000))/1000) .. " M rf/t", colors.lightGray, energyUpDown, colors.black)
- end
- else
- if eFlow > 0 then
- draw_text_lr(mon, 2, 18, 0, "Energy flow", "+" .. format_int(eFlow) .. " rf/t", colors.lightGray, energyUpDown, colors.black)
- else
- draw_text_lr(mon, 2, 18, 0, "Energy flow", format_int(eFlow) .. " rf/t", colors.lightGray, energyUpDown, colors.black)
- end
- end
- sleep(0.1)
- end
- end
- parallel.waitForAny(buttons, update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement