Aadvert

toggleBundleColor

Mar 9th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local validSides = {top = true, bottom = true, left = true, right = true, front = true, back = true}
  2. local validPow2 = {[1] = true, [2] = true, [4] = true, [8] = true, [16] = true, [32] = true, [64] = true, [128] = true,
  3.             [256] = true, [512] = true, [1024] = true, [2048] = true,
  4.             [4096] = true, [8192] = true, [16384] = true, [32768] = true }
  5.  
  6.  
  7. function toggleBundleColor(sSide, ...)
  8.     -- Provide helpful error messages
  9.     if type(sSide) ~= "string" then
  10.         error("(toggleBundleColor): Bad argument (sSide, 1): Expected string, got " .. type(sSide), 2)
  11.     end
  12.     if not validSides[sSide] then
  13.         error("(toggleBundleColor): Unrecognied side: " .. sSide, 2)
  14.     end
  15.     -- Retrieve the colors outside of the loop
  16.     local nColors = rs.getBundledOutput(sSide)
  17.  
  18.     -- Loop through all the extra arguments
  19.     for i, v in ipairs(arg) do
  20.         -- Error messages, again.
  21.         local sColor = v
  22.         local nColor = colors[sColor]
  23.         if type(sColor) == "number" then
  24.             nColor = sColor
  25.         end
  26.         if not validPow2[nColor] then
  27.             error("(toggleBundleColor): Bad argument (color, " .. i .. "): Unrecognized color.", 2)
  28.         end
  29.         -- Modify the color
  30.         nColors = bit.bxor(nColors, nColor) -- This will toggle the 'bit' of color we have.
  31.     end
  32.  
  33.     rs.setBundledOutput(sSide, nColors) -- Change the colors.
  34.     return nColors -- Return what the changed colors are.
  35. end
Advertisement
Add Comment
Please, Sign In to add comment