Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- API designed for implementing more advanced colored wire functions.
- -- v1.1.1
- --------------------------------------------------
- WireTable = {}
- WireTable.register = function (self, side, color, name)
- if self[name] then
- print('Wire name already taken.')
- return false
- else
- self[name] = {}
- self[name].side, self[name].color = side, color
- self[name].on = function () rs.setBundledOutput(self[name].side, colors.combine(rs.getBundledOutput(self[name].side), self[name].color)) return true end
- self[name].off = function () rs.setBundledOutput(self[name].side, colors.subtract(rs.getBundledOutput(self[name].side), self[name].color)) return true end
- self[name].switch = function () if rs.testBundledInput(self[name].side, self[name].color) then self[name].off() else self[name].on() end return true end
- return true
- end
- end
- WireTable.unregister = function (self, name)
- if not self[name] then
- print('This wire doesn\'t exist')
- return false
- else
- self[name] = nil
- return true
- end
- end
- WireTable.callOnAll = function (self, wireMethod)
- for _, wireTable in pairs(self) do
- wireTable[wireMethod]()
- end
- return true
- end
- WireTable.onAll = function(self)
- return self:callOnAll('on')
- end
- WireTable.offAll = function(self)
- return self:callOnAll('off')
- end
- WireTable.switchAll = function(self)
- return self:callOnAll('switch')
- end
- WireTable.new = function ()
- newTable = setmetatable({}, WireTable)
- return newTable
- end
- WireTable.__index = WireTable
- setmetatable(WireTable, {__call = WireTable.new})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement