5,358 Pages

-- <pre>
local p         = {}
local lib       = require('Module:Feature')
 
function p.get(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    local get = require ('Module:TFTTraitData/getter')
 
    args['traitname'] = args['traitname']     or args[1]
    args['set']       = tonumber(args['set']) or tonumber(args[2])
    args['datatype']  = args['datatype']      or args[3]
 
    local result = get[args['datatype']](args['traitname'], args['set'])
 
    if (args['datatype'] == "innate" or args['datatype'] == "synergy") and result ~= nil then
        if args['datatype'] == "synergy" then
            result = result .. synergy(args['traitname'], args['set'])
        end
 
        return frame:preprocess(result)
    elseif result == nil then
        return ""
    else
        return result
    end
end
 
function p.getTraits(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
    local IL         = require('Module:ImageLink')
    local datatable  = require('Module:TFTTraitData/data')
    local cmd        = require('Module:Maintenance data')
    local traittable = {}
    local result     = ""
 
    args['type'] = args['type']          or args[1] 
    args['set']  = tonumber(args['set']) or tonumber(args[2]) or tonumber(cmd.main{'TFTSet'})
 
    for trait in pairs(datatable) do
        if datatable[trait][args['set']] and datatable[trait][args['set']]['type'] == args['type'] then
            table.insert(traittable, trait)
        end
    end
    table.sort(traittable)
 
    for _, trait in pairs(traittable) do
        result = result .. tostring(IL.TFTtrait{
            ['trait']    = trait,
            ['set']      = args['set'],
            ['size']     = 46,
            ['text']     = '*none*',
            ['display']  = 'inline-block',
            ['border']   = 'false'
        })
    end
 
    return result
end
 
function p.championSynergy(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
    local TU         = require('Module:TFTUnitData')
    local s          = ''
 
    args['champion'] = args['champion']      or args[1]
    args['set']      = tonumber(args['set']) or tonumber(args[2])
 
    local origintable = TU.get{args['champion'], args['set'], "origin"}
    local classtable  = TU.get{args['champion'], args['set'], "class"}
 
    for _, originname in pairs(origintable) do
        s = s .. p.championSynergyTable{["traitname"] = originname, ["set"] = args['set']}
    end
 
    for _, classname in pairs(classtable) do
        s = s .. p.championSynergyTable{["traitname"] = classname, ["set"] = args['set']}
    end
 
    return s
end
 
function p.championSynergyTable(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
    local datatable  = require('Module:TFTTraitData/data')
    local IL         = require('Module:ImageLink')
    local TU         = require('Module:TFTUnitData')
    local lang       = mw.language.new("en")
    local table      = mw.html.create('table')
 
    args['traitname'] = args['traitname']     or args[1]
    args['set']       = tonumber(args['set']) or tonumber(args[2])
 
    -- TABLE START
    table
        :addClass('article-table')
        :css('width', '50%')
        :css('text-align', 'center')
        :newline()
 
 
    -- TABLE HEAD
    table
        :tag('th')
            :attr('colspan', '2')
            :css('text-align', 'center')
            :wikitext(tostring(IL.TFTtrait{
                ['trait']  = args['traitname'],
                ['set']    = args['set'],
                ['border'] = 'false'
            }))
        :done()
 
 
    -- TABLE ENTRY
    local tableEntry = mw.html.create('tr')
    local roster  = TU.getGroup({
        ['synergy'] = args['traitname'],
        ['set'] = args['set'],
        ['count'] = 'true'
    })
 
    if datatable[args['traitname']][args['set']]['item'] then
        tableEntry
            :tag('td')
                :wikitext(roster)
            :done()
            :tag('td')
                :css('width', '10%')
                :wikitext(tostring(IL.TFTitem{
                    ["item"] = datatable[args['traitname']][args['set']]['item'],
                    ["size"] = 46,
                    ["text"] = "*none*"
                }))
            :done()
    else
        tableEntry
            :tag('td')
                :attr('colspan', '2')
                :wikitext(roster)
            :done()
    end
    table
        :node(tableEntry)
        :newline()
 
    -- TABLE END
    table:allDone()
 
    return tostring(table)
end
 
function p.synergyList(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    local lang = mw.language.new("en")
    local list = mw.html.create('table')
    local IL   = require('Module:ImageLink')
    local TU   = require('Module:TFTUnitData')
 
    args['set']  = tonumber(args['set']) or tonumber(args[1])
    args['type'] = args['type']          or args[2]
 
    list
        :addClass('sortable article-table sticky-header')
        :css('width', '100%')
        :css('text-align', 'left')
        :newline()
 
        --TABLE HEADER    
        :tag('tr')
            :tag('th')
                :wikitext(args['type'])
            :done()
            :tag('th')
                :wikitext('Effect')
                :addClass('unsortable')
            :done()
            :tag('th')
                :css('width', '146px')
                :wikitext('Champions')
            :done()
            :tag('th')
                :wikitext('Items')
            :done()
        :done()
        :newline()
 
 
        -- TABLE ENTRIES
        local datatable  = require('Module:TFTTraitData/data')
        local traittable = {}
 
        for traitname in pairs(datatable) do
            if datatable[traitname][args['set']] ~= nil and datatable[traitname][args['set']]['type'] == args['type'] then
                table.insert(traittable, traitname)
            end
        end
        table.sort(traittable)
 
        for _, traitname in pairs(traittable) do
            local listentry = mw.html.create('tr')
 
            -- Trait
            listentry
                :tag('td')
                    :attr('data-sort-value', traitname)
                    :wikitext(tostring(IL.TFTtrait{
                        ["trait"]  = traitname,
                        ["set"]    = args['set'],
                        ["border"] = 'false'
                    }))
                :done()
 
            -- Effect
            listentry
                :tag('td')
                    :wikitext(datatable[traitname][args['set']]['synergy'] .. synergy(traitname, args['set']))
                :done()
 
            -- Champions
            local roster, count = TU.getGroup({
                        ['synergy'] = traitname,
                        ['set']     = args['set'],
                        ['count']   = 'true'
                    })
            listentry
                :tag('td')
                    :attr('data-sort-value', count)
                    :wikitext(roster)
                :done()
 
            -- Items
            if datatable[traitname][args['set']]['item'] then 
                listentry
                    :tag('td')
                        :attr('data-sort-value', datatable[traitname][args['set']]['item'])
                        :wikitext(tostring(IL.TFTitem{
                            ['item'] = datatable[traitname][args['set']]['item'],
                            ['size'] = 46,
                            ['text'] = "*none*"
                        }))
                    :done()
            else
                listentry
                    :tag('td')
                    :done()
            end
 
            list
                :node(listentry)
                :newline()
        end
        -- TABLE END
 
    list:allDone()
    return frame:preprocess(tostring(list))
end
 
-- LOCAL FUNCTONS
function synergy(traitname, set)
    local result = ''
    local get    = require ('Module:TFTTraitData/getter')
    local levels = get['levels'](traitname, set)
 
    if levels ~= nil then
 
        local sortedlevels = lib.getSortedKeys(levels)
 
        local levelcount = 0;
        local levelicons = {}
 
        for level in pairs(levels) do
            levelcount = levelcount + 1
        end
 
        local diamondtrait = get['diamondtrait'](traitname, set)
 
        if levelcount >= 2 then
 
            if levelcount == 2 then
                if diamondtrait then
                    levelicons = {'gold', 'diamond'}
                else
                    levelicons = {'bronze', 'gold'}
                end
            elseif levelcount == 3 then
                if (traitname == "Cloud" or traitname == "Steel") and set == 2 then
                    levelicons = {'silver', 'gold', 'diamond'}
                elseif diamondtrait then
                    levelicons = {'bronze', 'gold', 'diamond'}
                else
                    levelicons = {'bronze', 'silver', 'gold'}
                end
            else
                levelicons = {'bronze', 'silver', 'gold', 'diamond'}
            end
 
            result = result .. '<ul>'
            local levelunique = get['levelunique'](traitname, set)
 
            for index, level in pairs(sortedlevels) do
                local traittext = ''
                local levelcontent = levels[index]
                local levelindex = sortedlevels[index]
                if levelunique then
                    traittext = 'Exactly ' .. levelindex .. ' type'
                    if levelindex >= 2 then
                        traittext = traittext .. 's'
                    end
                    traittext = traittext .. ' of ' .. traitname
                else 
                    traittext = levelindex .. ' ' .. traitname
                    if levelindex >= 2 then
                        traittext = traittext .. 's'
                    end
                end
 
                result = result .. '<li>[[File:' .. traitname .. ' TFT ' .. levelicons[index] .. ' icon.png|20px|link=]] ' .. traittext .. ': ' .. levels[levelindex] .. '</li>'
            end
 
            result = result .. '</ul>'
        end
    end    
 
    return result
end
 
return p
-- </pre>
-- [[Category:Lua]]
Community content is available under CC-BY-SA unless otherwise noted.