Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Side the modem is attached.
- -- Valid: "left", "right", "front", "back", "top", "bottom"
- local peripheralModem = peripheral.wrap("back")
- -- Side the monitor is attached
- local mon = peripheral.wrap("top")
- -- Side the rednet cable is attached
- local rednetSide = "bottom"
- -- Set up classes
- -- Batbox object
- local batbox = {}
- batbox.new = function(id)
- -- Class local variables
- local self = {}
- self.id = id
- self.name = self.id
- -- Getters
- self.getMaxEnergyOutput = function()
- return peripheralModem.callRemote(self.id, "getMaxEnergyOutput")
- end
- self.getCapacity = function()
- return peripheralModem.callRemote(self.id, "getCapacity")
- end
- self.getStored = function()
- return peripheralModem.callRemote(self.id, "getStored")
- end
- self.getOutput = function()
- return peripheralModem.callRemote(self.id, "getOutput")
- end
- self.getName = function()
- return self.name
- end
- self.getId = function()
- return self.id
- end
- -- Setters
- self.setName = function(newName)
- self.name = newName
- end
- -- Other methods
- self.getPercent = function()
- return ((self.getStored() / self.getCapacity()) * 100 )
- end
- self.show = function()
- mon.write(self.getName())
- local x, y = mon.getCursorPos()
- mon.setCursorPos(4, y + 1)
- mon.write("EU: "..self.getStored().." / "..self.getCapacity()..". "..self.getPercent().."%")
- mon.setCursorPos(1, y + 3)
- end
- --#### PREVENT READ AND WRITE ACCESS TO THE RETURNED TABLE
- local mt = self
- -- PREVENT WRITE ACCESS AND ABORT APPROPRIATELY
- mt.__newindex = function(table, key, value)
- local msg = string.format("%s %s %s %s %s",
- "Attempt to illegally set Batbox object key",
- tostring(key),
- "to value",
- tostring(value),
- ", aborting...\n\n"
- )
- io.stderr:write(msg)
- os.exit(1)
- end
- -- PREVENT READ ACCESS AND ABORT APPROPRIATELY
- mt.__index = function(table, key)
- if type(key) ~= "function" then
- io.stderr:write("Attempt to illegally read attribute " ..
- tostring(key) .. " from Batbox object, aborting...\n\n")
- os.exit(1)
- end
- end
- -- WRITE NEW __index AND __newindex TO METATABLE
- setmetatable(self, mt)
- return self
- end
- -- Nuclear reactor object
- local reactor = {}
- reactor.new = function(id)
- -- Class local variables
- local self = {}
- self.id = id
- self.name = id
- -- Getters
- self.getInvName = function()
- return peripheralModem.callRemote(self.id, "getInvName")
- end
- self.getStackInSlot = function(slotNumber)
- return peripheralModem.callRemote(self.id, "getStackInSlot", slotNumber)
- end
- self.getSizeInventory = function()
- return peripheralModem.callRemote(self.id, "getSizeInventory")
- end
- self.getOutput = function()
- return peripheralModem.callRemote(self.id, "getOutput")
- end
- self.getHeat = function()
- return peripheralModem.callRemote(self.id, "getHeat")
- end
- self.getMaxHeat = function()
- return peripheralModem.callRemote(self.id, "getMaxHeat")
- end
- self.getName = function()
- return self.name
- end
- self.getId = function()
- return self.id
- end
- -- Setters
- self.setName = function(newName)
- self.name = newName
- end
- -- Other methods
- self.getHeatPercent = function()
- return ((self.getHeat() / self.getMaxHeat()) *100 )
- end
- self.show = function()
- mon.write(self.getName())
- local x, y = mon.getCursorPos()
- mon.setCursorPos(4, y + 1)
- mon.write("Heat: "..self.getHeat().." / "..self.getMaxHeat()..". "..self.getPercent().."%")
- mon.setCursorPos(1, y + 3)
- end
- --#### PREVENT READ AND WRITE ACCESS TO THE RETURNED TABLE
- local mt = self
- -- PREVENT WRITE ACCESS AND ABORT APPROPRIATELY
- mt.__newindex = function(table, key, value)
- local msg = string.format("%s %s %s %s %s",
- "Attempt to illegally set Reactor object key",
- tostring(key),
- "to value",
- tostring(value),
- ", aborting...\n\n"
- )
- io.stderr:write(msg)
- os.exit(1)
- end
- -- PREVENT READ ACCESS AND ABORT APPROPRIATELY
- mt.__index = function(table, key)
- if type(key) ~= "function" then
- io.stderr:write("Attempt to illegally read attribute " ..
- tostring(key) .. " from Reactor object, aborting...\n\n")
- os.exit(1)
- end
- end
- -- WRITE NEW __index AND __newindex TO METATABLE
- setmetatable(self, mt)
- return self
- end
- -- Program
- -- List of the connected peripherals matching the supported types.
- local reactors = {}
- local batboxes = {}
- for k, v in pairs(peripheralModem.getNamesRemote()) do
- local peripheralType = peripheralModem.getTypeRemote(v)
- if peripheralType == "batbox" then
- v = batbox.new(v)
- table.insert(batboxes, v)
- elseif peripheralType == "reactor_chamber" or peripheralType == "reactor" then
- v = reactor.new(v)
- table.insert(reactors, v)
- end
- end
- -- Make the text scale smaller.
- mon.setTextScale(0.5)
- -- Main program loop
- while true do
- mon.clear()
- mon.setCursorPos(1,1)
- local totalStored = 0
- local totalCapacity = 0
- -- Write out the batbox info
- for k, v in pairs(batboxes) do
- v.show()
- end
- -- mon.write("Total storage percentage: "..((totalStored / totalCapacity) * 100).."%")
- -- Write out the reactor info
- for k, v in pairs(reactors) do
- v.show()
- end
- -- Throttle the monitor updates
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement