Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Tier List: Difference between revisions

From CosmicPE Wiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 30: Line 30:
end
end


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


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


return wrapper
return wrapper
end
local function renderCargoItem(tableName, itemName)
local row = getCargoRow(tableName, itemName)
if row and row.thumb and trim(row.thumb) ~= '' then
return renderIconLabel(row.thumb, itemName)
end
return renderIconLabel(nil, itemName)
end
end


Line 51: Line 60:
:addClass('tierItem')
:addClass('tierItem')
:wikitext(string.format('<center><small>%s</small></center>', itemName))
:wikitext(string.format('<center><small>%s</small></center>', itemName))
end
local function renderExplicitIconItem(token)
local itemName, iconName = string.match(token, '^(.-)::(.+)$')
if itemName then
itemName = trim(itemName)
end
if iconName then
iconName = trim(iconName)
end
if not itemName or itemName == '' then
itemName = trim(token)
iconName = nil
end
return renderIconLabel(iconName, itemName)
end
end


Line 90: Line 118:


for token in string.gmatch(tierItems, '([^,]+)') do
for token in string.gmatch(tierItems, '([^,]+)') do
local itemName = trim(token)
token = trim(token)


if mode == 'cargo' then
if mode == 'cargo' then
tierGroup:node(renderCargoItem(cargoTable, itemName))
tierGroup:node(renderCargoItem(cargoTable, token))
elseif mode == 'icons' then
tierGroup:node(renderExplicitIconItem(token))
else
else
tierGroup:node(renderSimpleItem(itemName))
tierGroup:node(renderSimpleItem(token))
end
end
end
end
Line 111: Line 141:
function p.drawSimple(frame)
function p.drawSimple(frame)
return buildTierList(frame, 'simple')
return buildTierList(frame, 'simple')
end
function p.drawIcons(frame)
return buildTierList(frame, 'icons')
end
end



Latest revision as of 18:08, 8 March 2026

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
}}
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

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
}}
S
Flint
Emerald
Quartz
Experience Bottle
A
Tripwire Hook
Milk Bucket
Paper
Blaze Rod
B
Redstone Torch
Glowstone Dust
Ender Pearl
Spider Eye
C
Green Dye
Cyan Dye
Light Gray Dye
Orange Dye
D
Red Dye
Map
Ink Sac
Firework Star

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
}}
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

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',
		{
			where = string.format("name='%s'", itemName:gsub("'", "\\'")),
			limit = 1
		}
	)

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

	return nil
end

local function renderIconLabel(iconName, itemName)
	local wrapper = mw.html.create('div'):addClass('tierItem')

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

	return wrapper
end

local function renderCargoItem(tableName, itemName)
	local row = getCargoRow(tableName, itemName)

	if row and row.thumb and trim(row.thumb) ~= '' then
		return renderIconLabel(row.thumb, itemName)
	end

	return renderIconLabel(nil, itemName)
end

local function renderSimpleItem(itemName)
	return mw.html.create('div')
		:addClass('tierItem')
		:wikitext(string.format('<center><small>%s</small></center>', itemName))
end

local function renderExplicitIconItem(token)
	local itemName, iconName = string.match(token, '^(.-)::(.+)$')

	if itemName then
		itemName = trim(itemName)
	end

	if iconName then
		iconName = trim(iconName)
	end

	if not itemName or itemName == '' then
		itemName = trim(token)
		iconName = nil
	end

	return renderIconLabel(iconName, itemName)
end

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

	local startIndex = 1
	local cargoTable = nil

	if mode == 'cargo' then
		cargoTable = trim(frame.args[1])
		startIndex = 2
	end

	local numberOfTiers = tablelength(frame.args)

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

	for index = startIndex, 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 - startIndex + 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
			token = trim(token)

			if mode == 'cargo' then
				tierGroup:node(renderCargoItem(cargoTable, token))
			elseif mode == 'icons' then
				tierGroup:node(renderExplicitIconItem(token))
			else
				tierGroup:node(renderSimpleItem(token))
			end
		end

		html:node(tierGroup)
	end

	return styles .. tostring(html)
end

function p.drawCargoTable(frame)
	return buildTierList(frame, 'cargo')
end

function p.drawSimple(frame)
	return buildTierList(frame, 'simple')
end

function p.drawIcons(frame)
	return buildTierList(frame, 'icons')
end

p.drawTierList = p.drawCargoTable

return p