Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::start::
- -- Set Requirements & Variables
- component = require("component")
- event = require("event")
- term = require("term")
- thread = require("thread")
- unicode= require("unicode")
- gpu = component.gpu
- screen = component.screen
- reactorOutputMultiplier = 1
- cutoffTemp = 9005
- chaosMode = 0
- tempDrop = 0
- devMode = 0
- deviation = 0
- cVar = "Do not use Chaos Mode with less than one block of fuel"
- ratioX, ratioY = screen.getAspectRatio()
- maxX, maxY = gpu.maxResolution()
- tArgs = {...}
- adj_button_width = 19
- tempOffsetX = 62
- tempOffsetY = 2
- fieldOffsetX = tempOffsetX + adj_button_width + 2
- fieldOffsetY = 2
- cutoffField = 0.75
- highest_use = 0.1
- -- Set Resolution
- gpu.setResolution(math.min(ratioX*55, maxX), math.min(ratioY*25,maxY))
- term.clear()
- term.setCursor(0, 0)
- -- Program Help & Credits
- if tostring(tArgs[1]) == "-h" then
- os.execute(cls)
- print("Draconic Control 15.2")
- print("[1.12 and 1.16 Compatible]")
- print()
- print("dc15 [O] [T] [F] [M]")
- print()
- print("Start Arguments")
- print()
- print("[O] - Reactor Output Multiplier")
- print("This is set in your Draconic Evolution")
- print("configs, by default 1.12.2 uses 1, and")
- print("1.16.5 uses 10.")
- print()
- print("[T] - Desired Reactor Temperature")
- print("Recommended [8000]")
- print("Range [2500-8000]")
- print()
- print("[F] - Desired Field Strength %")
- print("Recommended [10]")
- print("Range [0.5-99]")
- print()
- print("[M] - User Interface Selection")
- print("Default [1]")
- print("Range [1-3]")
- print("Simple, Developer, Text Only")
- print()
- print()
- print()
- print("Compiled by BrokenSynapse & AwesomeAlec1")
- print()
- print("Thanks to Maurdekye for creating the base of this program:")
- print("https://youtu.be/iLvkk41K84E")
- print()
- print("Thanks to AwesomeAlec1 for creating the control script:")
- print("https://youtu.be/CLku1ckXpeU")
- print()
- print("Thanks to MightyPirates for being so gracious as to")
- print("let me fix what they broke by never using Lua 5.3")
- print()
- print("And a very special thanks to ZanBorg for breaking")
- print("this script until it doesn't break anymore.")
- goto fin
- end
- -- Set Control Variables
- reactorOutputMultiplier = tonumber(tArgs[1]) or 1
- idealTemp = tonumber(tArgs[2]) or 8000
- idealField = tonumber(tArgs[3]) or 15
- Mode = tonumber(tArgs[4]) or 1
- -- Register Components
- -- Check For Reactor
- if not component.isAvailable("draconic_reactor") then
- print("Reactor not connected. Please connect computer to reactor with an Adapter block.")
- os.exit()
- end
- reactor = component.draconic_reactor
- info = reactor.getReactorInfo()
- -- Check For Flux Gates
- fluxGates = {}
- for x,y in pairs(component.list("flux_gate")) do
- fluxGates[#fluxGates+1] = x
- end
- if #fluxGates < 2 then
- print("Not enough flux gates connected; please connect inflow and outflow flux gates with Adapter blocks.")
- os.exit()
- end
- inputFlux = component.proxy(fluxGates[1])
- outputFlux = component.proxy(fluxGates[2])
- outputFlux.setOverrideEnabled(true)
- inputFlux.setOverrideEnabled(true)
- if not inputFlux or not outputFlux then
- print("Not enough flux gates connected; please connect inflow and outflow flux gates with Adapter blocks.")
- os.exit()
- end
- print("Input and Output Flux Gates Available")
- -- Automatically Set Input & Output Flux Gates
- reactor.chargeReactor()
- satOne = info.energySaturation
- fieldOne = info.fieldStrength
- inputFlux.setFlowOverride(1.0)
- os.sleep(0.1)
- satTwo = info.energySaturation
- fieldTwo = info.fieldStrength
- inputFlux.setFlowOverride(0.0)
- reactor.stopReactor()
- if satTwo <= satOne or fieldTwo <= fieldOne then
- oldAddr = inputFlux.address
- inputFlux = component.proxy(outputFlux.address)
- outputFlux = component.proxy(oldAddr)
- end
- print("Input and Output Flux Gates Set")
- -- Functions & Arrays
- -- Exit Message
- function exit_msg(msg)
- term.clear()
- print(msg)
- os.exit()
- end
- -- Temperature Controls
- function modifyTemp(offset)
- newTemp = idealTemp + offset
- if newTemp > 8000 and Mode == 1 then
- newTemp = 8000
- elseif newTemp > 15000 then
- newTemp = 15000
- elseif newTemp < 2000 then
- newTemp = 2000
- end
- idealTemp = newTemp
- end
- -- Field Strength Controls
- function modifyField(offset)
- newField = idealField + offset
- if newField > 99 then
- newField = 99
- elseif newField < 99 and chaosMode == 1 then
- newField = 99
- elseif newField < 1.0 and Mode == 1 or Mode == 3 then
- newField = 1.0
- elseif newField < 0.5 and Mode == 2 then
- newField = 0.5
- end
- idealField = newField
- end
- print("Functions Declared")
- eventLoop = true
- function primaryCalculations()
- print("PrimaryCalc Start")
- while eventLoop do
- info = reactor.getReactorInfo()
- -- Reactor equation variables
- targetTemp50 = math.min((idealTemp / 10000) * 50, 99)
- coreSat = info.energySaturation / info.maxEnergySaturation
- convLVL = (info.fuelConversion / info.maxFuelConversion * 1.3) - 0.3
- -- Calculate the temperature rise resistance for the reactor at the desired temperature.
- targetTempResist = ((targetTemp50^4) / (100 - targetTemp50))
- -- Calculate the temperature rise exponential needed to reach the desired temperature
- targetTempExpo = -(targetTempResist*convLVL) - 1000*convLVL + targetTempResist
- -- Calculate the saturation level needed to produce the required tempRiseExpo
- term1 = 1334.1-(3*targetTempExpo)
- term2 = (1200690-(2700*targetTempExpo))^2
- term3 = ((-1350*targetTempExpo)+(((-4*term1^3+term2)^(1/2))/2)+600345)^(1/3)
- targetNegCSat = -(term1/(3*term3))-(term3/3)
- -- Saturation received from above equation needs to be reformatted to a more useful form
- targetCoreSat = 1 - (targetNegCSat/99)
- targetSat = targetCoreSat * info.maxEnergySaturation
- -- Calculate the difference between where saturation is and where it needs to be
- saturationError = info.energySaturation - targetSat
- -- Calculate field drain
- tempDrainFactor = 0
- if info.temperature > 8000 then
- tempDrainFactor = 1 + ((info.temperature-8000)^2 * 0.0000025)
- elseif info.temperature > 2000 then
- tempDrainFactor = 1
- elseif info.temperature > 1000 then
- tempDrainFactor = (info.temperature-1000)/1000
- end
- baseMaxRFt = (info.maxEnergySaturation / 1000) * reactorOutputMultiplier * 1.5
- fieldDrain = math.min(tempDrainFactor * math.max(0.01, (1-coreSat)) * (baseMaxRFt / 10.923556), 2147000000)
- fieldNegPercent = 1 - idealField
- -- fieldInputRate = fieldDrain / fieldNegPercent
- fieldStrengthError = (info.maxFieldStrength * idealField) - info.fieldStrength
- requiredInput = math.min((info.maxFieldStrength * info.fieldDrainRate) / (info.maxFieldStrength - info.fieldStrength), info.maxFieldStrength - info.fieldStrength)
- --Automations
- if info.status == "running" then
- outputNeeded = math.min(saturationError, (info.maxEnergySaturation/40))-- + info.generationRate
- outputFlux.setFlowOverride(outputNeeded)
- inputFlux.setFlowOverride(math.min(fieldStrengthError + requiredInput, info.maxFieldStrength) - info.fieldDrainRate + 1)
- elseif info.status == "warming_up" then
- outputFlux.setFlowOverride(0)
- inputFlux.setFlowOverride(550000000)
- elseif info.status == "stopping" then
- outputFlux.setFlowOverride(0)
- inputFlux.setFlowOverride(requiredInput)
- end
- --print("primaryCalculations okay")
- os.sleep(0.01)
- end
- print("primaryCalculations thread exited")
- end
- print("Primary Calculation Loop Defined")
- -- UI Related Calculations
- function secondaryCalculations()
- print("SecondaryCalc Start")
- while eventLoop do
- -- Safety Measures
- if info.status == "running" then
- if info.temperature > cutoffTemp then
- print("Reactor Too Hot, shutting down")
- reactor.stopReactor()
- end
- if ((info.fieldStrength / info.maxFieldStrength) * 100) < cutoffField then
- print("Reactor Field Has Failed, Failsafe Activated, Shutting Down")
- reactor.stopReactor()
- end
- if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 0.2 then
- print("Reactor Fuel Low, Shutting Down")
- reactor.stopReactor()
- end
- end
- -- Set Secondary Calculations
- -- Get Temp Rise
- oldTemp = currentTemp or info.temperature
- currentTemp = info.temperature
- oldTempRate = tempChangeRate or currentTemp - oldTemp
- tempChangeRate = currentTemp - oldTemp
- tempAccel = tempChangeRate - oldTempRate
- if tempAccel == 0 then
- tempAccel = 0.001
- end
- -- Get Fuel Use Rate
- oldFuel = currentFuel or (info.maxFuelConversion - info.fuelConversion)
- currentFuel = (info.maxFuelConversion - info.fuelConversion)
- oldUseRate = fuelUseRate or math.max(info.fuelConversionRate*20, 0.1)
- fuelUseRate = math.max(info.fuelConversionRate*20, 0.1)
- fuelAccel = math.max(fuelUseRate - oldUseRate, 0.1)
- -- Change Fuel Conversion Units
- if info.fuelConversionRate > 249999 then
- fuelConversionRate = ((info.fuelConversionRate / (info.maxFuelConversion * 1000000)) * 2000)
- fuelMeasure = " %%/s"
- elseif info.fuelConversionRate > 999 then
- fuelConversionRate = (info.fuelConversionRate / 1000)
- fuelMeasure = " "..(unicode.char(956)).."b/t"
- elseif info.fuelConversionRate > 999999 then
- fuelConversionRate = (info.fuelConversionRate / 1000000)
- fuelMeasure = " mb/t"
- else
- fuelConversionRate = info.fuelConversionRate
- fuelMeasure = " nb/t"
- end
- -- Get Time Until Cool
- if info.fuelConversionRate < 1 then
- tempDrain = ((info.temperature - 2000) / 0.4)
- else
- tempDrain = 1
- end
- -- Get Equivalent Solar Fusion Stage
- if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 20 then burnStage = "H"
- elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 15 then burnStage = "He"
- elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 10 then burnStage = "C"
- elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 8 then burnStage = "Ne"
- elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 5.5 then burnStage = "O"
- elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 2.5 then burnStage = "Si"
- elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 1 then burnStage = "Fe"
- end
- -- Get Field Deviation
- if ((info.fieldStrength / info.maxFieldStrength) * 100) > idealField then
- deviation = (((info.fieldStrength / info.maxFieldStrength) * 100)) - idealField
- elseif ((info.fieldStrength / info.maxFieldStrength) * 100) < idealField then
- deviation = idealField - (((info.fieldStrength / info.maxFieldStrength) * 100))
- end
- -- Get Time Until Refuel
- secondsToExpire = (info.maxFuelConversion - info.fuelConversion) / math.max(info.fuelConversionRate*0.00002, 0.00001)
- end
- print("secondaryCalculations thread exited")
- end
- print("Secondary Calculation Loop Defined")
- -- Draw GUI
- function drawGUI()
- print("DrawGUI Start")
- os.sleep(5)
- -- Button Array
- buttons = {
- startButton={
- x=2,
- y=20,
- width=18,
- height=1,
- text="Start",
- textcolor = 0x0000AA,
- action=function()
- if info.status == "cooling" or info.status == "cold" then
- chaosMode = 0
- idealField = tonumber(tArgs[3])
- cutoffField = 0.4
- idealTemp = tonumber(tArgs[2])
- cVar = "Do not use Chaos Mode with less than one block of fuel"
- reactor.chargeReactor()
- elseif info.status == "stopping" then
- chaosMode = 0
- idealField = tonumber(tArgs[3])
- cutoffField = 0.4
- idealTemp = tonumber(tArgs[2])
- cVar = "Do not use Chaos Mode with less than one block of fuel"
- reactor.activateReactor()
- end
- end,
- condition=function() return info.status ~= "running" and info.status ~= "warming_up" end
- },
- shutdownButton={
- x=2,
- y=20,
- width=18,
- height=1,
- text="Shutdown",
- textcolor = 0xAA0000,
- action=function()
- cutoffTemp = 9000
- idealTemp = tonumber(tArgs[2])
- idealField = tonumber(tArgs[3])
- cutoffField = 0.4
- chaosMode = 0
- cVar = "Do not use Chaos Mode with less than one block of fuel"
- state = "MASD"
- reactor.stopReactor()
- end,
- condition=function() return info.status == "running" or info.status == "warming_up" end
- },
- chaosMode={
- x=2,
- y=22,
- width=18,
- height=1,
- text=" Chaos Mode",
- textcolor = 0x800080,
- action=function()
- if chaosMode == 0 then
- chaosMode = 1
- cutoffTemp = 19750
- idealField = 99
- cutoffField = 5
- idealTemp = 55537.78
- elseif chaosMode == 1 then
- chaosMode = 0
- idealField = tonumber(tArgs[3])
- cutoffField = 0.4
- idealTemp = tonumber(tArgs[2])
- end
- end,
- condition=function() return Mode == 2 and info.status == "running" end
- },
- forceExit={
- x=158,
- y=1,
- width=3,
- height=1,
- text=" X ",
- textcolor = 0xB00000,
- action=function()
- inputFlux.setFlowOverride(250000)
- chaosMode = 0
- idealField = 99
- cutoffField = 0.4
- idealTemp = tonumber(tArgs[2])
- reactor.stopReactor()
- gpu.setResolution(gpu.maxResolution())
- event_loop = false
- os.execute("cls")
- end,
- -- condition=function() return running or shutting_down end
- },
- Update={
- x=22,
- y=22,
- width=18,
- height=1,
- text="Update",
- action=function()
- reactor.stopReactor()
- os.execute("cd /home; pastebin get -f hh14Sxhi dc15; cls; dc15")
- end,
- condition=function() return info.status ~= "running" and info.status ~= "warming_up" end
- },
- switchGates={
- x=2,
- y=22,
- width=18,
- height=1,
- text="Swap Flux Gates",
- action=function()
- cutoffTemp = 10500
- old_addr = inputFlux.address
- inputFlux = component.proxy(outputFlux.address)
- outputFlux = component.proxy(old_addr)
- end,
- condition=function() return info.status == "cooling" or info.status == "cold" or info.status == "stopping" end
- },
- tempMax={
- x=tempOffsetX,
- y=tempOffsetY,
- width=adj_button_width,
- height=1,
- text="Maximum",
- textcolor = 0x552222,
- action=function()
- idealTemp = 8000 end
- },
- tempPThousand={
- x=tempOffsetX,
- y=tempOffsetY+2,
- width=adj_button_width,
- height=1,
- text="+1000",
- textcolor = 0x552222,
- action=function() modifyTemp(1000) end
- },
- tempPHundred={
- x=tempOffsetX,
- y=tempOffsetY+4,
- width=adj_button_width,
- height=1,
- text="+100",
- textcolor = 0x552222,
- action=function() modifyTemp(100) end
- },
- tempPTen={
- x=tempOffsetX,
- y=tempOffsetY+6,
- width=adj_button_width,
- height=1,
- text="+10",
- textcolor = 0x552222,
- action=function() modifyTemp(10) end
- },
- tempPOne={
- x=tempOffsetX,
- y=tempOffsetY+8,
- width=adj_button_width,
- height=1,
- text="+1",
- textcolor = 0x552222,
- action=function() modifyTemp(1) end
- },
- tempMin={
- x=tempOffsetX,
- y=tempOffsetY+20,
- width=adj_button_width,
- height=1,
- text="Minimum",
- textcolor = 0x552222,
- action=function() modifyTemp(-20000) end
- },
- tempMThousand={
- x=tempOffsetX,
- y=tempOffsetY+18,
- width=adj_button_width,
- height=1,
- text="-1000",
- textcolor = 0x552222,
- action=function() modifyTemp(-1000) end
- },
- tempMHundred={
- x=tempOffsetX,
- y=tempOffsetY+16,
- width=adj_button_width,
- height=1,
- text="-100",
- textcolor = 0x552222,
- action=function() modifyTemp(-100) end
- },
- tempMTen={
- x=tempOffsetX,
- y=tempOffsetY+14,
- width=adj_button_width,
- height=1,
- text="-10",
- textcolor = 0x552222,
- action=function() modifyTemp(-10) end
- },
- tempMOne={
- x=tempOffsetX,
- y=tempOffsetY+12,
- width=adj_button_width,
- height=1,
- text="-1",
- textcolor = 0x552222,
- action=function() modifyTemp(-1) end
- },
- fieldPTen={
- x=fieldOffsetX,
- y=fieldOffsetY+1,
- width=adj_button_width,
- height=1,
- text="+10",
- textcolor = 0x222299,
- action=function() modifyField(10) end
- },
- fieldPOne={
- x=fieldOffsetX,
- y=fieldOffsetY+3,
- width=adj_button_width,
- height=1,
- text="+1",
- textcolor = 0x222299,
- action=function() modifyField(1) end
- },
- fieldPTenth={
- x=fieldOffsetX,
- y=fieldOffsetY+5,
- width=adj_button_width,
- height=1,
- text="+0.1",
- textcolor = 0x222299,
- action=function() modifyField(0.1) end
- },
- fieldPThou={
- x=fieldOffsetX,
- y=fieldOffsetY+7,
- width=adj_button_width,
- height=1,
- text="+0.005",
- textcolor = 0x222299,
- action=function() modifyField(0.005) end
- },
- fieldMTen={
- x=fieldOffsetX,
- y=fieldOffsetY+19,
- width=adj_button_width,
- height=1,
- text="-10",
- textcolor = 0x222299,
- action=function() modifyField(-10) end
- },
- fieldMOne={
- x=fieldOffsetX,
- y=fieldOffsetY+17,
- width=adj_button_width,
- height=1,
- text="-1",
- textcolor = 0x222299,
- action=function() modifyField(-1) end
- },
- fieldMTenth={
- x=fieldOffsetX,
- y=fieldOffsetY+15,
- width=adj_button_width,
- height=1,
- text="-0.1",
- textcolor = 0x222299,
- action=function() modifyField(-0.1) end
- },
- fieldMThou={
- x=fieldOffsetX,
- y=fieldOffsetY+13,
- width=adj_button_width,
- height=1,
- text="-0.005",
- textcolor = 0x222299,
- action=function() modifyField(-0.005) end
- }
- }
- -- Draw Relevant Data For GUI
- while eventLoop do
- if term.isAvailable() and Mode ~= 3 then
- function modify_eff(offset)
- eff = ((outputFlux / inputFlux) * 100)
- if eff > 100000 then
- eff = 1
- end
- end
- left_margin = 2
- spacing = 1
- values = {
- "Draconic Control™ [v16.0 xSMT | T3Zucygs]",
- " ",
- "┌──────────────────Reactor Statistics────────────────────┐",
- string.format("│Time Until Refuel: │ %5.0fd, %2.0fh, %2.0fm, %2.0fs │", secondsToExpire/86400, secondsToExpire /3600 % 24, secondsToExpire/60 % 60, secondsToExpire % 60),
- string.format("│Time Until Cool: │ %5.0fd, %2.0fh, %2.0fm, %2.0fs │", tempDrain/86400, tempDrain /3600 % 24, tempDrain/60 % 60, tempDrain % 60),
- string.format("│Ideal Field: │ %8.3f%% │", idealField),
- string.format("│Current Field: │ %8.3f%% │", ((info.fieldStrength / info.maxFieldStrength) * 100) + 0.122),
- "├───────────────────────────┼────────────────────────────┤",
- string.format("│Fuel Remaining: │ %7.3f%% │", ((1 - info.fuelConversion / info.maxFuelConversion) * 100)),
- string.format("│Fuel Use Rate: │ %7.3f" .. fuelMeasure .. " │", fuelConversionRate),
- "├───────────────────────────┼────────────────────────────┤",
- string.format("│Temperature │ %7.1f°c [%8.1f°f] │", info.temperature, ((info.temperature * 1.8) + 32)),
- string.format("│Ideal Temperature: │ %7.1f°c [%8.1f°f] │", idealTemp, ((idealTemp * 1.8) + 32)),
- "├───────────────────────────┼────────────────────────────┤",
- string.format("│Energy Input: │ %12.1f RF/t │", requiredInput),
- string.format("│Energy Output: │ %12.1f RF/t │", outputFlux.getFlow()),
- "└───────────────────────────┴────────────────────────────┘",
- " " .. cVar,
- " "
- }
- values2 = {
- " ",
- " ",
- " ",
- " [Reference Table]",
- " ┌─────────────┬─────────────┬─────────────┐",
- " │ Temperature │ Remaining │ Consumption │",
- " ├─────────────┼─────────────┼─────────────┤",
- " │ 14000 │ 93.27 │ 91.90 │",
- " ├─────────────┼─────────────┼─────────────┤",
- " │ 15000 │ 59.00 │ 123.5 │",
- " ├─────────────┼─────────────┼─────────────┤",
- " │ 16000 │ 36.45 │ 161 │",
- " ├─────────────┼─────────────┼─────────────┤",
- " │ 17000 │ 21.40 │ 204 │",
- " ├─────────────┼─────────────┼─────────────┤",
- " │ 18000 │ 11.80 │ 251 │",
- " ├─────────────┼─────────────┼─────────────┤",
- " │ 19000 │ 03.89 │ 303 │",
- " └─────────────┴─────────────┴─────────────┘",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- "Eq. Fusion Stage " .. burnStage,
- string.format("Max Fuel [nb]: %4.3f", (info.maxFuelConversion * 1000000)),
- string.format("Fuel Remaining [nb]: %4.3f", ((info.maxFuelConversion - info.fuelConversion) * 1000000)),
- string.format("Temperature Rise: %4.3f", tempAccel),
- string.format("Temp Resist for target temp %d (%d): %.2f", idealTemp, targetTemp50, targetTempResist),
- string.format("Temp expo for convLVL %.2f: %.2f", convLVL, targetTempExpo),
- string.format("Saturation needed for zero rise: %d (%3.2f%%)", targetSat, targetCoreSat*100),
- string.format("Error between current saturation and target saturation: %d\n", saturationError),
- string.format("Current field drain is %d RF/t", info.fieldDrainRate),
- string.format("Current temp drain factor for temp %d is %1.2f", info.temperature, tempDrainFactor),
- string.format("fieldNegPercent is %d", fieldNegPercent),
- string.format("Required input to counter field drain: %d RF/t\n", requiredInput),
- string.format("Field Deviation: " .. unicode.char(8776) .. deviation .. "%%"),
- string.format("Input Flux Gate: [" .. inputFlux.address .. "] Set To: " .. inputFlux.getFlow()),
- string.format("Output Flux Gate: [" .. outputFlux.address .. "] Set To: " .. outputFlux.getFlow())
- }
- term.clear()
- if Mode == 2 and Mode ~= 3 then
- for i, v in ipairs(values2) do
- term.setCursor(left_margin, i * spacing)
- term.write(v)
- end
- end
- if Mode ~= 3 then
- for i, v in ipairs(values) do
- term.setCursor(left_margin, i * spacing)
- term.write(v)
- end
- end
- -- Draw Buttons For GUI
- term.setCursor(tempOffsetX, tempOffsetY+10)
- term.write("Reactor Temperature")
- term.setCursor(fieldOffsetX+1, fieldOffsetY+10)
- term.write(" Field Strength")
- gpu.setForeground(0xFFFFFF)
- for bname, button in pairs(buttons) do
- gpu.setForeground(0x000000)
- if button.depressed then
- button.depressed = button.depressed - 1
- if button.depressed == 0 then
- button.depressed = nil
- end
- end
- if button.condition == nil or button.condition() then
- centerColor = 0xBBBBBB
- highlightColor = 0xCCCCCC
- lowlightColor = 0x808080
- if button.depressed then
- centerColor = 0xAAAAAA
- highlightColor = 0x707070
- lowlightColor = 0xBBBBBB
- end
- gpu.setBackground(centerColor)
- gpu.fill(button.x, button.y, button.width, button.height, " ")
- if button.width > 1 and button.height > 1 then
- gpu.setBackground(lowlightColor)
- gpu.fill(button.x+1, button.y+button.height-1, button.width-1, 1, " ")
- gpu.fill(button.x+button.width-1, button.y, 1, button.height, " ")
- gpu.setBackground(highlightColor)
- gpu.fill(button.x, button.y, 1, button.height, " ")
- gpu.fill(button.x, button.y, button.width, 1, " ")
- end
- gpu.setBackground(centerColor)
- if button.textcolor then
- gpu.setForeground(button.textcolor)
- end
- term.setCursor(button.x + math.floor(button.width / 2 - #button.text / 2), button.y + math.floor(button.height / 2))
- term.write(button.text)
- end
- end
- gpu.setBackground(0x777777)
- gpu.setForeground(0x000000)
- end
- -- Write Relevant Values For CLI
- if term.isAvailable() and Mode == 3 then
- left_margin = 2
- spacing = 1
- values3 = {
- "Eq. Fusion Stage " .. burnStage,
- string.format("Max Fuel [nb]: %4.3f", (info.maxFuelConversion * 1000000)),
- string.format("Fuel Remaining [nb]: %4.3f", ((info.maxFuelConversion - info.fuelConversion) * 1000000)),
- string.format("Temperature Rise: %4.3f", tempAccel),
- string.format("Temp Resist for target temp %d (%d): %.2f", idealTemp, targetTemp50, targetTempResist),
- string.format("Temp expo for convLVL %.2f: %.2f", convLVL, targetTempExpo),
- string.format("Saturation needed for zero rise: %d (%3.2f%%)", targetSat, targetCoreSat*100),
- string.format("Error between current saturation and target saturation: %d\n", saturationError),
- string.format("Current field drain is %d RF/t", info.fieldDrainRate),
- string.format("Current temp drain factor for temp %d is %1.2f", info.temperature, tempDrainFactor),
- string.format("fieldNegPercent is %d", fieldNegPercent),
- string.format("Required input to counter field drain: %d RF/t\n", requiredInput),
- string.format("Field Deviation: " .. unicode.char(8776) .. deviation .. "%%"),
- string.format("Input Flux Gate: [" .. inputFlux.address .. "] Set To: " .. inputFlux.getFlow()),
- string.format("Output Flux Gate: [" .. outputFlux.address .. "] Set To: " .. outputFlux.getFlow())
- }
- for i, v in ipairs(values3) do
- term.setCursor(left_margin, i * spacing)
- term.write(v)
- end
- end
- -- print(drawGUI okay)
- end
- os.sleep(0.1)
- print("drawGUI thread exited")
- end
- print("GUI Loop Defined")
- -- Parse User Input
- function parseInput()
- print("Parser Start")
- while eventLoop do
- -- Wait for next tick, or manual shutdown
- event, id, op1, op2 = event.pull()
- if event == "interrupted" then
- eventLoop = false
- thread.current():join()
- elseif event == "touch" then
- -- Handle Button Presses
- x = op1
- y = op2
- for bname, button in pairs(buttons) do
- if (button.condition == nil or button.condition()) and x >= button.x and x <= button.x + button.width and y >= button.y and y <= button.y + button.height then
- button.action()
- button.depressed = 3
- end
- end
- end
- --print("parseInput okay")
- end
- print("parseInputThread exited")
- end
- print("Input Parsing Enabled")
- local primaryCalculationsThread = thread.create(primaryCalculations)
- local secondaryCalculationsThread = thread.create(secondaryCalculations)
- local drawGUIThread = thread.create(drawGUI)
- local parseInputThread = thread.create(parseInput)
- print("Threads Created")
- thread.waitForAny({primaryCalculationsThread, secondaryCalculationsThread, drawGUIThread, parseInputThread})
- --drawUI()
- eventLoop = false
- reactor.stopReactor()
- term.clear()
- term.setCursor(1,1)
- maxX, maxY = gpu.maxResolution()
- gpu.setResolution(maxX,maxY)
- print("Exited")
- ::fin::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement