FANDOM


local Champion = {}
--[[--
{{#invoke: Bohater | parametr
| Bohater = Nazwa bohatera
| Parametr = Parametr do zwrócenia
}}
--]]--
function Champion.parametr(frame)
    local args = arguments(frame.args)    
    local s, data = pcall(getData, args['Bohater'])
    if not s then data = {} end
    return flatten(data)[args['Parametr']] or ''
end
--[[--
{{#invoke: Bohater | kod
| Bohater = Nazwa bohatera
| Kod = Kod do sparsowania po podmianie parametrów
| Nadpisz = *
...
}}
--]]--
function Champion.kod(frame, args)
    local invoke, overwrite = {}, {}
    if args then
        invoke = arguments(args)
    else
        invoke = arguments(frame.args)
        if invoke['Nadpisz'] then
            overwrite = arguments(frame:getParent().args, true)
        end
        invoke['Nadpisz'] = nil
    end
 
    local s, data = pcall(getData, invoke['Bohater'])
    if not s then data = { invoke['Bohater'] } end
 
    local code = invoke['Kod']
    invoke['Bohater'] = nil
    invoke['Kod'] = nil
 
    for k,v in pairs(flatten(data, invoke, overwrite)) do
        code = mw.ustring.gsub(code, '%%'..tostring(k)..'%%', tostring(v))
    end
 
    return frame:preprocess(code)
end
--[[--
{{#invoke: Bohater | szablon
| Bohater = Nazwa bohatera
| Szablon = Szablon do wywołania
| Nadpisz = *
...
}}
--]]--
function Champion.szablon(frame, args)
    local invoke, overwrite = {}, {}
    if args then
        invoke = arguments(args)
    else
        invoke = arguments(frame.args)
        if invoke['Nadpisz'] then
            overwrite = arguments(frame:getParent().args, true)
        end
        invoke['Nadpisz'] = nil
    end
 
    local s, data = pcall(getData, invoke['Bohater'])
    if not s then data = { invoke['Bohater'] } end
 
    local template = invoke['Szablon']
    invoke['Bohater'] = nil
    invoke['Szablon'] = nil
 
    local status, result = pcall(function() return frame:expandTemplate{title = template, args = flatten(data, invoke, overwrite)} end)
    if status then return result
    else return '{{' .. tostring(template) .. '}} doesn\'t exist' end
end
 
function getData(champion) return mw.loadData('Module:Champion/' .. tostring(champion)) end
function flatten(data, ...)
    local result = {}
    for k,v in pairs(data) do
        if type(v) == 'table' then
            for k2,v2 in pairs(v) do
                if v2 then
                    result[k..'_'..k2] = v2
                end
            end
        elseif v then
            result[k] = v
        end
    end
    for k,v in pairs({...}) do
        for k2,v2 in pairs(v) do
            if v2 then
                result[k2] = v2
            end
        end
    end
    return result
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
 
 
function Champion.test(frame)
    return (mw.loadData('LoL:Data'))['test']
end
 
return Champion

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.