Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local filePath = "basalt.lua"
- if not(fs.exists(filePath))then
- shell.run("wget https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basalt.lua "..filePath)
- end
- local basalt = dofile(filePath)
- --value init start
- local reactor = peripheral.wrap("back")
- local energyStored = reactor.battery().stored()
- local energyCapacity = reactor.battery().capacity()
- local energyPerTick = 0
- local fuelBurnedLastTick = 0
- local fuelCapacity = reactor.fuelTank().capacity()
- local fuelStored = 0
- local fuelReactivity = 0
- local fuelReactant = 0
- local fuelWaste = 0
- local controlRodCount = reactor.controlRodCount()
- local reactorRunning = false
- local burnTimerSeconds = 0
- local oldEnergyStored = energyStored
- local IOValue = {}
- local isAutoModeEnabled = false
- local isManuelEnabled = false
- local fuelRodLevel = 100
- local startThreshold = 0
- local stopThreshold = 0
- --value init end
- --settings start
- function saveSettings(var, value)
- settings.set(var, value)
- settings.save("reactor.settings")
- end
- function save()
- saveSettings("isAutoModeEnabled", isAutoModeEnabled)
- saveSettings("isManuelEnabled", isManuelEnabled)
- saveSettings("fuelRodLevel", fuelRodLevel)
- saveSettings("startThreshold", startThreshold)
- saveSettings("stopThreshold", stopThreshold)
- end
- if not(fs.exists("reactor.settings"))then
- save()
- end
- function loadSettings(var)
- settings.load("reactor.settings")
- return settings.get(var)
- end
- isAutoModeEnabled = loadSettings("isAutoModeEnabled")
- isManuelEnabled = loadSettings("isManuelEnabled")
- fuelRodLevel = loadSettings("fuelRodLevel")
- startThreshold = loadSettings("startThreshold")
- stopThreshold = loadSettings("stopThreshold")
- --settings end
- --function to round falues on x decimal places
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- --function to convert seconds to time
- function SecondsToTime(seconds)
- if seconds <= 0 then
- return "0:00:00";
- else
- hours = math.floor(seconds/3600);
- mins = math.floor(seconds/60 - (hours*60));
- secs = math.floor(seconds - hours*3600 - mins*60);
- return hours..":"..mins..":"..secs
- end
- end
- --get width and height of terminal
- local w, h = term.getSize()
- --init frames start
- local main = basalt.createFrame("mainFrame"):show()
- local homeFrame = main:addFrame("homeFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1):show()
- local fuelRodsFrame = main:addFrame("fuelRodsFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1)
- local mainThread = main:addThread("mainThread")
- local menuBar = main:addMenubar("mainMenuBar"):addItem("Overview"):addItem("Settings"):setBackground(colors.gray):setSize(w, 1):setSpace(4):show()
- menuBar:onChange(function(self)
- homeFrame:hide()
- fuelRodsFrame:hide()
- if(self:getValue().text=="Overview")then
- homeFrame:show()
- elseif(self:getValue().text=="Settings")then
- fuelRodsFrame:show()
- end
- end)
- --init frames end
- --totaly awesome button animation start
- local function visualButton(btn)
- btn:onClick(function(self) btn:setBackground(colors.black) btn:setForeground(colors.lightGray) end)
- btn:onClickUp(function(self) btn:setBackground(colors.gray) btn:setForeground(colors.black) end)
- btn:onLoseFocus(function(self) btn:setBackground(colors.gray) btn:setForeground(colors.black) end)
- end
- --totaly awesome button animation end
- --Overview start
- homeFrame:addLabel("energyLabel"):setText("Energy: "):setPosition(2,2):show()
- homeFrame:addLabel("energyStoredLabel"):setText("FE Stored: "):setPosition(3,3):show()
- energyStorage = homeFrame:addLabel("energyStoredValLabel"):setText(energyStored.." / "..energyCapacity.." FE"):setPosition(19,3):show()
- homeFrame:addLabel("energyProductionLabel"):setText("FE Pruduction: "):setPosition(3,4):show()
- energyTick = homeFrame:addLabel("energyProductionValLabel"):setText("0 FE/t"):setPosition(19,4):show()
- homeFrame:addLabel("energyIOLabel"):setText("Energy I/O: "):setPosition(3,5):show()
- ValueIOTick = homeFrame:addLabel("energyIOValLabel"):setText(0):setPosition(19,5):show()
- homeFrame:addLabel("fuelLabel"):setText("Fuel: "):setPosition(2,7):show()
- homeFrame:addLabel("fuelStoredLabel"):setText("Fuel Stored: "):setPosition(3,8):show()
- fuelStorage = homeFrame:addLabel("fuelStoredValLabel"):setText(fuelStored.." / "..fuelCapacity.." mB"):setPosition(19,8):show()
- homeFrame:addLabel("wasteStoredLabel"):setText("Waste Stored: "):setPosition(3,9):show()
- wasteStorage = homeFrame:addLabel("wasteStoredValLabel"):setText(fuelWaste.." / "..fuelCapacity.." mB"):setPosition(19,9):show()
- homeFrame:addLabel("fuelUsedLabel"):setText("Fuel Burned: "):setPosition(3,10):show()
- fuelUsed = homeFrame:addLabel("fuelUsedValLabel"):setText(fuelBurnedLastTick.." mB/t"):setPosition(19,10):show()
- homeFrame:addLabel("fuelUsedTimeLabel"):setText("Time per Ingot: "):setPosition(3,11):show()
- fuelUsedTime = homeFrame:addLabel("fuelUsedTimeValLabel"):setText(0):setPosition(19,11):show()
- homeFrame:addLabel("fuelBurnedTimeLabel"):setText("Ingot burned: "):setPosition(3,12):show()
- fuelBurnedTime = homeFrame:addLabel("fuelBurnedTimeValLabel"):setText(0):setPosition(19,12):show()
- homeFrame:addLabel("benchmarkLabel"):setText("Benchmark: "):setPosition(3,13):show()
- fuelBenchmark = homeFrame:addLabel("benchmarkValLabel"):setText(0):setPosition(19,13):show()
- homeFrame:addLabel("statusLabel"):setText("Status: "):setPosition(2,15):show()
- homeFrame:addLabel("activeLabel"):setText("Active: "):setPosition(3,16):show()
- activeLabel = homeFrame:addLabel("activeValLabel"):setText(0):setPosition(19,16):show()
- homeFrame:addLabel("autoModeLabel"):setText("Auto Mode: "):setPosition(3,17):show()
- autoModeLabel = homeFrame:addLabel("autoModeValLabel"):setText(0):setPosition(19,17):show()
- btnActivate = homeFrame:addButton("btnActivate"):setText("Activate"):setAnchor("right"):setSize(11,3):setPosition(2,2):onClick(function()
- reactor.setActive(not reactor.active())
- end):show()
- btnAutoMode = homeFrame:addButton("btnAutoMode"):setText("Auto Mode"):setAnchor("right"):setSize(11,3):setPosition(2,6):onClick(function()
- isManuelEnabled = false
- isAutoModeEnabled = not isAutoModeEnabled
- save()
- end):show()
- btnManuel = homeFrame:addButton("btnManuel"):setText("Manuel"):setAnchor("right"):setSize(11,3):setPosition(2,10):onClick(function()
- isAutoModeEnabled = false
- isManuelEnabled = not isManuelEnabled
- save()
- end):show()
- --Overview end
- --Settings start
- fuelRodsFrame:addLabel("powerLabel"):setText("Fuelrod Level:"):setPosition(2,2):show()
- powerValLabel = fuelRodsFrame:addLabel("powerValLabel"):setText("0%"):setPosition(19,3):show()
- visualButton(fuelRodsFrame:addButton("rodLevelPlus1"):setText("+1"):setSize(2,1):setPosition(30,3):onClick(function()
- if((fuelRodLevel+1) < 100) then
- fuelRodLevel = fuelRodLevel+1
- else
- fuelRodLevel = 100
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("rodLevelPlus5"):setText("+5"):setSize(2,1):setPosition(33,3):onClick(function()
- if((fuelRodLevel+5) < 100) then
- fuelRodLevel = fuelRodLevel+5
- else
- fuelRodLevel = 100
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("rodLevelPlus19"):setText("+10"):setSize(3,1):setPosition(36,3):onClick(function()
- if((fuelRodLevel+10) < 100) then
- fuelRodLevel = fuelRodLevel+10
- else
- fuelRodLevel = 100
- end
- save()
- end):show())
- rodLevel = fuelRodsFrame:addProgressbar("rodLevelProgressbar"):setSize(16,1):setPosition(13,3):show()
- visualButton(fuelRodsFrame:addButton("rodLevelMinus1"):setText("-1"):setSize(2,1):setPosition(3,3):onClick(function()
- if((fuelRodLevel-1) > 0) then
- fuelRodLevel = fuelRodLevel-1
- else
- fuelRodLevel = 0
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("rodLevelMinus5"):setText("-5"):setSize(2,1):setPosition(6,3):onClick(function()
- if((fuelRodLevel-5) > 0) then
- fuelRodLevel = fuelRodLevel-5
- else
- fuelRodLevel = 0
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("rodLevelMinus19"):setText("-10"):setSize(3,1):setPosition(9,3):onClick(function()
- if((fuelRodLevel-10) > 0) then
- fuelRodLevel = fuelRodLevel-10
- else
- fuelRodLevel = 0
- end
- save()
- end):show())
- fuelRodsFrame:addLabel("startThresholdLabel"):setText("Start Threshold:"):setPosition(2,5):show()
- startThresholdValLabel = fuelRodsFrame:addLabel("startThresholdValLabel"):setText("0%"):setPosition(19,6):show()
- visualButton(fuelRodsFrame:addButton("startThresholdLevelPlus1"):setText("+1"):setSize(2,1):setPosition(30,6):onClick(function()
- if((startThreshold+1) < 100) then
- startThreshold = startThreshold+1
- else
- startThreshold = 100
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("startThresholdLevelPlus5"):setText("+5"):setSize(2,1):setPosition(33,6):onClick(function()
- if((startThreshold+5) < 100) then
- startThreshold = startThreshold+5
- else
- startThreshold = 100
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("startThresholdLevelPlus19"):setText("+10"):setSize(3,1):setPosition(36,6):onClick(function()
- if((startThreshold+10) < 100) then
- startThreshold = startThreshold+10
- else
- startThreshold = 100
- end
- save()
- end):show())
- startThresholdLevel = fuelRodsFrame:addProgressbar("startThresholdLevelProgressbar"):setSize(16,1):setPosition(13,6):show()
- visualButton(fuelRodsFrame:addButton("startThresholdLevelMinus1"):setText("-1"):setSize(2,1):setPosition(3,6):onClick(function()
- if((startThreshold-1) > 0) then
- startThreshold = startThreshold-1
- else
- startThreshold = 0
- end
- end):show())
- visualButton(fuelRodsFrame:addButton("startThresholdLevelMinus5"):setText("-5"):setSize(2,1):setPosition(6,6):onClick(function()
- if((startThreshold-5) > 0) then
- startThreshold = startThreshold-5
- else
- startThreshold = 0
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("startThresholdLevelMinus19"):setText("-10"):setSize(3,1):setPosition(9,6):onClick(function()
- if((startThreshold-10) > 0) then
- startThreshold = startThreshold-10
- else
- startThreshold = 0
- end
- save()
- end):show())
- fuelRodsFrame:addLabel("stopThresholdLabel"):setText("Stop Threshold:"):setPosition(2,8):show()
- stopThresholdValLabel = fuelRodsFrame:addLabel("stopThresholdValLabel"):setText("0%"):setPosition(19,9):show()
- visualButton(fuelRodsFrame:addButton("stopThresholdLevelPlus1"):setText("+1"):setSize(2,1):setPosition(30,9):onClick(function()
- if((stopThreshold+1) < 100) then
- stopThreshold = stopThreshold+1
- else
- stopThreshold = 100
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("stopThresholdLevelPlus5"):setText("+5"):setSize(2,1):setPosition(33,9):onClick(function()
- if((stopThreshold+5) < 100) then
- stopThreshold = stopThreshold+5
- else
- stopThreshold = 100
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("stopThresholdLevelPlus19"):setText("+10"):setSize(3,1):setPosition(36,9):onClick(function()
- if((stopThreshold+10) < 100) then
- stopThreshold = stopThreshold+10
- else
- stopThreshold = 100
- end
- save()
- end):show())
- stopThresholdLevel = fuelRodsFrame:addProgressbar("stopThresholdLevelProgressbar"):setSize(16,1):setPosition(13,9):show()
- visualButton(fuelRodsFrame:addButton("stopThresholdLevelMinus1"):setText("-1"):setSize(2,1):setPosition(3,9):onClick(function()
- if((stopThreshold-1) > 0) then
- stopThreshold = stopThreshold-1
- else
- stopThreshold = 0
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("stopThresholdLevelMinus5"):setText("-5"):setSize(2,1):setPosition(6,9):onClick(function()
- if((stopThreshold-5) > 0) then
- stopThreshold = stopThreshold-5
- else
- stopThreshold = 0
- end
- save()
- end):show())
- visualButton(fuelRodsFrame:addButton("stopThresholdLevelMinus19"):setText("-10"):setSize(3,1):setPosition(9,9):onClick(function()
- if((stopThreshold-10) > 0) then
- stopThreshold = stopThreshold-10
- else
- stopThreshold = 0
- end
- save()
- end):show())
- --Settings end
- --Calculation Thread start
- rodsRunning = 0
- local function calcThread()
- while true do
- for i = 0, controlRodCount-1 do
- if(reactor.getControlRod(i).level() < 100) then
- rodsRunning = rodsRunning + 1
- end
- end
- if(rodsRunning > 0) then
- reactorRunning = true
- else
- reactorRunning = false
- end
- if(isManuelEnabled) then
- btnManuel:setBackground(colors.green)
- btnManuel:setForeground(colors.darkGray)
- else
- btnManuel:setBackground(colors.red)
- btnManuel:setForeground(colors.darkGray)
- end
- if(isAutoModeEnabled) then
- btnAutoMode:setBackground(colors.green)
- btnAutoMode:setForeground(colors.darkGray)
- autoModeLabel:setText("On")
- else
- btnAutoMode:setBackground(colors.red)
- btnAutoMode:setForeground(colors.darkGray)
- autoModeLabel:setText("Off")
- end
- if(reactor.active()) then
- btnActivate:setBackground(colors.green)
- btnActivate:setForeground(colors.darkGray)
- activeLabel:setText("On")
- else
- btnActivate:setBackground(colors.red)
- btnActivate:setForeground(colors.darkGray)
- activeLabel:setText("Off")
- end
- rodLevel:setProgress(fuelRodLevel)
- powerValLabel:setText(fuelRodLevel.."%")
- startThresholdLevel:setProgress(startThreshold)
- startThresholdValLabel:setText(startThreshold.."%")
- stopThresholdLevel:setProgress(stopThreshold)
- stopThresholdValLabel:setText(stopThreshold.."%")
- fuelStored = reactor.fuelTank().fuel()
- energyStored = reactor.battery().stored()
- energyPerTick = reactor.battery().producedLastTick()
- fuelWaste = reactor.fuelTank().waste()
- fuelBurnedLastTick = round(reactor.fuelTank().burnedLastTick(), 4)
- energyStorage:setText(energyStored.." / "..energyCapacity.." FE")
- energyTick:setText(energyPerTick.." FE/t")
- fuelStorage:setText(fuelStored.." / "..fuelCapacity.." mB")
- wasteStorage:setText(fuelWaste.." / "..fuelCapacity.." mB")
- fuelUsed:setText(fuelBurnedLastTick.." mB/t")
- if(reactorRunning) then
- burnTimerSeconds = (1000-fuelWaste)/(fuelBurnedLastTick*20)
- burnTimeSeconds = 1000/(fuelBurnedLastTick*20)
- benchmarkVal = math.floor(energyPerTick/reactor.fuelTank().burnedLastTick()/100)
- else
- burnTimerSeconds = 0
- burnTimeSeconds = 0
- benchmarkVal = 0
- end
- fuelBenchmark:setText(benchmarkVal.."")
- fuelBurnedTime:setText(SecondsToTime(burnTimerSeconds))
- fuelUsedTime:setText(SecondsToTime(burnTimeSeconds))
- if(#IOValue == 60) then
- table.remove(IOValue, 1)
- end
- table.insert(IOValue, (energyStored-oldEnergyStored))
- IOValueOutput = 0
- for i = 1, #IOValue do
- IOValueOutput = IOValueOutput + IOValue[i]
- end
- IOValueOutput = math.floor((IOValueOutput/#IOValue)/20)
- ValueIOTick:setText(IOValueOutput)
- oldEnergyStored = energyStored
- energyStoredPct = (energyStored*100)/energyCapacity
- if(reactor.active()) then
- if(isAutoModeEnabled) then
- if(energyStoredPct < startThreshold) then
- reactor.setAllControlRodLevels(fuelRodLevel)
- elseif(energyStoredPct > stopThreshold) then
- reactor.setAllControlRodLevels(100)
- end
- elseif(isManuelEnabled) then
- reactor.setAllControlRodLevels(fuelRodLevel)
- else
- reactor.setAllControlRodLevels(100)
- end
- end
- os.sleep(1)
- rodsRunning = 0
- end
- end
- mainThread:start(calcThread)
- --Calculation Thread end
- basalt.autoUpdate()
Add Comment
Please, Sign In to add comment