Module:DecodeHelper

local p = {}

local stackSizes = {SS_ONE=1, SS_SMALL=50, SS_MEDIUM=100, SS_BIG=200, SS_HUGE=500, SS_FLUID=0} setmetatable(stackSizes,{__index=function return 0 end})

p.decodeStackSize = function(strSize) return stackSizes[strSize] end

-- converts {193, 193, 193, 255} into '#C1C1C1FF' -- taken from here https://gist.github.com/marceloCodget/3862929; slightly modified local function rgb2hex(rgb) local hexadecimal = '#'

for key, value in pairs(rgb) do   local hex = ''

while(value > 0)do local index = math.fmod(value, 16) + 1 value = math.floor(value / 16) hex = string.sub('0123456789ABCDEF', index, index) .. hex end

if(string.len(hex) == 0)then hex = '00'

elseif(string.len(hex) == 1)then hex = '0' .. hex end

hexadecimal = hexadecimal .. hex end

return hexadecimal end

-- converts '(B=193,G=193,R=193,A=255)' into '#C1C1C1FF' p.decodeRGB = function(rgb) local bgra = {} local delims = {'=', ',', '(', ')'} local pattern = "[^"..table.concat(delims).."]+" for m in rgb:gmatch(pattern) do   table.insert(bgra, tonumber(m)) end -- colors are not in RGBA, they are BGRA! What the heck?! #BlameSimon return rgb2hex({ bgra[3], bgra[2], bgra[1], bgra[4] }) end

return p