Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bridge = peripheral.wrap("left")
- net = peripheral.wrap("back")
- width = 120
- shutting = false
- ready = false
- restarting = false
- storageUnits = {
- {
- ["id"] = "virtual",
- ["name"] = "All Power (Test)",
- ["type"] = "all_power",
- },
- {
- ["id"] = "batbox_11",
- ["name"] = "Power One:",
- ["type"] = "power",
- },
- {
- ["id"] = "batbox_12",
- ["name"] = "Power Two:",
- ["type"] = "power",
- },
- {
- ["id"] = "batbox_13",
- ["name"] = "Power Three:",
- ["type"] = "power",
- },
- {
- ["id"] = "batbox_14",
- ["name"] = "Power One:",
- ["type"] = "power",
- },
- {
- ["id"] = "batbox_15",
- ["name"] = "Power Two:",
- ["type"] = "power",
- },
- {
- ["id"] = "batbox_16",
- ["name"] = "Power Three:",
- ["type"] = "power",
- },
- {
- ["id"] = "LogisticsPowerJunction_2",
- ["name"] = "Logistics Pipes Backup",
- ["type"] = "log_power",
- },
- {
- ["id"] = "me_controller_4",
- ["name"] = "ME/AE Total Storage",
- ["type"] = "me_storage",
- },
- }
- gColors = {}
- gColors.red = 0xff3333
- gColors.blue = 0x7dd2e4
- gColors.yellow = 0xffff4d
- gColors.green = 0x4dff4d
- gColors.gray = 0xe0e0e0
- gColors.textGray = 0x818181
- gColors.text = 0x5a5a5a
- gColors.rain = 0x2e679f
- gColors.plain = 0x000000
- gColors.black = 0x000000
- function shutdown(name)
- if name == "controller" then
- shutting = true
- end
- if name == "glasses" then
- ready = true
- end
- if name == "get" then
- return shutting
- end
- if name == "restart" then
- restarting = true
- shutting = true
- end
- if shutting == true then
- if restarting == true then
- if ready == true then
- os.reboot()
- end
- end
- if ready == true then
- os.shutdown()
- end
- end
- end
- function glass()
- --Init Area
- bridge.clear()
- offset = 1
- startup = bridge.addText(4, 4, "System Starting Up...", gColors.red)
- for key, storageUnit in pairs(storageUnits) do
- --[[
- if storageUnit.type == "power" then
- pxOffset = offset * 20
- storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], gColors.yellow)
- storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, gColors.red, 0.9)
- storageUnit["bar"].setZIndex(2)
- storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, gColors.plain, 0.5)
- offset = offset + 1
- end
- ]]--
- if storageUnit.type == "me_storage" then
- pxOffset = offset * 20
- storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], gColors.yellow)
- storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, gColors.red, 0.9)
- storageUnit["bar"].setZIndex(2)
- storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, gColors.plain, 0.5)
- offset = offset + 1
- end
- if storageUnit.type == "log_power" then
- pxOffset = offset * 20
- storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], gColors.yellow)
- storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, gColors.red, 0.9)
- storageUnit["bar"].setZIndex(2)
- storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, gColors.plain, 0.5)
- offset = offset + 1
- end
- if storageUnit.type == "all_power" then
- pxOffset = offset * 20
- storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], gColors.yellow)
- storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, gColors.red, 0.9)
- storageUnit["bar"].setZIndex(2)
- storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, gColors.plain, 0.5)
- offset = offset + 1
- end
- end
- sleep(0.5)
- sleep(1)
- startup.delete()
- startup = bridge.addText(4, 4, "System Ready.", gColors.green)
- sleep(1)
- --Init Over
- while true do
- time = os.time()
- time = textutils.formatTime(time, false)
- startup.setText("System Running: "..time)
- if shutdown("get") == true then
- bridge.clear()
- bridge.addText(4, 4, "Shutting Down!!!", gColors.red)
- sleep(2)
- bridge.clear()
- shutdown("glasses")
- sleep(99)
- end
- for i=#storageUnits,1,-1 do
- storageUnit = storageUnits[i]
- --[[
- if storageUnit.type == "power" then
- if net.isPresentRemote(storageUnit["id"]) then
- capacity = net.callRemote(storageUnit["id"], "getCapacity")
- amount = net.callRemote(storageUnit["id"], "getStored")
- storageUnit["bar"].setWidth(width / capacity * amount)
- else
- storageUnit["bar"].delete()
- storageUnit["bg"].delete()
- storageUnit["label"].delete()
- table.remove(storageUnits, i)
- end
- end
- ]]--
- if storageUnit.type == "me_storage" then
- if net.isPresentRemote(storageUnit["id"]) then
- capacity = net.callRemote(storageUnit["id"], "getTotalBytes")
- amount = net.callRemote(storageUnit["id"], "getUsedBytes")
- storageUnit["bar"].setWidth(width / capacity * amount)
- else
- storageUnit["bar"].delete()
- storageUnit["bg"].delete()
- storageUnit["label"].delete()
- table.remove(storageUnits, i)
- end
- end
- if storageUnit.type == "log_power" then
- if net.isPresentRemote(storageUnit["id"]) then
- capacity = 2000000
- amount = net.callRemote(storageUnit["id"], "getPowerLevel")
- storageUnit["bar"].setWidth(width / capacity * amount)
- else
- storageUnit["bar"].delete()
- storageUnit["bg"].delete()
- storageUnit["label"].delete()
- table.remove(storageUnits, i)
- end
- end
- if storageUnit.type == "all_power" then
- capacity = 0
- amount = 0
- backup = storageUnit
- for i=#storageUnits,1,-1 do
- storageUnit = storageUnits[i]
- if storageUnit.type == "power" then
- capacity = capacity + net.callRemote(storageUnit["id"], "getCapacity")
- amount = amount + net.callRemote(storageUnit["id"], "getStored")
- end
- end
- storageUnit = backup
- storageUnit["bar"].setWidth(width / capacity * amount)
- end
- end
- sleep(0.2)
- end
- end
- function shell()
- term.clear()
- term.setCursorPos(1,1)
- print("Monitor System Started.")
- while true do
- inp = read()
- if inp == "shutdown" then
- shutdown("controller")
- end
- if inp == "restart" or "update" then
- shutdown("restart")
- end
- if inp == "ping" then
- print("pong")
- end
- end
- end
- parallel.waitForAll(glass, shell)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement