Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MonitorSide = "top"
- GlassesSide = "left"
- BackupGeneratorSide = "bottom"
- Monitor1 = peripheral.wrap("monitor_3")
- Monitor2 = peripheral.wrap("monitor_4")
- Glasses = peripheral.wrap(GlassesSide)
- GlassesLengthMultiplier = 5
- GlassesXMultiplier = 5
- GlassesYMultiplier = 7
- EmergencyActivationPercentage = 100
- cell1 = peripheral.wrap("cofh_thermalexpansion_energycell_0")
- cell2 = peripheral.wrap("cofh_thermalexpansion_energycell_1")
- cell3 = peripheral.wrap("cofh_thermalexpansion_energycell_2")
- cell4 = peripheral.wrap("cofh_thermalexpansion_energycell_3")
- cell5 = peripheral.wrap("cofh_thermalexpansion_energycell_4")
- cell6 = peripheral.wrap("cofh_thermalexpansion_energycell_5")
- function GetHexFromColour(clr)
- local colourOut = 0xCC4C4C --red
- if (clr == colours.white) then colourOut = 0xFFFFFF end
- if (clr == colours.orange) then colourOut = 0xF2B233 end
- if (clr == colours.yellow) then colourOut = 0xDEDE6C end
- if (clr == colours.green) then colourOut = 0x57A64E end
- if (clr == colours.cyan) then colourOut = 0x4C99B2 end
- return colourOut;
- end
- function GetColourFromPercent(percentage)
- local colourOut = colours.red
- if (percentage > 15) then colourOut = colours.orange end
- if (percentage > 45) then colourOut = colours.yellow end
- if (percentage > 70) then colourOut = colours.green end
- if (percentage > 90) then colourOut = colours.cyan end
- return colourOut
- end
- function ClearScreens()
- Monitor1.setTextColor(colours.black)
- Monitor1.setBackgroundColor(colours.black)
- Monitor1.clear()
- Monitor1.setCursorPos(1,1)
- Monitor2.setTextColor(colours.black)
- Monitor2.setBackgroundColor(colours.black)
- Monitor2.clear()
- Monitor2.setCursorPos(1,1)
- Glasses.clear()
- end
- function DrawText(xPos, yPos, text, textColour, backgroundColour)
- Monitor1.setBackgroundColor(backgroundColour)
- Monitor1.setTextColor(textColour)
- Monitor1.setCursorPos(xPos,yPos)
- Monitor1.write(text)
- Monitor2.setBackgroundColor(backgroundColour)
- Monitor2.setTextColor(textColour)
- Monitor2.setCursorPos(xPos,yPos)
- Monitor2.write(text)
- Glasses.addText(xPos * GlassesXMultiplier, yPos * GlassesYMultiplier, text, GetHexFromColour(textColour))
- end
- function DrawLine(xPos, yPos, lineLength, colour)
- Monitor1.setBackgroundColor(colour)
- Monitor1.setTextColor(colour)
- Monitor1.setCursorPos(xPos,yPos)
- Monitor1.write(string.rep(" ", lineLength))
- Monitor2.setBackgroundColor(colour)
- Monitor2.setTextColor(colour)
- Monitor2.setCursorPos(xPos,yPos)
- Monitor2.write(string.rep(" ", lineLength))
- Glasses.addBox(xPos * GlassesXMultiplier, yPos * GlassesYMultiplier, lineLength * GlassesLengthMultiplier, 5, GetHexFromColour(colour), 1)
- end
- function ProgressBar(xPos, yPos, barLength, value, maxValue, backgroundColour, progressColour)
- DrawLine(xPos, yPos, barLength, backgroundColour) --backgoround bar
- local barSize = math.floor((value/maxValue) * barLength)
- DrawLine(xPos, yPos, barSize, progressColour) --progress so far
- end
- function DrawPowerBar(monitorX, yPos, cellName, cellEnergy, cellMaxEnergy, cellPercent, barColour)
- DrawText(3, yPos, cellName, colours.white, colours.black)
- ProgressBar(10, yPos, monitorX - 15, cellEnergy, cellMaxEnergy, barColour, GetColourFromPercent(cellPercent))
- DrawText(monitorX - 4, yPos, cellPercent .. "%", colours.white, colours.black)
- end
- function GetCellBarColour(cellEnergyPercent)
- if (cellEnergyPercent == 0) then
- return colours.red
- else
- return colours.grey
- end
- end
- function FetchAndRedraw()
- Monitor1.setTextScale(1)
- Monitor2.setTextScale(1)
- local monX, monY = Monitor1.getSize()
- local cell1Energy = cell1.getEnergyStored("unknown")
- local cell2Energy = cell2.getEnergyStored("unknown")
- local cell3Energy = cell3.getEnergyStored("unknown")
- local cell4Energy = cell4.getEnergyStored("unknown")
- local cell5Energy = cell5.getEnergyStored("unknown")
- local cell6Energy = cell6.getEnergyStored("unknown")
- local cell1MaxEnergy = cell1.getMaxEnergyStored("unknown")
- local cell2MaxEnergy = cell2.getMaxEnergyStored("unknown")
- local cell3MaxEnergy = cell3.getMaxEnergyStored("unknown")
- local cell4MaxEnergy = cell4.getMaxEnergyStored("unknown")
- local cell5MaxEnergy = cell5.getMaxEnergyStored("unknown")
- local cell6MaxEnergy = cell6.getMaxEnergyStored("unknown")
- local cell1Percent = math.floor((cell1Energy / cell1MaxEnergy) * 100)
- local cell2Percent = math.floor((cell2Energy / cell2MaxEnergy) * 100)
- local cell3Percent = math.floor((cell3Energy / cell3MaxEnergy) * 100)
- local cell4Percent = math.floor((cell4Energy / cell4MaxEnergy) * 100)
- local cell5Percent = math.floor((cell5Energy / cell5MaxEnergy) * 100)
- local cell6Percent = math.floor((cell6Energy / cell6MaxEnergy) * 100)
- local totalEnergyPercentage = cell1Percent + cell2Percent + cell3Percent + cell4Percent + cell5Percent + cell6Percent
- local shouldEmergencyPowerBeOn = totalEnergyPercentage < EmergencyActivationPercentage
- ClearScreens()
- DrawPowerBar(monX, 2, "Cell 1", cell1Energy, cell1MaxEnergy, cell1Percent, GetCellBarColour(cell1Percent))
- DrawPowerBar(monX, 4, "Cell 2", cell2Energy, cell2MaxEnergy, cell2Percent, GetCellBarColour(cell2Percent))
- DrawPowerBar(monX, 6, "Cell 3", cell3Energy, cell3MaxEnergy, cell3Percent, GetCellBarColour(cell3Percent))
- DrawPowerBar(monX, 8, "Cell 4", cell4Energy, cell4MaxEnergy, cell4Percent, GetCellBarColour(cell4Percent))
- DrawPowerBar(monX, 10, "Cell 5", cell5Energy, cell5MaxEnergy, cell5Percent, GetCellBarColour(cell5Percent))
- DrawPowerBar(monX, 12, "Cell 6", cell6Energy, cell6MaxEnergy, cell6Percent, GetCellBarColour(cell6Percent))
- DrawText(3, 16, "Emergency Power", colours.white, colours.black)
- if (shouldEmergencyPowerBeOn) then
- redstone.setOutput(BackupGeneratorSide, true)
- DrawText(3, 18, "ONLINE", colours.white, colours.green)
- else
- redstone.setOutput(BackupGeneratorSide, false)
- DrawText(3, 18, "OFFLINE", colours.white, colours.red)
- end
- end
- while true do
- FetchAndRedraw()
- os.sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement