Module:TierColor

Revision as of 03:50, 28 June 2025 by Myrsta (talk | contribs) (Module to color map for zone tiers)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:TierColor/doc

local p = {}

local number_to_color_map = { -- Colors to correspond to a given zone tier, feel free to change if you think it would look better
	['1'] = '#ADFF2F',
	['2'] = '#D6EB18',
	['3'] = '#FFD700',
	['4'] = '#FFA500',
	['5'] = '#FF7500',
	['6'] = '#FF4500',
	['7'] = 'Plum',
	['8'] = 'PaleTurquoise',
}

function p.recolor_numbers(frame)
	local input_string = tostring(frame.args[1] or '')
	
	if frame.args[2] == "false" then -- Option for uncolored table, give back input
		return input_string
	end

	local output_parts = {}

	for i = 1, #input_string do -- Split up numbers and apply color to each
		local char = input_string:sub(i, i)

		if number_to_color_map[char] then
			local color_code = number_to_color_map[char]
			table.insert(output_parts, '<span style="color:' .. color_code .. ';font-weight: 500;">' .. char .. '</span>') -- I think 500 font weight looks better for colored, default 700 for uncolored
		else
			table.insert(output_parts, char)
		end
	end
	
	return table.concat(output_parts)
end

function p.main(frame)
	return p.recolor_numbers(frame)
end

return p