Module:Tier: Difference between revisions
Content added Content deleted
m (just use the actual arguments at this point I cannot deal with this anymore) |
m (replace package with p) |
||
Line 1: | Line 1: | ||
local |
local p = {} |
||
local function clamp(component) |
local function clamp(component) |
||
Line 34: | Line 34: | ||
end |
end |
||
function |
function p.rarity(frame) |
||
-- Get arguments from calling template |
-- Get arguments from calling template |
||
local arguments = frame.args |
local arguments = frame.args |
||
Line 45: | Line 45: | ||
end |
end |
||
return |
return p |
Revision as of 03:12, 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