FANDOM


local Abilities = {}
Abilities.vars = {}
 
function Abilities.tabber(frame)
    local args, indexes = arguments(frame.args)
    local tabber = mw.html.create('div'):addClass('ability-tabber')
    if Abilities.vars['Klasy'] then tabber:addClass(Abilities.vars['Klasy']) end
 
    local default = indexes[1] or 1
    if Abilities.vars['Domyślna'] ~= nil then
        Abilities.vars['Domyślna'] = tonumber(Abilities.vars['Domyślna'])
        for i,v in ipairs(indexes) do
            if Abilities.vars['Domyślna'] == v then
                default = v
                break
            end
        end
    end
    tabber:attr('data-current', default)
 
    local tabs = tabber:tag('div'):addClass('ability-tabber-tabs')
    local contents = tabber:tag('div'):addClass('ability-tabber-contents')
    for _,index in ipairs(indexes) do
        local entry = args[index]
 
        local tab = tabs:tag('div'):addClass('ability-tab'):attr('data-no', index):css('width', Abilities.vars['Rozmiar'] or '64px'):css('height', Abilities.vars['Rozmiar'] or '64px')
        local icon = tab:tag('div'):addClass('ability-tab-icon')
        local content = contents:tag('div'):addClass('ability-content'):attr('data-no', index):wikitext(entry['Opis'] or '')
        if entry['Klasy karty'] then tab:addClass(entry['Klasy karty']) end
        if entry['Klasy opisu'] then content:addClass(entry['Klasy opisu']) end
 
        if entry['Nazwa'] then
            tab:tag('div'):addClass('ability-tab-name'):tag('div'):wikitext(entry['Nazwa'])
            tab:attr('id', 'ab-' .. mw.uri.anchorEncode(entry['Nazwa']))
            content:attr('data-id', mw.uri.anchorEncode(entry['Nazwa']))
            icon:wikitext(mw.ustring.format('[[File:%s|%s|%s|link=#%s]]', entry['Ikona'], Abilities.vars['Rozmiar'] or '64px', entry['Nazwa'], entry['Nazwa']))
        else
            tab:attr('id', 'ab-a' .. index)
            content:attr('data-id', 'a' .. index)
            icon:wikitext(mw.ustring.format('[[File:%s|%s||link=#a%s]]', entry['Ikona'], Abilities.vars['Rozmiar'] or '64px', index))
        end
        if entry['Etykieta'] then
            tab:tag('div'):addClass('ability-tab-label'):wikitext(entry['Etykieta'])
        end
 
        if default == index then
            tab:addClass('current')
            content:addClass('current')
        end
    end
    return tabber
end
function arguments(origArgs)
    local args = {}
    local indexes = {}
    for k, v in pairs(origArgs) do
        local value = mw.text.trim(tostring(v))
        if value ~= '' then
            local keySplit = mw.text.split( tostring(k), ":" )
            local index  = tonumber(mw.text.trim(keySplit[1]))
            local key    = tostring(mw.text.trim(keySplit[2]))
            if index > 0 then
                if args[index] == nil then 
                    args[index] = {}
                end
                args[index][key] = value
            elseif index == 0 then
                Abilities.vars[key] = value
            end
        end
    end
    for index, v in pairs(args) do
        if v['Ikona'] then
            table.insert(indexes, index)
        else
            args[index] = nil
        end
    end
    table.sort(indexes)
    return args, indexes
end
function ternary(cond, T, F)
    if cond then return T else return F end
end
return Abilities

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.