Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor = peripheral.wrap("back")
- mon = peripheral.wrap("monitor_6")
- currentprod = 0
- mon.setTextScale(0.5)
- monX, monY = mon.getSize()
- function drawText(x, y, text, color, bg_color)
- mon.setCursorPos(x, y)
- mon.setTextColor(color)
- mon.setBackgroundColor(bg_color)
- mon.write(text)
- mon.setBackgroundColor(colors.black)
- end
- function save(datatosave)
- ih = fs.open("productions.txt", "w")
- ih.write(datatosave)
- ih.close()
- end
- function load(source)
- if fs.exists(source) == true then
- ih = fs.open(source, "r")
- data = ih.readAll()
- ih.close()
- return tostring(data)
- end
- end
- highestprod = load("productions.txt")
- function drawLine(x, y, width, height, color)
- for yPos = y, y+height-1 do
- mon.setBackgroundColor(color)
- mon.setCursorPos(x, yPos)
- mon.write(string.rep(" ", width))
- end
- end
- function drawProgress(x, y, width, height, minVal, maxVal, color_bg, color_bar)
- drawLine(x, y, width, height, color_bg)
- local barSize = math.floor((minVal/maxVal)*width)
- drawLine(x, y, barSize, height, color_bar)
- local text = math.floor((minVal/maxVal)*100).."%"
- if barSize > monX/2+#text/2 then
- drawText(monX/2, y+height/2, text, colors.black, color_bar)
- elseif barSize > #text then
- drawText((x+barSize)-string.len(tostring(text)), y+height/2, text, colors.black, color_bar)
- else
- drawText(monX/2, y+height/2, text, colors.black, color_bg)
- end
- --drawText(monX/2, y+height/2, tostring(text.."%"), colors.black, colors.red)
- end
- function clearMon()
- mon.clear()
- mon.setBackgroundColor(colors.black)
- end
- while true do
- sleep(0.2)
- clearMon()
- if reactor.getActive() == true then
- drawText((monX/2-string.len(" Online ")/2), 1, " Online ", colors.black, colors.green)
- end
- if reactor.getActive() == false then
- drawText((monX/2-string.len(" offline ")/2), 1, " Offline ", colors.black, colors.red)
- end
- -- information --
- local energy = reactor.getEnergyStored()
- drawText(1, 2, " Power ", colors.black, colors.gray)
- drawProgress(1, 3,monX, 1, energy, 10000000, colors.red, colors.green)
- -- draw production --
- currentprod = reactor.getEnergyProducedLastTick()
- if currentprod > tonumber(highestprod) then
- highestprod = currentprod
- save(highestprod)
- end
- drawText(1, 4, "Production:", colors.white, colors.black)
- drawText(1, 5, tostring(math.floor(highestprod)).."RF/T", colors.white, colors.black)
- -- logic --
- if reactor.getEnergyStored() == 10000000 then
- reactor.setActive(false)
- end
- if reactor.getEnergyStored() <= 100000 then
- reactor.setActive(true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement