Module:TierListTest

local p = {} local heroCount = 0 local returnErrorFields = false local errorFields = '' local tierCount = 1 local borderStyle = 'solid 3px black' local cargo = mw.ext.cargo local escq = require 'Module:EscQ'.main1 local tierLetters = { [1] = 'S+', [2] = 'S', [3] = 'S-', [4] = 'A+', [5] = 'A', [6] = 'A-', [7] = 'B+', [8] = 'B', [9] = 'B-', [10] = 'C' } local tierNumbers = { [1] = '10.0', [2] = '9.5',  [3] = '9.0',  [4] = '8.5',  [5] = '8.0',  [6] = '7.5',  [7] = '7.0',  [8] = '6.5',  [9] = '6.0',  [10] = '5.5' } -- Defining table cells -- (12 nested tables b/c 12 diff. weapon types) local tiers = { {{},{},{},{},{},{},{},{},{},{},{},{}}, {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}},  {{},{},{},{},{},{},{},{},{},{},{},{}} } function p._tierList(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,frame,iconflag) parseThroughTier(t1,frame) parseThroughTier(t2,frame) parseThroughTier(t3,frame) parseThroughTier(t4,frame) parseThroughTier(t5,frame) parseThroughTier(t6,frame) parseThroughTier(t7,frame) parseThroughTier(t8,frame) parseThroughTier(t9,frame) parseThroughTier(t10,frame) if not true then return createTable(frame,iconflag) .. "hero count: " .. heroCount .. "errors: " .. errorFields .. mw.title.getCurrentTitle.text end return createTable(frame,iconflag) end

function parseThroughTier(tier,frame) if tier ~= '' then for k,heroName in ipairs(tier) do     local queryFields = "WeaponType" local queryArgs = { where = ("_pageName='%s' AND IFNULL(Properties__full,'') NOT LIKE '%%enemy%%'"):format(escq(heroName)), groupBy = '_pageName', limit = 10 }     local queryResult = cargo.query( 'Units', queryFields, queryArgs ) if queryResult[1] ~= nil then heroCount = heroCount + 1 table.insert(tiers[tierCount][getWeaponTypeNum(queryResult[1].WeaponType)], heroName) --errorFields = errorFields .. "nil error" .. heroName .. ' '     end frame:callParserFunction('#vardefine', { heroName, tierLetters[tierCount] }) end end tierCount = tierCount + 1 end

function createTable(frame,iconflag) local tbl = mw.html.create('table') :addClass('wikitable tierlist') :css('text-align','center') :css('max-width','1200px')

tbl:tag('th') :wikitext('Rating') :css('height', '45px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-left', borderStyle) :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-left', borderStyle) :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-left', borderStyle) :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-left', borderStyle) :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle) tbl:tag('th') :wikitext('') :css('width', '84px') :css('border-bottom', borderStyle)

local iconTemplate = 'Template:TierListUnitBox' if iconflag == 'true' or iconflag == 'yes' then iconTemplate = 'Template:TierListUnitBoxR' end tierCount = 1 for k,v in ipairs(tiers) do   local tr = tbl:tag('tr') tr:tag('td'):wikitext(' .. tierLetters[tierCount] .. ' (' .. tierNumbers[tierCount] .. ') )   for tier,weaponType in ipairs(v) do      local cellHeroes = "" for wt,hero in ipairs(weaponType) do       local tierListUnitBox = frame:expandTemplate{ title = iconTemplate, args = { hero } } cellHeroes = cellHeroes .. tostring(tierListUnitBox) end local wtTD = tr:tag('td') :wikitext(cellHeroes) if tier%3 == 1 then wtTD:css('border-left', borderStyle) end if tier>=1 and tier<=3 then wtTD:css('background-color', '#efe6e1') elseif tier>=4 and tier<=6 then wtTD:css('background-color', '#e1e6ef') elseif tier>=7 and tier<=9 then wtTD:css('background-color', '#e5efe1') elseif tier>=10 and tier<=12 then wtTD:css('background-color', '#eeeeee') end end tierCount = tierCount + 1 end return tostring(tbl) end

function getWeaponTypeNum(weaponType) local weaponTypeNum = { ['Red Sword'] = 1, ['Red Tome'] = 2, ['Red Breath'] = 3, ['Blue Lance'] = 4, ['Blue Tome'] = 5, ['Blue Breath'] = 6, ['Green Axe'] = 7, ['Green Tome'] = 8, ['Green Breath'] = 9, ['Colorless Bow'] = 10, ['Colorless Dagger'] = 11, ['Colorless Staff'] = 12, } return weaponTypeNum[weaponType] end

function p.tierList(frame) local args = frame.args local iconflag = '' if args['icons'] ~= nil then iconflag = args['icons'] end return p._tierList(   mw.text.split(args[1], '%s*,%s*'),    mw.text.split(args[2], '%s*,%s*'),    mw.text.split(args[3], '%s*,%s*'),    mw.text.split(args[4], '%s*,%s*'),    mw.text.split(args[5], '%s*,%s*'),    mw.text.split(args[6], '%s*,%s*'),    mw.text.split(args[7], '%s*,%s*'),    mw.text.split(args[8], '%s*,%s*'),    mw.text.split(args[9], '%s*,%s*'),    mw.text.split(args[10], '%s*,%s*'),    frame,iconflag) end

return p