Module:Tier: Difference between revisions

From Rock Revolution Wiki
Content added Content deleted
m (Joshument moved page Module:Rarity to Module:Tier without leaving a redirect: incorrect module name)
m (rename rarity to tier)
Line 13: Line 13:
end
end


local function getColorFromRarityString(rarityString)
local function getColorFromTierString(tierString)
rarityString = rarityString or "Common"
tierString = tierString or "Common"
return ({
return ({
Layer = "5B5B5B",
Layer = "5B5B5B",
Line 31: Line 31:
Empyrean = "D50086",
Empyrean = "D50086",
Seraphic = "00021B"
Seraphic = "00021B"
})[rarityString]
})[tierString]
end
end


function p.rarity(frame)
function p.tier(frame)
-- Get arguments from calling template
-- Get arguments from calling template
local arguments = frame.args
local arguments = frame.args
local rarityString = arguments[1]
local tierString = arguments[1]
local hexCode = getColorFromRarityString(rarityString)
local hexCode = getColorFromTierString(tierString)
local brightHexCode = lightenDarkenColor(hexCode, 92)
local brightHexCode = lightenDarkenColor(hexCode, 92)
Line 45: Line 45:
.. '; border: 1px solid #'.. brightHexCode
.. '; border: 1px solid #'.. brightHexCode
.. '; color: #' .. brightHexCode
.. '; color: #' .. brightHexCode
.. '">' .. rarityString .. '</div>'
.. '">' .. tierString .. '</div>'
end
end



Revision as of 03:47, 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)):sub(3)
end

local function getColorFromTierString(tierString)
	tierString = tierString 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"
	})[tierString]
end

function p.tier(frame)
	-- Get arguments from calling template
	local arguments = frame.args
	
	local tierString = arguments[1]
	local hexCode = getColorFromTierString(tierString)
	local brightHexCode = lightenDarkenColor(hexCode, 92)
	
	return '<div style="font-weight: bold; border-radius: 6px; text-align: center; background-color: #' .. hexCode 
	.. '; border: 1px solid #'.. brightHexCode 
	.. '; color: #' .. brightHexCode
	.. '">' .. tierString .. '</div>' 
end

return p