User:DarthPhallus/GGSTCharNavTable/doc: Difference between revisions

From Dustloop Wiki
No edit summary
No edit summary
Line 4: Line 4:


Problems:
Problems:
* I want to make it include different games with different numbers of characters. So I need to find a way to generate tables as rectangles dynamically based on the number of characters? Or is that too much?
* Needs to navigate to the right page, just doing link=#character works but might have issues on edge cases? May need to figure out how magicwords work. https://www.mediawiki.org/wiki/Help:Magic_words#URL_data
* Needs to navigate to the right page, just doing link=#character works but might have issues on edge cases? May need to figure out how magicwords work. https://www.mediawiki.org/wiki/Help:Magic_words#URL_data
* Table might need some light styling. Get rid of cell borders?
* Table might need some light styling. Get rid of cell borders?

Revision as of 19:19, 5 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

Want it to look like this

Problems: