Guest User

Untitled

a guest
Aug 28th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local side = "back"
  2.  
  3. local function parseColorInternal(color)
  4.   if colors[color] or colours[color] then
  5.     color = colors[color] or colours[color]
  6.   elseif not (type(colors) == "number" and colors >= 0 and colors <= 65535) then
  7.     error("Invalid colour supplied: Expected color got, "..tostring(color), 3)
  8.   end
  9.  
  10.   return color
  11. end
  12.  
  13. --# this turns on and off the colors
  14. local function setInternal(color, state)
  15.   local func = state and colors.combine or colors.subtract
  16.   rs.setBundledOutput(side, func(rs.getBundledOutput(side), color))
  17. end
  18.  
  19. function allOff()
  20.   rs.setBundledOutput(side, 0)
  21. end
  22.  
  23. function allOn()
  24.   rs.setBundledOutput(side, 65535)
  25. end
  26.  
  27. --[[
  28. turn on the supplied colors. example usages:
  29. turnOn("white", colors.orange, "purple", 16)
  30.  
  31. notice how we can use a combination of ways to say the colour, and we can also supply lots of colours and it will do it for us.
  32. --]]
  33. function turnOn(...)
  34.   for _,color in ipairs({...}) do
  35.     setInternal(parseColorInternal(color), true)
  36.   end
  37. end
  38.  
  39. --# Same as above only turns off the supplied colors.
  40. function turnOff(...)
  41.   for _,color in ipairs({...}) do
  42.     setInternal(parseColorInternal(color), false)
  43.   end
  44. end
  45.  
  46. function isOn(color)
  47.   return rs.testBundledInput(side, parseColorInternal(color))
  48. end
  49.  
  50. --# returns a number representing all the colours that are on
  51. function getOn()
  52.   return rs.getBundledOutput(side)
  53. end
  54.  
  55. --# returns a number representing all the colours that are off
  56. function getOff()
  57.   return 65535 - rs.getBundledOutput(side)
  58. end
  59.  
  60. function toggle(...)
  61.   for _,color in ipairs({...}) do
  62.     --# easier to use the internal here
  63.     setInternal(color, not isOn(parseColorInternal(color)))
  64.   end
  65. end
  66.  
  67. function setside(s)
  68.   side = s
  69. end
Advertisement
Add Comment
Please, Sign In to add comment