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
Created page with "local p = {} local html function p.drawTierList(frame) html = mw.html.create('div'):addClass('tierList')-- initialize the wikitext with the container for the list local GAME = frame.args[1]:gsub("%s+", "") -- capture the target game from the first arg local character = "default" local numberOfTiers = tablelength(frame.args) local colors = { '#b8ff89', '#fdff89', '#ffdf7f', '#ffbf7f','#e98d87', '#ff7ff0', '#d17fff', '#7fbfff', '#7feeff', '#7fffc3' }..."
 
No edit summary
Line 3: Line 3:


function p.drawTierList(frame)
function p.drawTierList(frame)
   html = mw.html.create('div'):addClass('tierList')-- initialize the wikitext with the container for the list
  local styles = frame:extensionTag('templatestyles', '', { src = 'Module:Tier_List/styles.css' })
   local GAME = frame.args[1]:gsub("%s+", "") -- capture the target game from the first arg
   html = mw.html.create('div'):addClass('tierList')
 
   local GAME = frame.args[1]:gsub("%s+", "")
   local character = "default"
   local character = "default"
   local numberOfTiers = tablelength(frame.args)
   local numberOfTiers = tablelength(frame.args)
   local colors = {
   local colors = {
  '#b8ff89', '#fdff89', '#ffdf7f',
    '#b8ff89', '#fdff89', '#ffdf7f',
  '#ffbf7f','#e98d87', '#ff7ff0',
    '#ffbf7f','#e98d87', '#ff7ff0',
  '#d17fff', '#7fbfff', '#7feeff', '#7fffc3'
    '#d17fff', '#7fbfff', '#7feeff', '#7fffc3'
   }
   }


   for index=2,numberOfTiers do
   for index=2,numberOfTiers do
     local currentTier = trim(frame.args[index]) -- use the argument at the current index as current tier data
     local currentTier = trim(frame.args[index])
     local tierLabel = string.match(currentTier, '(.*);') -- capture tier label from all characters before first ';'
     local tierLabel = string.match(currentTier, '(.*);')
     currentTier = string.match(currentTier, ";(.*)") -- remove the tier label from the current tier data
     currentTier = string.match(currentTier, ";(.*)")
 
    html:tag('div')
      :addClass('tierHeader')
      :css('background-color', colors[index-1])
      :wikitext(tierLabel)
      :done()


    --Inject tier label
    if index == 2 then -- first tier should have a rounded top corner
    html:tag('div'):addClass('tierHeader'):css('background-color', colors[1])
    :wikitext(tierLabel)
    :done()
    else
html:tag('div'):addClass('tierHeader'):css('background-color', colors[index-1])
    :wikitext(tierLabel)
    :done()
    end
   
    -- open a new tier container
     local tierGroup = mw.html.create('div'):addClass('tierGroup')
     local tierGroup = mw.html.create('div'):addClass('tierGroup')
     if index ~= numberOfTiers then  
     if index ~= numberOfTiers then
    tierGroup:addClass('tierUnderline')
      tierGroup:addClass('tierUnderline')
     end
     end


    -- iterate over tokens in current tier, sperrated by ',' character
     for token in string.gmatch(currentTier, '([^,]+)') do
     for token in string.gmatch(currentTier, '([^,]+)') do
       character = token
       character = token
       local characterLabel = mw.html.create('div')
       local characterLabel = mw.html.create('div')
       characterLabel:node(frame:expandTemplate{ title = 'Character Label', args = { GAME, character, size='32px' } }):done()
       characterLabel:node(frame:expandTemplate{ title = 'Character Label', args = { GAME, character, size='32px' } })
       tierGroup:node(characterLabel):done()
       tierGroup:node(characterLabel)
     end
     end
     html:node(tierGroup)
     html:node(tierGroup)
    html:done()
   end
   end


   -- close the entire tier list
   return styles .. tostring(html)
  html:done()
 
  return html
end
 
-- Return the size of a table by iterating over it and counting
function tablelength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end
end
function trim(s)
  return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
return p

Revision as of 17:34, 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
}}

Script error: The module returned a nil value. It is supposed to return an export table.

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 module returned a nil value. It is supposed to return an export table.

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 module returned a nil value. It is supposed to return an export table.

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 html

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

  local GAME = frame.args[1]:gsub("%s+", "")
  local character = "default"
  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, '(.*);')
    currentTier = string.match(currentTier, ";(.*)")

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

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

    for token in string.gmatch(currentTier, '([^,]+)') do
      character = token
      local characterLabel = mw.html.create('div')
      characterLabel:node(frame:expandTemplate{ title = 'Character Label', args = { GAME, character, size='32px' } })
      tierGroup:node(characterLabel)
    end

    html:node(tierGroup)
  end

  return styles .. tostring(html)
end