Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local gpu = component.gpu
- local rs = component.redstone
- local modem = component.modem
- -- Ensure the correct path to ButtonAPI.lua and ProgressBarAPI.lua
- local ButtonAPI = require("button")
- local ProgressBarAPI = require("ProgressBarAPI")
- local Button = ButtonAPI
- local HandleClick = ButtonAPI.handleClick
- local SendCommand = ButtonAPI.sendCommand
- local ProgressBar = ProgressBarAPI.ProgressBar
- local RsAddress = "b1e4214b-ab41-44c3-938a-13d4cb71f66f"
- local BatchSize = 4000 -- 4 buckets
- local ScreenSize = {x = 160, y = 50}
- local Temp_1 = component.getPrimary("tank_controller")
- local Temp_2 = Temp_1.address
- -- UI Elements
- local Panels = {}
- Buttons = {}
- local ToggleStates = {["Heat Exchanger"] = false, ["Distillery"] = false}
- local CommandInProgress = false
- local Colors = {
- white = 0xffffff,
- orange = 0xff6600,
- magenta = 0xff00ff,
- lightblue = 0x0099ff,
- yellow = 0xffff00,
- lime = 0x00ff00,
- pink = 0xff3399,
- gray = 0x737373,
- lightgray = 0xa5a5a5,
- silver = 0xc0c0c0,
- cyan = 0x169c9d,
- purple = 0x8932b7,
- blue = 0x3c44a9,
- brown = 0x825432,
- green = 0x5d7c15,
- red = 0xb02e26,
- lightred = 0xffcccb,
- lightorange = 0xbd8817,
- black = 0x000000
- }
- -- Function to set the primary tank controller
- function SetPrimaryTankController()
- local currentPrimary = component.getPrimary("tank_controller")
- if currentPrimary.address ~= PrimerTankAddress then
- component.setPrimary("tank_controller", PrimerTankAddress)
- end
- end
- SetPrimaryTankController()
- -- This is a building with both a distiller and a heat exchanger
- local refinery = {
- heatExchanger = {
- isRunning = false,
- productionData = {
- ticksInOperation = 0,
- totalFluidsheated = 0,
- totalFluidsCooled = 0,
- fluidsProcessed = {
- oil = {cool = 0, hot = 0, searing = 0},
- mixedLightFuels = {cool = 0, hot = 0, searing = 0},
- denseOil = {cool = 0, hot = 0, searing = 0},
- denseFuel = {cool = 0, hot = 0, searing = 0},
- lightFuel = {cool = 0, hot = 0, searing = 0},
- gaseousFuel = {cool = 0, hot = 0, searing = 0},
- residue = {cool = 0, hot = 0, searing = 0}
- }
- },
- inputTank = {
- allowedFluids = {
- oil = {cool = true, hot = true, searing = false},
- mixedLightFuels = {cool = false, hot = true, searing = false},
- denseOil = {cool = false, hot = true, searing = true},
- denseFuel = {cool = false, hot = true, searing = true}
- },
- tankAddress = "53fecb07-0c2c-436b-8b2b-54e78dbd221c",
- side = 4
- },
- outputTank = {
- tankAddress = "88f8bbd9-d711-45bd-8299-6f26d463e7a0",
- side = 4
- },
- heatingMediumInputTank = {
- allowedFluids = {
- oil = {cool = true, hot = true, searing = false},
- mixedLightFuels = {cool = false, hot = true, searing = false},
- denseOil = {cool = false, hot = true, searing = true},
- denseFuel = {cool = false, hot = true, searing = true}
- },
- tankAddress = "88f8bbd9-d711-45bd-8299-6f26d463e7a0",
- side = 5
- },
- heatingMediumOutputTank = {
- worldPos = {},
- tankAddress = "53fecb07-0c2c-436b-8b2b-54e78dbd221c",
- side = 5
- },
- primerTank = {
- worldPos = {x = -370, y = -206, z = 68},
- tankAddress = "fda585ee-ebd3-4adf-a25c-928287641fd6",
- side = 1
- },
- controls = {
- enable = {rsSide = 2, bundleCableCannel = 1},
- enablePrimerTank = {rsSide = 5, bundleCableChannel = 2},
- enableVoidPrimer = {rsSide = 2, bundleCableChannel = 1}
- }
- },
- distilery = {
- isRunning = false,
- inputTank = {
- allowedFluids = {
- oil = {cool = false, hot = true, searing = false},
- mixedLightFuels = {cool = true, hot = false, searing = false},
- denseOil = {cool = false, hot = false, searing = true},
- },
- worldPos = {x = -361, y = -198, z = 69, facing = 3, capacity = 4000}
- },
- outputTank1 = {
- worldPos = {x = -361, y = -197, z = 69, facing = 5, capacity = 4000}
- },
- outputTank2 = {
- worldPos = {x = -361, y = -197, z = 69, facing = 4, capacity = 4000}
- },
- productionData = {
- ticksInOperation = 0,
- totalFluidsProcessed = 0,
- fluidsProcessed = {
- oil = {cool = 0, hot = 0, searing = 0},
- mixedLightFuels = {cool = 0, hot = 0, searing = 0},
- denseOil = {cool = 0, hot = 0, searing = 0}
- },
- fluidsProduced = {
- denseFuel = 0,
- lightFuel = 0,
- gaseousFuel = 0,
- residue = 0
- }
- },
- }
- }
- local storageTanks = {
- mixedLightFuelsTanks = {
- controllerAddress = "b8cc58b8-af0e-4873-b896-8597f4a4af6e",
- hot_MixedFuelsTank = {pos = {x = -363, y = -213, z = 73}, side = 4},
- cool_MixedFuelsTank = {pos = {x = -365, y = -213, z = 73}, side = 5},
- },
- refinedMixedLightFuels = {
- controllerAddress = "a447a51d-b80f-4bd2-b58a-12934791eb4e",
- cool_lightFuel = {pos = {x = -361, y = -213, z = 73}, side = 4},
- cool_gaseousFuel = {pos = {x = -359, y = -213, z = 73}, side = 5},
- cool_denseFuel = {pos = {x = -359, y = -213, z = 73}, side = 3}
- },
- denseFuels = {
- controllerAddress = "07403ada-4b52-4fc5-a250-f5d398230a09",
- hot_denseOil = {pos = {x = -361, y = -213, z = 73}, side = 4},
- searing_denseFuel = {pos = {x = -355, y = -213, z = 73}, side = 5},
- searing_residue = {pos = {x = -356, y = -214, z = 73}, side = 2}
- },
- }
- -- Path definitions for the robot
- local RobotPaths = {
- FromCoolOilToPrimer = {
- Tank = {pos = {x = -373, y = -199, z = 68}},
- PrimerTank = {pos = {x = -370, y = -206, z = 68}},
- direction = 2,
- path = {
- [1] = {forward = 8, turnRight = 1},
- [2] = {forward = 3, turnRight = 1},
- [3] = {forward = 2}
- }
- },
- FromPrimerToMixedLightFuelsHotTank = {
- PrimerTank = {pos = {x = -370, y = -206, z = 68}},
- HotMixedFuelsTank = {pos = {x = -363, y = -213, z = 73}},
- direction = 2,
- path = {
- [1] = {up = 5, forward = 8, turnRight = 1},
- [2] = {forward = 7, turnRight = 1}
- }
- },
- FromMixedLightFuelsHotTankToMediumInput = {
- MediumInputTank = {pos = {x = -366, y = -192, z = 71}},
- HotMixedFuelsTank = {pos = {x = -363, y = -213, z = 73}},
- direction = 2,
- path = {
- [1] = {up = 1, forward = 16, turnLeft = 1},
- [2] = {forward = 2, down = 2},
- [3] = {turnaround = 1, forward = 5, turnLeft = 1},
- [4] = {forward = 5, down = 1}
- }
- },
- FromMediumInputToMediumOutput = {
- MediumInputTank = {pos = {x = -366, y = -192, z = 71}},
- MediumOutputTank = {pos = {x = -366, y = -200, z = 71}},
- direction = 2,
- path = {
- [1] = {turnaround = 1, forward = 8}
- }
- },
- FromMediumInputToMixedLightFuelsCoolTank = {
- MediumInputTank = {pos = {x = -366, y = -192, z = 71}},
- CoolMixedFuelsTank = {pos = {x = -365, y = -213, z = 73}},
- direction = 2,
- path = {
- [1] = {forward = 13, turnRight = 1},
- [2] = {up = 2, forward = 4, turnRight = 1}
- }
- },
- FromMixedLightFuelsCoolTankToDistillerInput = {
- CoolMixedFuelsTank = {pos = {x = -365, y = -213, z = 73}},
- DistillerInput = {pos = {x = -361, y = -198, z = 69}},
- direction = 3,
- path = {
- [1] = {forward = 11, up = 1},
- [2] = {forward = 4, down = 5, turnaround = 1},
- [3] = {forward = 1, turnRight = 1},
- [4] = {forward = 1, turnRight = 1}
- }
- }
- }
- -- Initialize the screen
- function InitScreen()
- gpu.setResolution(ScreenSize.x, ScreenSize.y)
- gpu.fill(1, 1, ScreenSize.x, ScreenSize.y, " ")
- end
- -- Function to create a panel
- function CreatePanel(x, y, width, height, title)
- table.insert(Panels, {x = x, y = y, width = width, height = height, title = title})
- DrawPanel(#Panels)
- end
- -- Function to draw a panel
- function DrawPanel(index)
- local panel = Panels[index]
- gpu.setBackground(0x333333)
- gpu.fill(panel.x, panel.y, panel.width, panel.height, " ")
- gpu.setBackground(0x000000)
- gpu.set(panel.x + 1, panel.y, panel.title)
- end
- -- Function to create a button using Button API
- function CreateButton(label, x, y, width, height, onClick, bgColor, fgColor)
- local button = Button.new(label, x, y, width, height, onClick, bgColor, fgColor)
- button:draw()
- table.insert(Buttons, button)
- end
- function GetTankData(tank, side)
- local a = component.getPrimary("tank_controller")
- if tank == a.address then
- local theTank = component.tank_controller
- local fluidData = theTank.getFluidInTank(side)
- return fluidData[1]
- else
- local theTank = component.proxy(tank)
- local fluidData = theTank.getFluidInTank(side)
- return fluidData[1]
- end
- end
- -- Function to update heat exchanger production data
- function UpdateHeatExchangerProductionData(x, y)
- local data = refinery.heatExchanger.productionData
- gpu.set(x + 1, y + 1, "Ticks in Operation: " .. data.ticksInOperation)
- gpu.set(x + 1, y + 2, "Total Fluids Heated: " .. data.totalFluidsheated .. "mB")
- gpu.set(x + 1, y + 3, "Total Fluids Cooled: " .. data.totalFluidsCooled .. "mB")
- end
- -- Function to update distillery production data
- function UpdateDistilleryProductionData(x, y)
- local data = refinery.distilery.productionData
- gpu.set(x + 1, y + 1, "Ticks in Operation: " .. data.ticksInOperation)
- gpu.set(x + 1, y + 2, "Total Fluids Processed: " .. data.totalFluidsProcessed .. "mB")
- gpu.set(x + 1, y + 3, "Fluids Produced:")
- gpu.set(x + 2, y + 4, "Dense Fuel: " .. data.fluidsProduced.denseFuel .. "mB")
- gpu.set(x + 2, y + 5, "Light Fuel: " .. data.fluidsProduced.lightFuel .. "mB")
- gpu.set(x + 2, y + 6, "Gaseous Fuel: " .. data.fluidsProduced.gaseousFuel .. "mB")
- gpu.set(x + 2, y + 7, "Residue: " .. data.fluidsProduced.residue .. "mB")
- end
- -- Function to draw a simple real-time graph (placeholder)
- function DrawGraph(x, y, title)
- gpu.setBackground(0x000000)
- gpu.fill(x + 1, y + 1, 48, 8, " ") -- Clear graph area
- -- Example of drawing a simple graph (replace with actual graph logic)
- gpu.setForeground(0x00FF00)
- for i = 1, 48 do
- gpu.set(x + i, y + math.random(1, 8), "*")
- end
- gpu.setForeground(0xFFFFFF)
- end
- -- Toggle function for heat exchanger production data panel
- function ToggleHeatExchangerPanel()
- ToggleStates["Heat Exchanger"] = not ToggleStates["Heat Exchanger"]
- end
- -- Toggle function for distillery production data panel
- function ToggleDistilleryPanel()
- ToggleStates["Distillery"] = not ToggleStates["Distillery"]
- end
- -- Example button callbacks
- function StartHeatExchanger()
- -- Add the functionality to start the heat exchanger
- end
- function LoadPrimerTank()
- end
- function CreatePrimerTankProgBar()
- local tankData = GetTankData(refinery.heatExchanger.primerTank.tankAddress, refinery.heatExchanger.primerTank.side)
- local progBar = ProgressBarAPI:new(5, 25, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "primer tank", "below")
- return progBar
- end
- function CreateCoolMixedLightFuelsProBar()
- local tankData = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.cool_MixedFuelsTank.side)
- local ProgBar = ProgressBarAPI:new(5, 28, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "mixed fuels hot", "below")
- return ProgBar
- end
- function CreateHotMixedLightFuelsProBar()
- local tankData = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.cool_MixedFuelsTank.side)
- local ProgBar = ProgressBarAPI:new(5, 31, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "mixed fuels cool", "below")
- return ProgBar
- end
- function CreateCoolLightFuelProBar()
- local tankData = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_lightFuel.side)
- local ProgBar = ProgressBarAPI:new(5, 34, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "light fuel cool", "below")
- return ProgBar
- end
- function CreateCoolGaseousFuelProBar()
- local tankData = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_gaseousFuel.side)
- local ProgBar = ProgressBarAPI:new(5, 37, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "gaseous fuel cool", "below")
- return ProgBar
- end
- function CreateCoolDenseFuelProBar()
- local tankData = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_gaseousFuel.side)
- local ProgBar = ProgressBarAPI:new(5, 40, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "dense fuel cool", "below")
- return ProgBar
- end
- function CreateHotDenseOilProBar()
- local tankData = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.hot_denseOil.side)
- local ProgBar = ProgressBarAPI:new(5, 43, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "dense oil hot", "below")
- return ProgBar
- end
- function CreateSearingDenseFuelProBar()
- local tankData = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.searing_denseFuel.side)
- local ProgBar = ProgressBarAPI:new(5, 46, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "dense fuel searing", "below")
- return ProgBar
- end
- function OpenComms()
- modem.open(123)
- end
- -- Initialize the screen
- InitScreen()
- CreatePanel(2, 2, 50, 10, "Heat Exchanger")
- CreatePanel(2, 14, 50, 10, "Distillery")
- CreatePanel(60, 14, 50, 10, "Heat Exchanger Production Data")
- CreatePanel(60, 26, 50, 10, "Distillery Production Data")
- CreateButton("Start Heat Exchanger", 60, 2, 22, 3, StartHeatExchanger)
- CreateButton("Load Primer Tank", 60, 6, 20, 3, LoadPrimerTank)
- CreateButton("Toggle HX Panel", 60, 38, 20, 3, ToggleHeatExchangerPanel) -- Button for toggling heat exchanger panel
- CreateButton("Toggle Dist Panel", 60, 42, 20, 3, ToggleDistilleryPanel) -- Button for toggling distillery panel
- ProgBar_PrimerTank = CreatePrimerTankProgBar()
- ProgBar_HotMixedLightFuels = CreateHotMixedLightFuelsProBar()
- ProgBar_CoolMixedLightFuels = CreateCoolMixedLightFuelsProBar()
- ProgBar_CoolLightFuel = CreateCoolLightFuelProBar()
- ProgBar_CoolGaseousFuel = CreateCoolGaseousFuelProBar()
- ProgBar_CoolDenseFuel = CreateCoolDenseFuelProBar()
- ProgBar_HotDenseOil = CreateHotDenseOilProBar()
- ProgBar_SearingDenseFuel = CreateSearingDenseFuelProBar()
- function ButtonCheck(buttonTable)
- for i = 1, #buttonTable do
- local eventData = {event.pull(0.01)}
- if eventData[1] == "touch" then
- if eventData[3] >= buttonTable[i].x and eventData[3] < buttonTable[i].x + buttonTable[i].width and eventData[4] >= buttonTable[i].y and eventData[4] < buttonTable[i].y + buttonTable[i].height then
- buttonTable[i].onClick()
- end
- end
- end
- end
- while true do
- local temp_3 = GetTankData(refinery.heatExchanger.primerTank.tankAddress, refinery.heatExchanger.primerTank.side)
- local temp_4 = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.cool_MixedFuelsTank.side)
- local temp_5 = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.hot_MixedFuelsTank.side)
- local temp_6 = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_lightFuel.side)
- local temp_7 = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_gaseousFuel.side)
- local temp_8 = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_denseFuel.side)
- local temp_9 = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.hot_denseOil.side)
- local temp_10 = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.searing_denseFuel.side)
- ProgBar_PrimerTank:update(temp_3.amount)
- ProgBar_HotMixedLightFuels:update(temp_4.amount)
- ProgBar_CoolMixedLightFuels:update(temp_5.amount)
- ProgBar_CoolLightFuel:update(temp_6.amount)
- ProgBar_CoolGaseousFuel:update(temp_7.amount)
- ProgBar_CoolDenseFuel:update(temp_8.amount)
- ProgBar_HotDenseOil:update(temp_9.amount)
- ProgBar_SearingDenseFuel:update(temp_10.amount)
- ButtonCheck(Buttons)
- --os.sleep(0.01)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement