FANDOM


local Tree = {}
 
-- Dependencies
local ImageLink = require("Module:ImageLink")
 
function Tree.tree(frame)
    local args, pargs = arguments(frame.args), arguments(frame:getParent().args) or {}
    local tab = mw.html.create('table'):addClass('mastery-tree')
 
    local parent = true
    if mw.ustring.lower(args['Use parent'] or '') == 'no' then parent = false end
 
    local season = tonumber(args['Season'])
    local masteries = {}
    for x=1,4 do
        masteries[x] = {}
        local perquisite = false
        for y=1,6 do
            local prefix = y .. ':' .. x .. ':'
            local mastery = args[prefix .. 'Mastery']
 
            if mastery then
                local levels = math.max(tonumber(args[prefix .. 'Levels']) or 0, 0)
 
                local points
                if parent then points = math.max(math.min(tonumber(args[prefix .. 'Points'] or pargs[mastery]) or 0, levels), 0)
                else points = math.max(math.min(tonumber(args[prefix .. 'Points']) or 0, levels), 0) end
 
                if perquisite and perquisite[1] < perquisite[2] then
                    points = 0
                    perquisite = false
                end
 
                perquisite = ternary(args[prefix .. 'Perquisite'], true, false)
                masteries[x][y] = {
                    mastery = mastery,
                    points = points,
                    levels = levels,
                    perquisite = perquisite,
                }
                if perquisite then perquisite = {points, levels} end
            elseif y>1 then
                local count = 1
                for i=y-1,1 do
                    if masteries[x][i] then
                        masteries[x][i]['space'] = count
                        break
                    end
                    count = count + 1
                end
                masteries[x][y] = nil
            else
                masteries[x][y] = nil
            end
        end
    end
    for y=1,6 do
        local tr = tab:tag('tr')
        for x=1,4 do
            if masteries[x][y] then
                local link = ImageLink.mastery{args={
                    mastery = masteries[x][y]['mastery'],
                    season = season,
                    display = 'inline-block',
                    label = 'none',
                    size = 40,
                }}
                link:addClass('mastery-tree-icon'):addClass(pointsClass(masteries[x][y]['points'], masteries[x][y]['levels']))
                if masteries[x][y]['levels'] > 0 then link:tag('div'):addClass('mastery-levels'):wikitext(mw.ustring.format('%s/%s', masteries[x][y]['points'], masteries[x][y]['levels'])) end
                tr:tag('td'):node(link):css('width', '48px'):css('height', '44px')
            else
                if y == 1 then tr:tag('td') end
            end
        end
        if y<6 then
            local tr = tab:tag('tr'):addClass('spacer')
            for x=1,4 do
                if masteries[x][y] then
                    local td = tr:tag('td')
                    if masteries[x][y]['perquisite'] then
                        td:addClass('join')
                    end
                    local rowspan = 1
                    for i=y+1,6 do
                        if masteries[x][i] then
                            td:addClass(pointsClass(masteries[x][i]['points'] or 0, masteries[x][i]['levels'] or 0))
                            break
                        else
                            if i<6 then
                                rowspan = rowspan+2
                            else
                                rowspan = rowspan+1
                            end
                        end
                    end
 
                    if rowspan > 1 then td:attr('rowspan', rowspan) end
                end
            end
        end
    end
    return tab
end
function pointsClass(points, levels)
    if points == 0 then
        return ''
    elseif points == levels then
        return 'all-points'
    elseif points > 0 then
        return 'some-points'
    end
    return ''
end
function ternary(cond, T, F) if cond then return T else return F end end
function arguments(origArgs)
    local args = {}
    for k, v in pairs(origArgs) do
        if type(v) == 'string' then v = mw.text.trim(v) end
        if v ~= '' then args[k] = v end
    end
    return args
end
return Tree

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.