Module:Utilities: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m introduced a bug; temp reverting. Undo revision 13806 by Sur (talk)
Tag: Undo
Sur (talk | contribs)
m Bugfixed no_wrap param being handled wrong. Undo revision 13807 by Sur (talk)
Line 102: Line 102:
end
end


local slots_data = {
-- Hash for color values
local slot_colors = {
["Weapon"] = {
["Weapon"] = {
hex = "#c97a03",
hex = "c97a03",
rgb = "rgb(201, 122, 3)",
rgb = "201,122,3",
hsl = "hsl(35, 97%, 40%)",
hsl = "35,97%,40%",
cmyk = "cmyk(0%, 39%, 98%, 21%)"
cmyk = "0%,39%,98%,21%"
},
},
["Armor"] = {
["Armor"] = {
hex = "#659818",
hex = "659818",
rgb = "rgb(101, 152, 24)",
rgb = "101,152,24",
hsl = "hsl(82, 73%, 34%)",
hsl = "82,73%,34%",
cmyk = "cmyk(34%, 0%, 84%, 40%)"
cmyk = "34%,0%,84%,40%"
},
},
["Tech"] = {
["Tech"] = {
hex = "#8b56b4",
hex = "8b56b4",
rgb = "rgb(139, 86, 180)",
rgb = "139,86,180",
hsl = "hsl(274, 36%, 52%)",
hsl = "274,36%,52%",
cmyk = "cmyk(23%, 52%, 0%, 29%)"
cmyk = "23%,52%,0%,29%"
}
}
}
}
function p.get_slot_color(slot, color_format, debug_mode)
 
-- Hash for format configuration
local color_formats = {
hex = {
prefix = "#",
postfix = ""
},
rgb = {
prefix = "rgb(",
postfix = ")"
},
hsl = {
prefix = "hsl(",
postfix = ")"
},
cmyk = {
prefix = "cmyk(",
postfix = ")"
}
}
function p.get_slot_color(slot, color_format, no_wrap, debug_mode)
if type(slot) == 'table' and slot.args then
if type(slot) == 'table' and slot.args then
frame = slot
frame = slot
slot = frame.args[1]
slot = frame.args[1]
color_format = frame.args[2]
color_format = frame.args[2]
no_wrap = frame.args["no_wrap"]
debug_mode = frame.args["debug_mode"]
debug_mode = frame.args["debug_mode"]
end
end
-- Validate arguments
-- Validate arguments
if slot == nil then  
if slot == nil then return "'slot' parameter must be provided" end
return "'slot' parameter must be provided"
if color_format == nil then color_format = "hex" end
end
if no_wrap == nil or no_wrap == 'false' then no_wrap = false else no_wrap = true end
if color_format == nil then  
if debug_mode == nil or debug_mode == 'false' then debug_mode = false end
color_format = "hex"
end
local slot_data = slots_data[slot]
local slot_data = slot_colors[slot]
if slot_data == nil then
if slot_data == nil then return "slot '" .. slot .. "' was not in slots_data map" end
return "slot '" .. slot .. "' was not in slots_data map"
end
--Retrieve the color
--Retrieve the color
Line 147: Line 165:
if color == nil then
if color == nil then
return "color_format '" .. color_format .. "' is not in slots_data map"
return "color_format '" .. color_format .. "' is not in slots_data map"
end
-- Add prefix and postfix wrapping
if not no_wrap then
-- Retrieve prefix and postfix
prefix = color_formats[color_format]['prefix']
postfix = color_formats[color_format]['postfix']
-- Add to color
color = prefix .. color .. postfix
end
end
-- Return result
-- Return result
if debug_mode == nil then
debug_mode = false
end
if debug_mode then
if debug_mode then
return " " .. color
return " " .. color