FANDOM


local Skill = {}
 
local getArgs = require('Module:Translate').getArgs
local abilityIcon = require('Module:Filename').ability
local t2a = require('Module:Funkcje').table2array
local T = require('Module:Tekstowe')
local color = T.color
local progression = T.progression
local decimals = T.decimals
 
local function formatProgression(text)
    text = text or ''
    local s, e = mw.ustring.find(text, '[0-9][0-9%.,]*%s*/[0-9%.,/%s]*[0-9]')
    while s do
        local str = '<span class="progression">' .. progression(mw.ustring.sub(text, s, e)) .. '</span>'
        text = (s-1>1 and mw.ustring.sub(text, 1, s-1) or '') .. str .. mw.ustring.sub(text, e+1)
        s, e = mw.ustring.find(text, '[0-9][0-9%.,]*%s*/[0-9%.,/%s]*[0-9]', s+mw.ustring.len(str))
    end
    return text
end
local function formatHeader(text)
    text = text or ''
    -- Formatowanie poziomów
    text = formatProgression(text)
    -- Małe liczby po przecinach
    text = decimals(text)
    return text
end
local function formatDesc(text)
    text = text or ''
    -- Małe liczby po przecinach
    text = decimals(text)
    -- Kolorowanie nawiasów
    text = color(text)
    return text
end
local function formatLevels(text)
    text = text or ''
    -- Wyróżnienie etykiet na liście
    text = mw.ustring.gsub(text, '%*%s*([^:^<^>]-):%s*', '* <strong class="skill-label">%1:</strong> ')
    -- Formatowanie poziomów
    text = formatProgression(text)
    -- Małe liczby po przecinach
    text = decimals(text)
    -- Kolorowanie nawiasów
    text = color(text)
    return text
end
local function makeIcon(file, size)
    size = tonumber(size) or 64
    local icon = mw.title.makeTitle('File', file)
    if icon.fileExists then
        return '[[' .. icon.prefixedText .. '|'..size..'px]]'
    else
        return '[[File:' .. abilityIcon{} .. '|'..size..'px|link=' .. mw.site.server .. '/wiki/Special:Upload?wpDestFile=' .. mw.uri.encode(icon.text) .. ']]'
    end
