More actions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 30: | Line 30: | ||
end | end | ||
local function | local function renderIconLabel(iconName, itemName) | ||
local wrapper = mw.html.create('div'):addClass('tierItem') | local wrapper = mw.html.create('div'):addClass('tierItem') | ||
if | 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>', | ||
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 | ||
token = trim(token) | |||
if mode == 'cargo' then | if mode == 'cargo' then | ||
tierGroup:node(renderCargoItem(cargoTable, | tierGroup:node(renderCargoItem(cargoTable, token)) | ||
elseif mode == 'icons' then | |||
tierGroup:node(renderExplicitIconItem(token)) | |||
else | else | ||
tierGroup:node(renderSimpleItem( | 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 textdrawIcons– renders entries from manually specified icon filesdrawCargoTable– 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:
- 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
}}
drawIcons
Use drawIcons when you want to define each item directly with its own icon file, without using Cargo.
Required argument order:
- 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
}}




















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:
- Cargo table name
- 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
}}























Notes
drawSimpledoes not query Cargo and only displays the provided labels directly.drawIconsdoes not query Cargo and renders each item using the explicitly supplied icon file.- For
drawIcons, each item must use the formatDisplay Name::FileName.ext. drawCargoTableexpects the first argument to be a valid Cargo table name.- For Cargo rendering, item names must match the stored
namevalues exactly. drawTierListmay still exist as an alias fordrawCargoTableif 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