Module:User:Rot8er conex/TierListText

local p = {} local heroCount = 0 local returnErrorFields = false local errorFields = '' local tierCount = 1 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' } -- 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 lightblue default') :css('text-align','center') :css('max-width','1200px')

tbl:tag('th') :wikitext('Rating') :css('height', '45px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px') tbl:tag('th') :wikitext('') :css('width', '84px')

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] .. ) for tier,weaponType in ipairs(v) do     local cellHeroes = "" for wt,hero in ipairs(weaponType) do       cellHeroes = cellHeroes .. hero .. ' '     end local wtTD = tr:tag('td') :wikitext(cellHeroes) 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