end
local function makeSkill(opt)
    if opt.name then
        local box = mw.html.create('div')
 
        box:addClass('skill')
           :attr('id', mw.uri.anchorEncode(opt.name))
 
        local header = box:tag('div') :addClass('skill-header')
 
        local h3 = header:tag('h3') :wikitext(opt.name .. ' ')
        if opt.tip then h3:tag('span'):addClass('tip'):wikitext('<small>(' .. opt.tip .. ')</small>') end
 
        local proplist = {}
        if opt.range then
            proplist[#proplist+1] = {
                'Zasięg',
                opt.range
            }
        end
        if opt.cost then
            proplist[#proplist+1] = {
                'Koszt',
                opt.cost
            }
        end
        if opt.cooldown then
            proplist[#proplist+1] = {
                '<span title="Czas odnowienia">Czas</span>',
                opt.cooldown
            }
        end
        if opt.extra1 then
            proplist[#proplist+1] = mw.text.split(opt.extra1, ':')
        end
        if opt.extra2 then
            proplist[#proplist+1] = mw.text.split(opt.extra2, ':')
        end
 
        if #proplist then
            local props = header:tag('div'):addClass('skill-props')
            for i,v in ipairs(proplist) do
                local label, text
                if #v > 1 then label = mw.text.trim(table.remove(v, 1) or '') end
                text = mw.text.trim(table.concat(v, ':') or '')
 
                if text ~= '' then
                    if i > 1 then props:wikitext(' <b>·</b> ') end
 
                    local e = props:tag('span')
                    e:addClass('infobox-builder-go-to-source-tooltip-text') -- has only nowrap in Mercury
                    if label and label ~= '' then
                        e:tag('strong')
                         :addClass('skill-label')
                         :wikitext(label ..':')
                    end
                    e:wikitext(' ' .. formatHeader(text))
                end
            end
        end
 
        for i,v in ipairs(opt.rows) do
            local row = box:tag('div'):addClass('skill-row')
            if v.icon then
                row:tag('div')
                   :addClass('skill-icon')
                   :wikitext(makeIcon(v.icon, i==1 and 64 or 60))
            end
            row:tag('div')
               :addClass('skill-desc')
               :newline()
               :wikitext(formatDesc(v.desc))
               :newline()
            if v.levels then
                row:tag('div')
                   :addClass('skill-levels')
                   :newline()
                   :wikitext(formatLevels(v.levels))
                   :newline()
            else
                row:addClass('no-levels')
            end
        end
        --¶
 
        return box
    end
end
local detailsData
local function details(key, group)
    detailsData = detailsData or mw.loadData('Module:Skill/details')
 
    group = mw.ustring.lower(tostring(group))
    key = detailsData['keys'][mw.ustring.lower(tostring(key))]
 
    if not key or not detailsData[group] then return nil end
    return detailsData[group][key] or key
end
 
local function makeDetails(opt)
    if not (opt['aiming'] or opt['dmg'] or opt['spelleffects'] or opt['onhiteffects'] or opt['barriers'] or opt['moreinfo'] or opt['video']) then return nil end
 
    local box = mw.html.create('div'):addClass('skill-more mw-collapsible')
    if not opt['expanded'] then box:addClass('mw-collapsed') end
    local toggle = box:tag('h4')
    toggle:addClass('mw-collapsible-toggle')
          :wikitext('Szczegóły')
          :attr('data-expandtext', 'Pokaż')
          :attr('data-collapsetext', 'Ukryj')
    local content = box:tag('div'):addClass('mw-collapsible-content')
 
    local sec = {}
    if opt['aiming'] then
        sec[#sec+1] = {
            label = 'Celowanie',
            text = opt['aiming'] or 'Wymagane informacje o celowaniu.',
        }
    end
    if opt['dmg'] then
        sec[#sec+1] = {
            label = 'Obrażenia',
            text = opt['dmg'],
        }
    end
    if opt['spelleffects'] then
        sec[#sec+1] = {
            label = 'Efekty czarów',
            text = opt['spelleffects'],
        }
    end
    if opt['onhiteffects'] then
        sec[#sec+1] = {
            label = 'Efekty przy trafieniu',
            text = opt['onhiteffects'],
        }
    end
    if opt['shields'] then
        sec[#sec+1] = {
            label = 'Tarcze czarów',
            text = opt['shields'],
        }
    end
    if opt['barriers'] then
        sec[#sec+1] = {
            label = 'Bariery',
            text = opt['barriers'],
        }
    end
    if opt['moreinfo'] then
        sec[#sec+1] = {
            label = 'Dodatkowe informacje',
            text = opt['moreinfo'],
        }
    end
    if opt['video'] then
        sec[#sec+1] = {
            text = '[[File:' .. opt['video'] .. '|center|520px]]',
        }
    end
 
    for i,v in ipairs(sec) do
        local dl = content:tag('dl'):addClass('skill-more-details')
        if v.label then
            dl:tag('dt'):addClass('skill-more-label'):wikitext(v.label)
        end
        dl:tag('dd')
          :newline()
          :wikitext(v.text)
    end
    return box
end
local function prepSkills(args)
    local list = {}
    local props = {'champ','name','range','cooldown','cost','extra1','extra2','barriers','aiming','moreinfo','shields','dmg','spelleffects','onhiteffects','video','expanded'}
 
    for no,prefix in ipairs({'f_', 's_'}) do
        if args[prefix..'desc0'] then
            args[prefix..'desc'][0] = args[prefix..'desc0']
            args[prefix..'desc0'] = nil
        end
        if args[prefix..'icon0'] then
            args[prefix..'icon'][0] = args[prefix..'icon0']
            args[prefix..'icon0'] = nil
        end
        if args[prefix..'levels0'] then
            args[prefix..'levels'][0] = args[prefix..'levels0']
            args[prefix..'levels0'] = nil
        end
 
        local obj = {}
        obj.rows = t2a(args:group(prefix..'desc', {prefix..'icon', prefix..'levels'}))
 
        if #obj.rows then
            for i,v in ipairs(obj.rows) do
                v['desc'] = v[prefix..'desc']
                v[prefix..'desc'] = nil
                v['levels'] = v[prefix..'levels']
                v[prefix..'levels'] = nil
                v['icon'] = v[prefix..'icon']
                v[prefix..'icon'] = nil
            end
            for i,v in ipairs(props) do
                local k = prefix .. v
                if args[k] and args[k] ~= '' then
                    obj[v] = args[k]
                end
            end
            if not obj.champ and no > 1 then obj.champ = list[1] and list[1].champ or nil end
            if obj.name and #obj.rows > 0 then table.insert(list, obj) end
        end
    end
    return list
end
 
-- #invokeable
function Skill.create(frame)
    local args = getArgs(frame, {
        translate = {
            f_champ        = 'Bohater',
            f_name         = 'Nazwa',
            f_range        = 'Zasięg',
            f_cooldown     = 'Czas',
            f_cost         = 'Koszt',
            f_extra1       = 'Dodatkowe 1',
            f_extra2       = 'Dodatkowe 2',
 
            f_icon0        = 'Ikona',
            f_desc0        = 'Opis',
            f_levels0      = 'Poziomy',
            f_icon         = 'Ikona #',
            f_desc         = 'Opis #',
            f_levels       = 'Poziomy #',
 
            f_barriers     = 'Bariery',
            f_aiming       = 'Celowanie',
            f_moreinfo     = 'Dodatkowe informacje',
            f_shields      = 'Tarcze czarów',
            f_dmg          = 'Obrażenia',
            f_spelleffects = 'Efekty czarów',
            f_onhiteffects = 'Efekty przy trafieniu',
            f_video        = 'Film',
            f_expanded     = 'Rozwinięty',
 
 
            s_champ        = 'Druga/Bohater',
            s_name         = 'Druga/Nazwa',
            s_range        = 'Druga/Zasięg',
            s_cooldown     = 'Druga/Czas',
            s_cost         = 'Druga/Koszt',
            s_extra1       = 'Druga/Dodatkowe 1',
            s_extra2       = 'Druga/Dodatkowe 2',
 
            s_icon0        = 'Druga/Ikona',
            s_desc0        = 'Druga/Opis',
            s_levels0      = 'Druga/Poziomy',
            s_icon         = 'Druga/Ikona #',
            s_desc         = 'Druga/Opis #',
            s_levels       = 'Druga/Poziomy #',
 
            s_barriers     = 'Druga/Bariery',
            s_aiming       = 'Druga/Celowanie',
            s_moreinfo     = 'Druga/Dodatkowe informacje',
            s_shields      = 'Druga/Tarcze czarów',
            s_dmg          = 'Druga/Obrażenia',
            s_spelleffects = 'Druga/Efekty czarów',
            s_onhiteffects = 'Druga/Efekty przy trafieniu',
            s_video        = 'Druga/Film',
            s_expanded     = 'Druga/Rozwinięty',
        },
        parentFirst = true,
    })
 
    local skills = prepSkills(args)
    if #skills == 0 then return end
 
    local box = mw.html.create('div'):addClass('skillbox')
    local key = mw.ustring.lower(args[1] or '')
    if key == 'p' then
        key = 'Bierna'
        box:addClass('skill-passive')
           :attr('id', key)
    elseif key == 'q' or key == 'w' or key == 'e' or key == 'r' then
        box:addClass('skill-'..key)
        key = mw.ustring.upper(key)
        box:attr('id', key)
    end
 
    for i,v in ipairs(skills) do
        v.tip = key
        if v.rows[1].icon == nil then
            v.rows[1].icon = abilityIcon{v.champ, v.name}
        end
        box:node(makeSkill(v))
        box:node(makeDetails(v))
    end
    return box
end
return Skill

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.