Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("bg dispLogo")
- sleep(5)
- mon = peripheral.find("monitor")
- reactor = peripheral.find("BigReactors-Reactor")
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- autoEject = false
- autoEjectBounds = {0,0,0,0}
- onOffBounds = {0,0,0,0}
- ejectBounds = {0,0,0,0}
- x,y = -5,-5
- width,height = 1,1
- rodHeight = reactor.getControlRodLevel(1)
- function isInBounds (xPos,yPos,bounds)
- if xPos >= bounds[1] and
- yPos >= bounds[2] and
- xPos <= bounds[3] and
- yPos <= bounds[4] then
- return true
- else
- return false
- end
- end
- function writeCentered (text,line,xMin,xMax)
- if xMin == nil then
- xMin = 0
- end
- if xMax == nil then
- xMax = width
- end
- deltaX = xMax-xMin
- mon.setCursorPos(xMin+math.floor((deltaX/2)-(string.len(text)/2))+1,line)
- mon.write(text)
- end
- function writeRightJustified (text,line,gap)
- if gap == nil then
- gap = 0
- end
- mon.setCursorPos(width-string.len(text)+1-gap,line)
- mon.write(text)
- end
- function fillRect (xMin,yMin,dx,dy)
- line = ""
- for cursor=1,dx do
- line = line.." "
- end
- for cursor=1,dy do
- mon.setCursorPos(xMin,yMin+cursor-1)
- mon.write(line)
- end
- return {xMin,yMin,xMin+dx-1,yMin+dy-1}
- end
- function bgc (color)
- mon.setBackgroundColor(color)
- end
- function tc (color)
- mon.setTextColor(color)
- end
- function writeLeft (text,line,gap)
- if gap == nil then
- gap = 0
- end
- mon.setCursorPos(1+gap,line)
- mon.write(text)
- end
- function getClick ()
- while true do
- event,arg1,xPos,yPos = os.pullEvent()
- if event == "monitor_touch" then
- return xPos,yPos
- elseif event == "key" and arg1 == keys.x then
- return -1,-1
- end
- end
- end
- function drawGui ()
- rodHeight = reactor.getControlRodLevel(1)
- width,height = mon.getSize()
- bgc(colors.black)
- mon.clear()
- bgc(colors.white)
- fillRect(1,1,width-7,2)
- tc(colors.black)
- writeRightJustified(" Fuel ",1)
- writeRightJustified(" Rods ",2)
- writeCentered("Reactor Information",1,1,width-7)
- bgc(colors.pink)
- tc(colors.white)
- writeRightJustified("-1 ",height-1,3)
- bgc(colors.red)
- writeRightJustified("-10",height-1)
- bgc(colors.lime)
- writeRightJustified("+1 ",height,3)
- bgc(colors.green)
- writeRightJustified("+10",height)
- if reactor.getFuelAmount()+reactor.getWasteAmount() ~= reactor.getFuelAmountMax() then
- bgc(colors.lightGray)
- for yPos=4,height-4 do
- writeRightJustified(" ",yPos,1)
- end
- end
- bgc(colors.yellow)
- if reactor.getFuelAmount() > 0 then
- yPos = 4
- startY = 4
- while (yPos-startY)/(height-8) <= (reactor.getFuelAmount()+reactor.getWasteAmount())/reactor.getFuelAmountMax() do
- writeRightJustified(" ",height-yPos,1)
- yPos = yPos + 1
- end
- end
- bgc(colors.cyan)
- if reactor.getWasteAmount() > 1000 then
- yPos = 4
- startY = 4
- while (yPos-startY)/(height-8) <= reactor.getWasteAmount()/reactor.getFuelAmountMax() do
- writeRightJustified(" ",height-yPos,1)
- yPos = yPos + 1
- end
- end
- yPos = height-4
- bgc(colors.black)
- writeRightJustified(tostring(rodHeight).."%",height-2,1)
- bgc(colors.gray)
- startY = 4
- yPos = 4
- if rodHeight > 0 then
- while (yPos-startY)/(height-8) <= rodHeight/100 do
- writeRightJustified(" ",yPos,2)
- yPos = yPos+1
- end
- end
- bgc(colors.black)
- tc(colors.white)
- for yPos=1,height do
- mon.setCursorPos(width-6,yPos)
- mon.write("|")
- end
- --display reactor stats--
- if reactor.getActive() then
- tc(colors.red)
- writeLeft("Energy",4,1)
- tc(colors.white)
- writeLeft("Production: ",5,3)
- writeRightJustified(tostring(math.floor(
- reactor.getEnergyProducedLastTick())).." rf/t",
- 5,8)
- writeLeft("Stored:",6,3)
- writeRightJustified(tostring(math.floor(
- reactor.getEnergyStored())).." rf",
- 6,8)
- tc(colors.red)
- writeLeft("Fuel Amount",8,1)
- tc(colors.white)
- writeLeft("Capacity:",9,3)
- writeRightJustified(tostring(reactor.getFuelAmountMax()).." mb",
- 9,8)
- writeLeft("Fuel:",10,3)
- writeRightJustified(tostring(reactor.getFuelAmount()).." mb",
- 10,8)
- writeLeft("Waste:",11,3)
- writeRightJustified(tostring(reactor.getWasteAmount()).." mb",
- 11,8)
- tc(colors.red)
- writeLeft("Efficiency",13,1)
- tc(colors.white)
- writeLeft("Core Heat:",14,3)
- writeRightJustified(tostring(math.floor(
- reactor.getFuelTemperature())).." C",
- 14,8)
- writeLeft("Casing Heat:",15,3)
- writeRightJustified(tostring(math.floor(
- reactor.getCasingTemperature())).." C",
- 15,8)
- writeLeft("Fuel Use:",16,3)
- writeRightJustified(tostring(math.floor(1000*
- reactor.getFuelConsumedLastTick())/1000).." mb/t",
- 16,8)
- writeLeft("Reactivity:",17,3)
- writeRightJustified(tostring(math.floor((
- reactor.getFuelReactivity()))).."%",
- 17,8)
- end
- --bottom buttons--
- writeLeft("POWER!",height-4,1)
- onOff = " "
- if reactor.getActive() then
- bgc(colors.green)
- onOff = "ON"
- else
- bgc(colors.red)
- onOff = "OFF"
- end
- onOffBounds = fillRect(2,height-3,6,3)
- writeCentered(onOff,onOffBounds[2]+1,onOffBounds[1],onOffBounds[3])
- bgc(colors.black)
- writeLeft("Auto-Eject",height-4,onOffBounds[3]+1)
- if autoEject then
- bgc(colors.green)
- onOff = "ON"
- else
- bgc(colors.red)
- onOff = "OFF"
- end
- autoEjectBounds = fillRect(onOffBounds[3]+2,height-3,10,3)
- writeCentered(onOff,autoEjectBounds[2]+1,autoEjectBounds[1],autoEjectBounds[3])
- if not autoEject then
- bgc(colors.black)
- writeLeft("Eject Now",height-4,autoEjectBounds[3]+1)
- bgc(colors.red)
- ejectBounds = fillRect(autoEjectBounds[3]+2,height-3,9,3)
- end
- end
- function main ()
- x,y = -5,-5
- while true do
- drawGui()
- sleep(.25)
- if x ~= -5 then
- if x > width or y > height then
- x = -5
- y = -5
- elseif x == -1 then
- return
- elseif isInBounds(x,y,autoEjectBounds) then
- if autoEject then
- autoEject = false
- else
- autoEject = true
- end
- elseif not autoEject and isInBounds(x,y,ejectBounds) then
- reactor.doEjectWaste()
- elseif isInBounds(x,y,onOffBounds) then
- if reactor.getActive() then
- reactor.setActive(false)
- else
- reactor.setActive(true)
- end
- else
- if x >= width-5 and y >= height-1 then
- if y == height-1 and rodHeight > 0 then
- if x >= width-2 then
- rodHeight = rodHeight - 10
- if rodHeight < 0 then
- rodHeight = 0
- end
- else
- rodHeight = rodHeight - 1
- end
- reactor.setAllControlRodLevels(rodHeight)
- elseif y == height and rodHeight < 100 then
- if x >= width-2 then
- rodHeight = rodHeight + 10
- if rodHeight > 100 then
- rodHeight = 100
- end
- else
- rodHeight = rodHeight + 1
- end
- reactor.setAllControlRodLevels(rodHeight)
- end
- end
- end
- x,y = -5,-5
- end
- if autoEject then
- reactor.doEjectWaste()
- end
- end
- end
- function getInput ()
- while true do
- x,y = getClick()
- if x == -1 then
- return
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- term.write("press x to terminate program")
- parallel.waitForAll(main,getInput)
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement