User:DarthPhallus/GGSTCharNavTable: Difference between revisions

From Dustloop Wiki
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
local p = {}
{| class="wikitable"  
 
! colspan=5 | Table of Contents
function p.drawTierList(frame)
! style="border-style: none";
  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
|[[Image:GGST_Anji_Icon.png|45px|link={{FULLPAGENAME}}#Anji]]||[[Image:GGST_Axl_Icon.png|45px|link={{FULLPAGENAME}}#Axl]]||[[Image:GGST_Baiken_Icon.png|45px|link={{FULLPAGENAME}}#Baiken]]||[[Image:GGST_Chipp_Icon.png|45px|link={{FULLPAGENAME}}#Chipp]]||[[Image:GGST_Faust_Icon.png|45px|link={{FULLPAGENAME}}#Faust]]
  local character = "default"
|-
  local numberOfTiers = tablelength(frame.args)
|[[Image:GGST_Giovanna_Icon.png|45px|link={{FULLPAGENAME}}#Giovanna]]||[[Image:GGST_Goldlewis_Icon.png|45px|link={{FULLPAGENAME}}#Goldlewis]]||[[Image:GGST_Happy_Chaos_Icon.png|45px|link={{FULLPAGENAME}}#Happy_Chaos]]||[[Image:GGST_I-No_Icon.png|45px|link={{FULLPAGENAME}}#I-No]]||[[Image:GGST_Jack-O_Icon.png|45px|link={{FULLPAGENAME}}#Jack-O]]
  local colors = {'b8ff89', 'fdff89', 'ffdf7f', 'ffbf7f', 'e98d87', 'ff7ff0', 'd17fff', '7fbfff', '7feeff', '7fffc3' } -- an array of pre-defined colors
|-
 
|[[Image:GGST_Ky_Icon.png|45px|link={{FULLPAGENAME}}#Ky]] || [[Image:GGST_Leo_Icon.png|45px|link={{FULLPAGENAME}}#Leo]]||[[Image:GGST_May_Icon.png|45px|link={{FULLPAGENAME}}#May]]||[[Image:GGST_Millia_Icon.png|45px|link={{FULLPAGENAME}}#Millia]]||[[Image:GGST_Nagoriyuki_Icon.png|45px|link={{FULLPAGENAME}}#Nagoriyuki]]
  for index=2,numberOfTiers do
|-
    local currentTier = trim(frame.args[index]) -- use the argument at the current index as current tier data
|[[Image:GGST_Potemkin_Icon.png|45px|link={{FULLPAGENAME}}#Potemkin]]||[[Image:GGST_Ramlethal_Icon.png|45px|link={{FULLPAGENAME}}#Ramlethal]]||[[Image:GGST_Sol_Icon.png|45px|link={{FULLPAGENAME}}#Sol]]||[[Image:GGST_Testament_Icon.png|45px|link={{FULLPAGENAME}}#Testament]]||[[Image:GGST_Zato_Icon.png|45px|link={{FULLPAGENAME}}#Zato]]
    local tierLabel = string.match(currentTier, '(.*);') -- capture tier label from all characters before first ';'
|}</includeonly><noinclude>{{clear}}{{doc}}</noinclude>
    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

Latest revision as of 16:54, 9 August 2022

local p = {}

function p.drawTierList(frame)

local wikitext = "

" -- 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 .. "
" .. tierLabel .. "
"
   elseif index == numberOfTiers then -- middle tiers are normal
wikitext = wikitext .. "
" .. tierLabel .. "
"
   else -- final tier has a roudned bottom corner
wikitext = wikitext .. "
" .. tierLabel .. "
"
   end
   
   -- open a new tier container
   if index ~= numberOfTiers then 
wikitext = wikitext .. "
"
   else -- final tier does not have an underline
wikitext = wikitext .. "
"
   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 .. "
" .. characterLabel .. "
"
   end
 
   -- close the current tier container
wikitext = wikitext .. "
"
 end
 -- close the entire tier list
wikitext = wikitext .. "
"
 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