Module:Tier: Difference between revisions
Content added Content deleted
m (try to get around mediawiki formatting) |
m (surround div style in quotes) |
||
Line 42: | Line 42: | ||
local brightHexCode = lightenDarkenColor(hexCode, 40) |
local brightHexCode = lightenDarkenColor(hexCode, 40) |
||
return |
return '<div style="background-color: #;' .. hexCode .. '; border: 1px solid #"'.. brightHexCode ..'>' .. rarityString .. '</div>' |
||
end |
end |
||
Revision as of 03:35, 22 November 2023
Documentation for this module may be created at Module:Tier/doc
local p = {}
local function clamp(component)
return math.min(math.max(component, 0), 255)
end
local function lightenDarkenColor(col, amt)
local num = tonumber(col, 16)
local r = math.floor(num / 0x10000) + amt
local g = (math.floor(num / 0x100) % 0x100) + amt
local b = (num % 0x100) + amt
return string.format("%#x", clamp(r) * 0x10000 + clamp(g) * 0x100 + clamp(b))
end
local function getColorFromRarityString(rarityString)
rarityString = rarityString or "Common"
return ({
Layer = "5B5B5B",
Common = "C1C1C1",
Uncommon = "04B71C",
Rare = "1696F7",
Strange = "FD6933",
Unusual = "CC99FF",
Elite = "B50000",
Wondrous = "6AFF99",
Ascendant = "00B9CE",
Miraculous = "3853FF",
Immaculate = "FFA7E",
Outrageous = "8100B8",
Divine = "59E8FF",
Empyrean = "D50086",
Seraphic = "00021B"
})[rarityString]
end
function p.rarity(frame)
-- Get arguments from calling template
local arguments = frame.args
local rarityString = arguments[1]
local hexCode = getColorFromRarityString(rarityString)
local brightHexCode = lightenDarkenColor(hexCode, 40)
return '<div style="background-color: #;' .. hexCode .. '; border: 1px solid #"'.. brightHexCode ..'>' .. rarityString .. '</div>'
end
return p