Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# cableBuddy 1.0.05 - a basic bundled cable API by Dog
- --# pastebin: Sy4zgkXS
- --# For instructions and documentation visit http://www.computercraft.info/forums2/index.php?/topic/28274-cablebuddy-a-basic-bundled-cable-api/
- local validColors = { [1] = true; [2] = true; [4] = true; [8] = true; [16] = true; [32] = true; [64] = true; [128] = true; [256] = true; [512] = true; [1024] = true; [2048] = true; [4096] = true; [8192] = true; [16384] = true, [32768] = true; }
- local validSides = { top = true; bottom = true; left = true; right = true; front = true; back = true; }
- local cable = {
- set = function(...)
- local cbCommands, side, color, newColor = { ... }
- for i = 1, #cbCommands, 2 do
- side = cbCommands[i]
- if type(side) == "string" and validSides[side] then
- color = cbCommands[i + 1]
- if type(color) == "number" then
- if validColors[color] then
- newColor = color
- else
- newColor = 0
- for colorValue in pairs(validColors) do
- if colors.test(color, colorValue) then
- newColor = colors.combine(newColor, colorValue)
- end
- end
- end
- if newColor == color then
- rs.setBundledOutput(side, color)
- end
- end
- end
- end
- end;
- add = function(...)
- local cbCommands, side, color, newColor = { ... }
- for i = 1, #cbCommands do
- side = cbCommands[i]
- if type(side) == "string" and validSides[side] then
- for j = i + 1, #cbCommands do
- color = cbCommands[j]
- if type(color) == "number" then
- if validColors[color] then
- newColor = color
- else
- newColor = 0
- for colorValue in pairs(validColors) do
- if colors.test(color, colorValue) then
- newColor = colors.combine(newColor, colorValue)
- end
- end
- end
- if newColor == color then
- rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
- end
- else
- break
- end
- end
- end
- end
- end;
- remove = function(...)
- local cbCommands, side, color, newColor = { ... }
- for i = 1, #cbCommands do
- side = cbCommands[i]
- if type(side) == "string" and validSides[side] then
- for j = i + 1, #cbCommands do
- color = cbCommands[j]
- if type(color) == "number" then
- if validColors[color] then
- newColor = color
- else
- newColor = 0
- for colorValue in pairs(validColors) do
- if colors.test(color, colorValue) then
- newColor = colors.combine(newColor, colorValue)
- end
- end
- end
- if newColor == color then
- rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
- end
- else
- break
- end
- end
- end
- end
- end;
- off = function(...)
- local cbCommands, side = { ... }
- for i = 1, #cbCommands do
- side = cbCommands[i]
- if type(side) == "string" and validSides[side] then
- rs.setBundledOutput(side, 0)
- end
- end
- end;
- getInput = function(sSide)
- if type(sSide) == "string" and validSides[sSide] then
- return rs.getBundledInput(sSide)
- end
- return 0
- end;
- getOutput = function(sSide)
- if type(sSide) == "string" and validSides[sSide] then
- return rs.getBundledOutput(sSide)
- end
- return 0
- end;
- findInputColor = function(sSide, nColor)
- if type(sSide) == "string" and type(nColor) == "number" and validSides[sSide] then
- if validColors[nColor] then
- return rs.testBundledInput(sSide, nColor)
- else
- local newColor = 0
- for colorValue in pairs(validColors) do
- if colors.test(nColor, colorValue) and rs.testBundledInput(sSide, colorValue) then
- newColor = colors.combine(newColor, colorValue)
- end
- end
- return newColor == nColor
- end
- end
- return false
- end;
- findOutputColor = function(sSide, nColor)
- if type(sSide) == "string" and type(nColor) == "number" and validSides[sSide] then
- if validColors[nColor] then
- return colors.test(rs.getBundledOutput(sSide), nColor)
- else
- local newColor = 0
- for colorValue in pairs(validColors) do
- if colors.test(nColor, colorValue) and colors.test(rs.getBundledOutput(sSide), colorValue) then
- newColor = colors.combine(newColor, colorValue)
- end
- end
- return newColor == nColor
- end
- end
- return false
- end;
- }
- return cable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement