Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 17:51, 8 March 2026 by Muqsit (talk | contribs)

Module:Tier_List is used to generate tier lists directly within the wiki.

It currently supports three rendering methods:

  • drawSimple – renders entries directly from the provided text
  • drawIcons – renders entries from manually specified icon files
  • drawCargoTable – renders entries using Cargo data

Usage

drawSimple

Use drawSimple when you want to render a tier list directly from the provided text without using Cargo.

Required argument order:

  1. All tiers, ordered from top to bottom

Within each tier, define the tier label first, followed by a semicolon character (;), then a comma-separated list of item names.

Example

{{#invoke:Tier List|drawSimple
|S;Blackout,Divine Immolation,Godly Overload,Deadly Disarmor
|A;Bleed,Deathbringer,Guardians,Gears,Execute
|B;Angelic,Armored,Dodge,Enlighted,Ghost
|C;Auto Smelt,Haste,Glowing,Headless,Confusion
|D;Aquatic,Anti Gravity,Experience,Decapitation
}}

Script error: The function "drawSimple" does not exist.

drawIcons

Use drawIcons when you want to define each item directly with its own icon file, without using Cargo.

Required argument order:

  1. All tiers, ordered from top to bottom

Within each tier, define the tier label first, followed by a semicolon character (;), then a comma-separated list of items.

Each item must use this format:

  • Display Name::FileName.ext

Example

{{#invoke:Tier List|drawIcons
|S;Flint::Flint.png,Emerald::Emerald.png,Quartz::Quartz.png,Experience Bottle::Experience bottle.png
|A;Tripwire Hook::Tripwire hook.png,Milk Bucket::Milk bucket.png,Paper::Paper.png,Blaze Rod::Blaze rod.png
|B;Redstone Torch::Redstone torch.png,Glowstone Dust::Glowstone dust.png,Ender Pearl::Ender pearl.png,Spider Eye::Spider eye.png
|C;Green Dye::Green dye.png,Cyan Dye::Cyan dye.png,Light Gray Dye::Light gray dye.png,Orange Dye::Orange dye.png
|D;Red Dye::Red dye.png,Map::Map.png,Ink Sac::Ink sac.png,Firework Star::Firework star.png
}}

Script error: The function "drawIcons" does not exist.

drawCargoTable

Use drawCargoTable when the first argument is the name of a Cargo table, and the remaining arguments are the tiers in top-to-bottom order.

Required argument order:

  1. Cargo table name
  2. All tiers, ordered from top to bottom

Within each tier, define the tier label first, followed by a semicolon character (;), then a comma-separated list of item names.

The item names should match the values stored in the Cargo table exactly.

Example: Masks

{{#invoke:Tier List|drawCargoTable
|Mask
|S;Zeus,Monopoly,Thanos,Animal Control
|A;Anonymous,Anti-Silence,Bunny,Death Knight,Death Wish
|B;Equalizer,Ghost,Glitch,Grave Digger
|C;Headless,Holy,Joker,Lover,Monopoly,Muqsit
|D;Necromancer,Outpost,Party,Pilgrim
}}

Script error: The function "drawCargoTable" does not exist.

Notes

  • drawSimple does not query Cargo and only displays the provided labels directly.
  • drawIcons does not query Cargo and renders each item using the explicitly supplied icon file.
  • For drawIcons, each item must use the format Display Name::FileName.ext.
  • drawCargoTable expects the first argument to be a valid Cargo table name.
  • For Cargo rendering, item names must match the stored name values exactly.
  • drawTierList may still exist as an alias for drawCargoTable if backward compatibility is enabled.

local p = {}

local function tablelength(t)
	local count = 0
	for _ in pairs(t) do
		count = count + 1
	end
	return count
end

local function trim(s)
	return (string.gsub(s or "", "^%s*(.-)%s*$", "%1"))
end

local function getCargoRow(tableName, itemName)
	local results = mw.ext.cargo.query(
		tableName,
		'name,thumb,thumb_formatted',
		{
			where = string.format("name='%s'", itemName:gsub("'", "\\'")),
			limit = 1
		}
	)

	if results and results[1] then
		return results[1]
	end

	return nil
end

local function renderCargoItem(tableName, itemName)
	local row = getCargoRow(tableName, itemName)
	local wrapper = mw.html.create('div'):addClass('tierItem')

	if row and row.thumb and trim(row.thumb) ~= '' then
		wrapper:wikitext(string.format(
			'[[File:%s|32px|link=|class=cpe-pixelate cpe-round|center]]<center><small>%s</small></center>',
			row.thumb,
			itemName
		))
	else
		wrapper:wikitext(string.format('<center><small>%s</small></center>', itemName))
	end

	return wrapper
end

function p.drawTierList(frame)
	local styles = frame:extensionTag('templatestyles', '', { src = 'Module:Tier_List/styles.css' })
	local html = mw.html.create('div'):addClass('tierList')

	local cargoTable = trim(frame.args[1])
	local numberOfTiers = tablelength(frame.args)

	local colors = {
		'#b8ff89', '#fdff89', '#ffdf7f',
		'#ffbf7f', '#e98d87', '#ff7ff0',
		'#d17fff', '#7fbfff', '#7feeff', '#7fffc3'
	}

	for index = 2, numberOfTiers do
		local currentTier = trim(frame.args[index])
		local tierLabel = string.match(currentTier, '^(.-);')
		local tierItems = string.match(currentTier, ';(.*)$') or ''

		html:tag('div')
			:addClass('tierHeader')
			:css('background-color', colors[index - 1] or '#ccc')
			:wikitext(tierLabel or '?')
			:done()

		local tierGroup = mw.html.create('div'):addClass('tierGroup')
		if index ~= numberOfTiers then
			tierGroup:addClass('tierUnderline')
		end

		for token in string.gmatch(tierItems, '([^,]+)') do
			local itemName = trim(token)
			tierGroup:node(renderCargoItem(cargoTable, itemName))
		end

		html:node(tierGroup)
	end

	return styles .. tostring(html)
end

return p