Module:TierColour: Difference between revisions

From SmashWiki, the Super Smash Bros. wiki
Jump to navigationJump to search
No edit summary
m (Protected "Module:TierColour": high-risk template (part of tier lists) ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(3 intermediate revisions by the same user not shown)
Line 7: Line 7:
thisTier = tonumber(frame.args[2])
thisTier = tonumber(frame.args[2])
style = frame.args[3]
style = frame.args[3]
default = {127, 127, 127}
default = {191, 191, 191}
targetColour = default
targetColour = default
if colourCount ~= nil and thisTier ~= nil then
if colourCount ~= nil then
targetColour = tierColours[colourCount][thisTier]
colourSet = tierColours[colourCount]
if targetColour == nil then
if colourSet ~= nil and thisTier ~= nil then
targetColour = default
foundColour = colourSet[thisTier]
if foundColour ~= nil then
targetColour = foundColour
end
end
end
end
end
Line 25: Line 28:
returnColour[2] = math.floor(targetColour[2] * (1 - lighten) + 255 * lighten)
returnColour[2] = math.floor(targetColour[2] * (1 - lighten) + 255 * lighten)
returnColour[3] = math.floor(targetColour[3] * (1 - lighten) + 255 * lighten)
returnColour[3] = math.floor(targetColour[3] * (1 - lighten) + 255 * lighten)
return string.format("%x",returnColour[1])..string.format("%x",returnColour[2])..string.format("%x",returnColour[3])
return string.format("%02x",returnColour[1])..string.format("%02x",returnColour[2])..string.format("%02x",returnColour[3])
end
end


return tierColouriser
return tierColouriser

Latest revision as of 23:01, February 15, 2024

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

local tierColours = mw.loadData("Module:TierColour/data")

local tierColouriser = {}

function tierColouriser.getColour(frame)
	colourCount = tonumber(frame.args[1])
	thisTier = tonumber(frame.args[2])
	style = frame.args[3]
	default = {191, 191, 191}
	targetColour = default
	if colourCount ~= nil then
		colourSet = tierColours[colourCount]
		if colourSet ~= nil and thisTier ~= nil then
			foundColour = colourSet[thisTier]
			if foundColour ~= nil then
				targetColour = foundColour
			end
		end
	end
	lighten = 0
	if style == "header" then
		lighten = 0.75
	elseif style == "cell" then
		lighten = 0.5
	end
	returnColour = default -- targetColour inherits the readonly-ness of the import
	returnColour[1] = math.floor(targetColour[1] * (1 - lighten) + 255 * lighten)
	returnColour[2] = math.floor(targetColour[2] * (1 - lighten) + 255 * lighten)
	returnColour[3] = math.floor(targetColour[3] * (1 - lighten) + 255 * lighten)
	return string.format("%02x",returnColour[1])..string.format("%02x",returnColour[2])..string.format("%02x",returnColour[3])
end

return tierColouriser