Module:Tier List: Difference between revisions

From Dustloop Wiki
mNo edit summary
mNo edit summary
(30 intermediate revisions by the same user not shown)
Line 3: Line 3:
function p.drawTierList(frame)
function p.drawTierList(frame)
   local wikitext = "<div class=\"tierList\">" -- initialize the wikitext with the container for the list
   local wikitext = "<div class=\"tierList\">" -- initialize the wikitext with the container for the list
   local GAME = frame.args[1]:gsub("%s+", "")
   local GAME = frame.args[1]:gsub("%s+", "") -- capture the target game from the first arg
   local character = "default"
   local character = "default"
    
   local numberOfTiers = tablelength(frame.args)
   --Inject the special first tier label
   local colors = {'b8ff89', 'fdff89', 'ffdf7f', 'ffbf7f', 'e98d87', 'ff7ff0', 'd17fff', '7fbfff', '7feeff', '7fffc3' } -- an array of pre-defined colors
  wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #b8ff89; border-top-left-radius: 4px;\">S</div>"


   -- open a new tier container
   for index=2,numberOfTiers do
  wikitext = wikitext .. "<div class=\"tierGroup tierUnderline\">"
    local currentTier = trim(frame.args[index]) -- use the argument at the current index as current tier data
    local tierLabel = string.match(currentTier, '(.*);') -- capture tier label from all characters before first ';'
    currentTier = string.match(currentTier, ";(.*)") -- remove the tier label from the current tier data


  local currentTier = "default"
    --Inject tier label
  currentTier = frame.args[2]:gsub("%s+", "")
    if index == 2 then -- first tier should have a rounded top corner
  -- iterate over tokens in arg, sperrated by ',' character
      wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #" .. colors[1] .. "; border-top-left-radius: 4px;\">" .. tierLabel .. "</div>"
  for token in string.gmatch(currentTier, '([^,]+)') do
    elseif index == numberOfTiers then -- middle tiers are normal
     character = token
      wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #" .. colors[index-1] .. "; border-bottom-left-radius: 4px;\">" .. tierLabel .. "</div>"
     -- inject character label
    else -- final tier has a roudned bottom corner
     local characterLabel = frame:expandTemplate{ title = 'Character Label', args = { GAME, character, '32px' } }
      wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #" .. colors[index-1] .. ";\">" .. tierLabel .. "</div>"
    wikitext = wikitext .. "<div>" .. characterLabel .. "</div>"
    end
  end
      
     -- open a new tier container
     if index ~= numberOfTiers then
      wikitext = wikitext .. "<div class=\"tierGroup tierUnderline\">"
    else -- final tier does not have an underline
      wikitext = wikitext .. "<div class=\"tierGroup\">"
    end


   -- close the current tier container
    -- iterate over tokens in current tier, sperrated by ',' character
  wikitext = wikitext .. "</div>"
    for token in string.gmatch(currentTier, '([^,]+)') do
      character = token
      -- inject character label
      local characterLabel = frame:expandTemplate{ title = 'Character Label', args = { GAME, character, '32px' } }
      wikitext = wikitext .. "<div>" .. characterLabel .. "</div>"
    end
    
    -- close the current tier container
    wikitext = wikitext .. "</div>"


 
   end
 
 
 
 
 
 
   -- inject a new tier label
  wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #fdff89;\">A</div>"
 
  -- open a new tier container
  wikitext = wikitext .. "<div class=\"tierGroup tierUnderline\">"
 
  -- inject a new character label
  local characterLabel = frame:expandTemplate{ title = 'Character Label', args = { GAME, character, '32px' } }
  wikitext = wikitext .. "<div>" .. characterLabel .. "</div>"
 
  -- close the current tier container
  wikitext = wikitext .. "</div>"


   -- close the entire tier list
   -- close the entire tier list
Line 51: Line 48:
end
end


return p
-- 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


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


  -- local index = 2
return p
  -- while tonumber(frame.args['active' .. index]) ~= nil or tonumber(frame.args['inactive' .. index]) ~= nil do
  --  drawFrame(frame.args['active' .. index], "active")
  --  drawFrame(frame.args['inactive' .. index], "inactive")
  --  index = index + 1
  -- end

Revision as of 17:35, 25 May 2022

Module:Tier_List is used to generate tier lists directly within the wiki using HTML, and the existing character labels.

Usage

A tier list requires that arguments be present in order.

  1. The abbreviation for the game (IE: GGACR, GBVS, DBFZ, etc)
  2. All of the tiers, ordered from top to bottom

Within a given tier, you must define the label for that tier (the letter that appears inside of the colored square) followed by a semicolon character (';').

Short Names in Labels

The tier list will attempt to find the appropriate icon and link for a given character. If you choose not to use the full name of a character, you must set up a necessary redirect from the short name to the full name. This applies to both the icon file and the character page itself.

For example: We want to show "Sol" on our tier list instead of "Sol Badguy". We must create 2 redirects.

  • Redirect from [[File:GGACR_Sol_Icon.png]] to [[File:GGACR_Sol_Badguy_Icon.png]]
  • Redirect from [[GGACR/Sol]] to [[GGACR/Sol_Badguy]]

Example

{{#invoke:Tier List|drawTierList
|GGACR
|S;Testament,Baiken,Zappa,Dizzy
|A;Chipp,Axl,Faust,Millia,Jam
|B;A.B.A,Potemkin,Sol,May
|C;Kliff,Order-Sol,Justice,Slayer,Anji,Johnny
|D;Robo-Ky,Eddie,I-No,Ky,Venom,Bridget
}}

local p = {}

function p.drawTierList(frame)
  local wikitext = "<div class=\"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' } -- an array of pre-defined colors

  for index=2,numberOfTiers do
    local currentTier = trim(frame.args[index]) -- use the argument at the current index as current tier data
    local tierLabel = string.match(currentTier, '(.*);') -- capture tier label from all characters before first ';'
    currentTier = string.match(currentTier, ";(.*)") -- remove the tier label from the current tier data

    --Inject tier label
    if index == 2 then -- first tier should have a rounded top corner
      wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #" .. colors[1] .. "; border-top-left-radius: 4px;\">" .. tierLabel .. "</div>"
    elseif index == numberOfTiers then -- middle tiers are normal
      wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #" .. colors[index-1] .. "; border-bottom-left-radius: 4px;\">" .. tierLabel .. "</div>"
    else -- final tier has a roudned bottom corner
      wikitext = wikitext .. "<div class=\"tierHeader\" style=\"background-color: #" .. colors[index-1] .. ";\">" .. tierLabel .. "</div>"
    end
    
    -- open a new tier container
    if index ~= numberOfTiers then 
      wikitext = wikitext .. "<div class=\"tierGroup tierUnderline\">"
    else -- final tier does not have an underline
      wikitext = wikitext .. "<div class=\"tierGroup\">"
    end

    -- iterate over tokens in current tier, sperrated by ',' character
    for token in string.gmatch(currentTier, '([^,]+)') do
      character = token
      -- inject character label
      local characterLabel = frame:expandTemplate{ title = 'Character Label', args = { GAME, character, '32px' } }
      wikitext = wikitext .. "<div>" .. characterLabel .. "</div>"
    end
  
    -- close the current tier container
    wikitext = wikitext .. "</div>"

  end

  -- close the entire tier list
  wikitext = wikitext .. "</div>"

  return wikitext
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

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

return p