Module:Utilities: Difference between revisions

Sur (talk | contribs)
m fix color_format arg for get_slot_color
Sur (talk | contribs)
m get_slot_color now utilizes color formats, hex, rgb, hsl, cmyk
Line 102: Line 102:
end
end


local slot_category_to_color = {
local slots_data = {
["Weapon"] = "c97a03", --orange
["Weapon"] = {
["Armor"] = "659818", --green
hex = "#c97a03",
["Tech"] = "8b56b4" --purple/pink
rgb = "rgb(201, 122, 3)",
hsl = "hsl(35, 97%, 40%)",
cmyk = "cmyk(0%, 39%, 98%, 21%)"
},
["Armor"] = {
hex = "#659818",
rgb = "rgb(101, 152, 24)",
hsl = "hsl(82, 73%, 34%)",
cmyk = "cmyk(34%, 0%, 84%, 40%)"
},
["Tech"] = {
hex = "#8b56b4",
rgb = "rgb(139, 86, 180)",
hsl = "hsl(274, 36%, 52%)",
cmyk = "cmyk(23%, 52%, 0%, 29%)"
}
}
}
function p.get_slot_color(slot, color_format)
function p.get_slot_color(slot, color_format)
Line 111: Line 126:
frame = slot
frame = slot
slot = frame.args[1]
slot = frame.args[1]
end
-- Validate arguments
if slot == nil then
return "'slot' parameter must be provided"
end
end
if color_format == nil then  
if color_format == nil then  
color_format = "hex"
color_format = "hex"
end
end
-- Utilize other formats later
if slot == nil then  
local slot_data = slots_data[slot]
return "'slot' parameter must be provided"
if slot_data == nil then
return "slot '" .. slot .. "' was not in slots_data map"
end
end
local color = slot_category_to_color[slot]
local color = slot_data[color_format]
if color == nil then
if color == nil then
return "'slot' " .. slot .. " is not in slot_category_to_color map"
return "color_format '" .. color_format .. "' is not in slots_data map"
end
end
return "#" .. color
return color
end
end


return p
return p