FANDOM


local Champion = require('Module:Champion')
local List = {}
--[[--
{{#invoke: Bohaterowie | kod
| Kod = Kod do sparsowania po podmianie parametrów
| Separator = \n
| Bohaterowie = aktualni, nadchodzący
| Sortuj = A-Z
}}
{{#invoke: Bohaterowie | kod
| Kod = Kod do sparsowania po podmianie parametrów
| Separator = \n
| Bohaterowie = lista
| Sortuj = Z-A
 
| Aatrox
| Quinn
| Ziggs
}}
--]]--
function List.kod(frame)
    local named, numeric = arguments(frame.args, true)
    local code = named['Kod']
 
    local list = getLists(named['Bohaterowie'], numeric, named['Sortuj'])
    local results = {}
 
    for i,v in ipairs(list) do
        local result = Champion.kod(frame, {
            ['Bohater'] = v,
            ['Kod'] = code,
        })
        if v then
            table.insert(results, result)
        end
    end
    local sep = mw.ustring.gsub(named['Separator'] or '', '\\n', '\n') or ''
    return table.concat(results, sep)
end
--[[--
{{#invoke: Bohaterowie | szablon
| Szablon = Template name
| Separator = \n
| Bohaterowie = aktualni, nadchodzący
| Sortuj = A-Z
}}
{{#invoke: Bohaterowie | szablon
| Szablon = Template name
| Separator = \n
| Bohaterowie = lista
| Sortuj = Z-A
 
| Aatrox
| Quinn
| Ziggs
}}
--]]--
function List.szablon(frame)
    local named, numeric = arguments(frame.args, true)
    local template = named['Szablon']
 
    local list = getLists(named['Bohaterowie'], numeric, named['Sortuj'])
    local results = {}
 
    for i,v in ipairs(list) do
        local result = Champion.szablon(frame, {
            ['Bohater'] = v,
            ['Szablon'] = template,
        })
        if v then
            table.insert(results, result)
        end
    end
    local sep = mw.ustring.gsub(named['Separator'] or '', '\\n', '\n') or ''
    return table.concat(results, sep)
end
 
local groups = {'aktualni', 'nadchodzący'}
function getLists(lists, custom, order)
    local result = {}
    if mw.ustring.find(mw.ustring.lower(lists or ''), 'lista', 1, true) then
        for _,v in ipairs(custom) do
            table.insert(result, mw.text.trim(v))
        end
    else
        for _,v in ipairs(groups) do
            if mw.ustring.find(mw.ustring.lower(lists or ''), mw.ustring.lower(v), 1, true) then
                local data = mw.loadData('Module:ChampionList/' .. v)
                for _,v2 in ipairs(data) do
                    table.insert(result, v2)
                end
            end
        end
    end
    order = ord(order)
    if order == 1 then
        table.sort(result)
    elseif order == -1 then
        table.sort(result, function(a,b) return a>b end)
    end
    return result
end
function ord(text)
    return ({
        ['asc'] = 1,
        ['a-z'] = 1,
        ['az'] = 1,
        ['rosnąco'] = 1,
 
        ['desc'] = -1,
        ['z-a'] = -1,
        ['za'] = -1,
        ['malejąco'] = -1,
    })[mw.ustring.lower(text or '')] or ''
end
function arguments(origArgs, separate)
    separate = not not separate
    local named, numeric = {}, {}
    for k, v in pairs(origArgs) do
        if type(v) == 'string' then v = mw.text.trim(v) end
        if v and v ~= '' then
            if not separate then named[k] = v
            elseif k == tonumber(k) then numeric[k] = v
            else named[k] = v
            end
        end
    end
    if separate then return named, numeric else return named end
end
return List

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.