Module:Tier: Difference between revisions
Content added Content deleted
(create Rarity module) |
m (attempt to make Rarity module work with template) |
||
Line 34: | Line 34: | ||
function package.rarity(frame) |
function package.rarity(frame) |
||
-- if frame was called via #invoke, use invoke arguments. Else use template arguments |
|||
⚫ | |||
local args |
|||
if frame == mw.getCurrentFrame() then |
|||
args = frame:getParent().args |
|||
else |
|||
args = frame.args |
|||
end |
|||
⚫ | |||
local hexCode = package.getColorFromRarityString(rarityString) |
local hexCode = package.getColorFromRarityString(rarityString) |
||
local brightHexCode = lightenDarkenColor(hexCode, 40) |
local brightHexCode = lightenDarkenColor(hexCode, 40) |
Revision as of 02:03, 22 November 2023
Documentation for this module may be created at Module:Tier/doc
local package = {}
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
function package.getColorFromRarityString(rarityString)
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 package.rarity(frame)
-- if frame was called via #invoke, use invoke arguments. Else use template arguments
local args
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
else
args = frame.args
end
local rarityString = args[1]
local hexCode = package.getColorFromRarityString(rarityString)
local brightHexCode = lightenDarkenColor(hexCode, 40)
return "<div style=background-color: #" .. hexCode .. "; border: 1px solid #" .. brightHexCode ..">" .. rarityString .. "</div>"
end
return package