Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("left")
- reactor = peripheral.wrap("BigReactors-Reactor_0")
- capacitor = peripheral.wrap("tile_blockcapacitorbank_name_0")
- local workingMode = 1
- local button = {}
- mon.setBackgroundColor(colors.black)
- mon.setTextScale(0.5)
- mon.clear()
- local reactorInfo = {}
- function getReactorInfo()
- reactorInfo["active"] = reactor.getActive()
- reactorInfo["nRods"] = reactor.getNumberOfControlRods()
- reactorInfo["storedEnergy"] = reactor.getEnergyStored()
- reactorInfo["internalTemp"] = reactor.getFuelTemperature()
- reactorInfo["externalTemp"] = reactor.getCasingTemperature()
- reactorInfo["fuel"] = reactor.getFuelAmount()
- reactorInfo["waste"] = reactor.getWasteAmount()
- reactorInfo["fuelmax"] = reactor.getFuelAmountMax()
- reactorInfo["controlRodLvl"] = reactor.getControlRodLevel(1)
- reactorInfo["producedLastTick"] = reactor.getEnergyProducedLastTick()
- end
- local capacitorInfo = {}
- function getCapacitorInfo()
- capacitorInfo["storedEnergy"] = capacitor.getEnergyStored()
- capacitorInfo["maxStoredEnergy"] = capacitor.getMaxEnergyStored()
- end
- function center(str,width)
- while string.len(str) < width do
- str = " "..str.." "
- end
- return str
- end
- function round(num,dec)
- local mult = 10^(dec or 0)
- return math.floor(num + mult + 0.5)/mult
- end
- function Percentage(toCalculate,maxToCalculate)
- return round((toCalculate*100)/maxToCalculate,2)*100-100
- end
- function autoControl()
- local storedEnergy = capacitorInfo["storedEnergy"]
- local maxStoredEnergy = capacitorInfo["maxStoredEnergy"]
- if Percentage(storedEnergy,maxStoredEnergy) < 25.00 then
- reactor.setActive(true)
- elseif Percentage(storedEnergy,maxStoredEnergy) > 80.00 then
- reactor.setActive(false)
- end
- end
- function drawBoxes(xmin,ymin,width,height)
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(xmin,ymin)
- mon.write(string.rep(" ",width))
- mon.setCursorPos(xmin,ymin+height)
- mon.write(string.rep(" ",width))
- for i = 0, height do
- mon.setCursorPos(xmin,ymin+i)
- mon.write(string.rep(" ",2))
- end
- for i = 0, height do
- mon.setCursorPos(xmin+width,ymin+i)
- mon.write(string.rep(" ",2))
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawRod(x,y,per)
- for i = 0,10 do
- mon.setCursorPos(x,y+i)
- mon.setBackgroundColor(colors.yellow)
- mon.write(string.rep(" ",3))
- end
- if per ~= nil then
- for i = 0, math.floor((per/100)*10) do
- mon.setCursorPos(x+1,y+i)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawGrafic(x,y,per)
- mon.setBackgroundColor(colors.red)
- for i = 0,3 do
- mon.setCursorPos(x,y+i)
- mon.write(string.rep(" ",35))
- end
- mon.setBackgroundColor(colors.green)
- for i = 0, 3 do
- mon.setCursorPos(x,y+i)
- mon.write(string.rep(" ",math.floor((per/100)*35)))
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawButtons()
- for name,data in pairs(button) do
- if data["state"] == 1 then
- mon.setBackgroundColor(data["onColor"])
- else
- mon.setBackgroundColor(data["offColor"])
- end
- mon.setCursorPos(data["xmin"],data["ymin"])
- for i = 0, data["height"] do
- mon.setCursorPos(data["xmin"],data["ymin"]+i)
- mon.write(string.rep(" ",data["width"]))
- end
- mon.setCursorPos(data["xmin"],data["ymin"]+(data["height"]/2))
- mon.write(center(data["display"],data["width"]))
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawText(x,y,str,color)
- color = color or color.white
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(x,y)
- mon.setTextColor(color)
- mon.write(str)
- end
- function drawGui()
- mon.clear()
- --Boxes
- --Reactor Info Box
- drawBoxes(3,2,45,20)
- --Activate Controller
- drawBoxes(3,25,45,12)
- --Control Rod Controller
- drawBoxes(53,2,44,16)
- --Capacitor Info Box
- drawBoxes(53,21,44,16)
- --Text
- --Info Box
- drawText(24-(string.len(" Reactor Info ")/2),2, " Reactor Info ", colors.green)
- --Activate Controller
- drawText(24-(string.len(" Activate ")/2),25, " Activate ", colors.green)
- --Control Rod Controller
- drawText((53+22)-(string.len(" Rods ")/2),2, " Rods ", colors.green)
- --Info Box
- drawText((53+22)-(string.len(" Capacitor Info ")/2),21, " Capacitor Info ", colors.green)
- --Draw all buttons
- drawButtons()
- --Reactor Info Panel
- --Reactor isActive
- if workingMode == 0 then
- drawText(6,5,"Activated: "..tostring(reactorInfo["active"]), colors.red)
- elseif workingMode == 1 then
- drawText(6,5,"Activated: "..tostring(reactorInfo["active"]), colors.green)
- else
- drawText(6,5,"Activated: "..tostring(reactorInfo["active"]), colors.yellow)
- end
- --StoredEnergy
- drawText(6,7, "StoredEnergy: "..tostring(reactorInfo["storedEnergy"]).."RF", colors.green)
- --Core Temp.
- drawText(6,9, "Core Temp: "..tostring(round(reactorInfo["internalTemp"]),2).."c", colors.green)
- --Case Temp.
- drawText(6,11, "Case Temp: "..tostring(round(reactorInfo["externalTemp"]),2).."c", colors.green)
- --Fuel Level
- drawText(6,13, "Fuel: "..tostring(Percentage(reactorInfo["fuel"],reactorInfo["fuelmax"])).."%",colors.green)
- --Control Rods Level
- drawText(6,15, "Control Rod Level: "..tostring(reactorInfo["controlRodLvl"]).."%", colors.green)
- --Produced Last Tick
- drawText(6,17, "Produced Last Tick: "..tostring(round(reactorInfo["producedLastTick"]),2).."RF/t", colors.green)
- --Credits
- drawText(24-(string.len("Coded by ResaloliPT")/2)+2,20,"Coded by ResaloliPT",colors.lime)
- --Rods Panel
- --Labels
- drawText(74-(string.len("Rod Lvl")/2)+2,4, "Rod Lvl", colors.green)
- drawText(63-(string.len("Lower")/2)+2,4, "Lower", colors.green)
- drawText(87-(string.len("Higher")/2)+2,4, "Higher", colors.green)
- --Rod
- drawRod(74,6,reactorInfo["controlRodLvl"])
- --Capacitor Panel
- --StoredEnergy
- drawText(57,26, "StoredEnergyPer: "..tostring(Percentage(capacitorInfo["storedEnergy"],capacitorInfo["maxStoredEnergy"])).."%", colors.green)
- --Grafic
- drawGrafic(57,29,Percentage(capacitorInfo["storedEnergy"],capacitorInfo["maxStoredEnergy"]))
- end
- function addButton(name,func,display,xmin,ymin,width,height,offColor,onColor,state)
- button[name] = {}
- button[name]["name"] = name
- button[name]["func"] = func
- button[name]["display"] = display
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["width"] = width
- button[name]["height"] = height
- button[name]["offColor"] = offColor
- button[name]["onColor"] = onColor
- button[name]["state"] = state
- end
- function activate()
- button["inactive"]["state"] = 0
- if button["active"]["state"] == 1 then
- button["active"]["state"] = 0
- button["auto"]["state"] = 1
- workingMode = 0
- else
- button["active"]["state"] = 1
- button["auto"]["state"] = 0
- workingMode = 2
- end
- end
- function auto()
- button["active"]["state"] = 0
- if button["auto"]["state"] == 1 then
- button["auto"]["state"] = 0
- workingMode = 0
- button["inactive"]["state"] = 1
- else
- button["auto"]["state"] = 1
- button["inactive"]["state"] = 0
- workingMode = 1
- end
- end
- function deactivate()
- button["active"]["state"] = 0
- if button["inactive"]["state"] == 1 then
- button["inactive"]["state"] = 0
- button["auto"]["state"] = 1
- workingMode = 2
- else
- button["inactive"]["state"] = 1
- button["auto"]["state"] = 0
- workingMode = 0
- end
- end
- function lower1()
- if reactorInfo["controlRodLvl"] + 1 <= 100 then
- reactor.setAllControlRodLevels(reactorInfo["controlRodLvl"]+1)
- end
- end
- function lower5()
- if reactorInfo["controlRodLvl"] + 5 <= 100 then
- reactor.setAllControlRodLevels(reactorInfo["controlRodLvl"]+5)
- end
- end
- function lower10()
- if reactorInfo["controlRodLvl"] + 10 <= 100 then
- reactor.setAllControlRodLevels(reactorInfo["controlRodLvl"]+10)
- end
- end
- function higher1()
- if reactorInfo["controlRodLvl"] - 1 >= 0 then
- reactor.setAllControlRodLevels(reactorInfo["controlRodLvl"]-1)
- end
- end
- function higher5()
- if reactorInfo["controlRodLvl"] - 5 >= 0 then
- reactor.setAllControlRodLevels(reactorInfo["controlRodLvl"]-5)
- end
- end
- function higher10()
- if reactorInfo["controlRodLvl"] - 10 >= 0 then
- reactor.setAllControlRodLevels(reactorInfo["controlRodLvl"]-10)
- end
- end
- --Activate Panel
- addButton("active",activate,"Activate",8,30,10,2,colors.red,colors.lime,0)
- addButton("auto",auto,"Automatic",20,30,11,2,colors.red,colors.lime,1)
- addButton("inactive",deactivate,"Deactivate",33,30,12,2,colors.red,colors.lime,0)
- --Rod Panel
- --Lower
- addButton("+1",lower1,"+1",60,6,12,2,colors.red,colors.lime,0)
- addButton("+5",lower5,"+5",60,10,12,2,colors.red,colors.lime,0)
- addButton("+10",lower10,"+10 ",60,14,12,2,colors.red,colors.lime,0)
- --Higher
- addButton("-1",higher1,"-1",79,6,12,2,colors.red,colors.lime,0)
- addButton("-5",higher5,"-5",79,10,12,2,colors.red,colors.lime,0)
- addButton("-10",higher10,"-10 ",79,14,12,2,colors.red,colors.lime,0)
- function checkxy(x, y)
- for id,data in pairs(button) do
- if x < data["xmin"]+data["width"] and x > data["xmin"] then
- if y < data["ymin"]+data["height"] and y > data["ymin"] then
- data["func"]()
- end
- end
- end
- return false
- end
- function getClick()
- event,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x, y)
- end
- function mainLoop()
- sleep(0.2)
- getReactorInfo()
- getCapacitorInfo()
- if workingMode == 1 then
- autoControl()
- elseif workingMode == 2 then
- reactor.setActive(true)
- else
- reactor.setActive(false)
- end
- drawGui()
- end
- while true do
- parallel.waitForAny(mainLoop,getClick)
- end
Add Comment
Please, Sign In to add comment