Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local width = 60
- local refreshrate = 0.1
- local bridge = peripheral.wrap("left")
- local net = peripheral.wrap("right")
- local gainColor = 0x00DD00
- local steadyColor = 0x000000
- local lossColor = 0xDD0000
- bridge.clear()
- local storageUnits = {
- { ["id"] = "", ["name"] = "Total: 0%", ["lastValue"] = 0 },
- { ["id"] = "batbox_6", ["name"] = "#1", ["lastValue"] = 0 },
- { ["id"] = "batbox_7", ["name"] = "#2", ["lastValue"] = 0 },
- { ["id"] = "batbox_8", ["name"] = "#3", ["lastValue"] = 0 },
- { ["id"] = "batbox_9", ["name"] = "#4", ["lastValue"] = 0 },
- { ["id"] = "batbox_10", ["name"] = "#5", ["lastValue"] = 0 },
- { ["id"] = "batbox_11", ["name"] = "#6", ["lastValue"] = 0 },
- { ["id"] = "batbox_12", ["name"] = "#7", ["lastValue"] = 0 },
- }
- local offset = 7
- for key, storageUnit in pairs(storageUnits) do
- pxOffset = (offset * 10) + 5
- storageUnit["label"] = bridge.addText(width+8, pxOffset, storageUnit["name"], steadyColor)
- storageUnit["bar"] = bridge.addBox(5, pxOffset+1, 0, 5, 0xCC0000, 0.9)
- storageUnit["bar"].setZIndex(2)
- storageUnit["bg"] = bridge.addBox(4, pxOffset, width+2, 7, 0x000000, 0.5)
- offset = offset + 1
- end
- function roundNum(val, decimal)
- if (decimal) then
- return math.floor(((val * 10^decimal) + 0.5) / (10^decimal))
- else
- return math.floor(val+0.5)
- end
- end
- while true do
- local totalCapacity = 0
- local totalStored = 0
- local totalPercent = 0
- for i=#storageUnits,1,-1 do
- storageUnit = storageUnits[i]
- if storageUnit["id"] == "" then
- if totalCapacity > 0 then
- storageUnit["bar"].setWidth(width / totalCapacity * totalStored)
- storageUnit["label"].setText("Total: "..roundNum(totalPercent, 2).."% ("..(totalStored - storageUnit["lastValue"])..")")
- if storageUnit["lastValue"] > totalStored then
- storageUnit["label"].setColor(lossColor)
- elseif storageUnit["lastValue"] < totalStored then
- storageUnit["label"].setColor(gainColor)
- elseif storageUnit["lastValue"] == totalStored then
- storageUnit["label"].setColor(steadyColor)
- end
- storageUnit["lastValue"] = totalStored
- end
- elseif net.isPresentRemote(storageUnit["id"]) then
- capacity = net.callRemote(storageUnit["id"], "getCapacity")
- amount = net.callRemote(storageUnit["id"], "getStored")
- storageUnit["bar"].setWidth(width / capacity * amount)
- totalCapacity = totalCapacity + capacity
- totalStored = totalStored + amount
- if totalCapacity > 0 then
- totalPercent = (totalStored / totalCapacity) * 100
- end
- storageUnit["label"].setText(storageUnit["name"]..": "..roundNum(totalPercent, 2).."% ("..(amount - storageUnit["lastValue"])..")")
- if storageUnit["lastValue"] > amount then
- storageUnit["label"].setColor(lossColor)
- elseif storageUnit["lastValue"] < amount then
- storageUnit["label"].setColor(gainColor)
- elseif storageUnit["lastValue"] == amount then
- storageUnit["label"].setColor(steadyColor)
- end
- storageUnit["lastValue"] = amount
- else
- storageUnit["bar"].delete()
- storageUnit["bg"].delete()
- storageUnit["label"].delete()
- table.remove(storageUnits, i)
- end
- end
- if totalPercent < 80 then
- rs.setOutput("back", false) -- Connect EU-Splitter cable
- end
- if totalPercent >= 100 then
- rs.setOutput("back", true) -- Disconnect EU-Splitter cable
- end
- sleep(refreshrate)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement