FANDOM


local S = {}
 
local txt = require('Module:Mw.text')
local json = require('Dev:Json')
local F = require('Module:Funkcje')
 
function S.skill(frame)
    local str = frame.args[1] or ''
    local args = {}
 
    args['Zasięg'] = mw.ustring.match(str, '{%s*lc%s*§%s*Zasięg%s*}%s*([0-9%/%s]+)')
    if args['Zasięg'] then args['Zasięg'] = mw.text.trim(args['Zasięg']) end
    str = mw.ustring.gsub(str, '{%s*lc%s*§%s*Zasięg%s*}%s*([0-9%/%s]+)', '')
 
    local s = txt.esplit(str, '%s*§%s*[%w%s]-%s*=%s*', '%b{}', false, true)
 
    args[1] = mw.ustring.match(s[1], '^%s*§%s*([QWERPBqwerpb])%s*$')
 
    for i=2,#s,2 do
        local k = mw.ustring.match(s[i], '%s*§%s*([%w%s]-)%s*=%s*')
        args[1] = args[1] or mw.ustring.match(s[i+1], '§%s*([QWERPBqwerpb])%s*$')
        local v = mw.text.trim(s[i+1] or '')
        if v and v ~= '' then args[k] = v end
    end
 
    return '\n* Skill:' .. json.encode(args) ..'//:'
end
function S.details(frame)
    local str = frame.args[1] or ''
    local args = {}
    local s = txt.esplit(str, '%s*§%s*[%w%s]-%s*=%s*', '%b{}', false, true)
 
    for i=2,#s,2 do
        local k = mw.ustring.match(s[i], '%s*§%s*([%w%s]-)%s*=%s*')
        local v = mw.text.trim(s[i+1] or '')
        if v and v ~= '' then args[k] = v end
    end
 
    return '\n* Details:' .. json.encode(args) ..'//:'
end
 
local function arg(tab, a, b, empty, prefix)
    local val = mw.text.trim(tab[a] or '')
    if not val or val == '' then val = nil end
    if val or empty then return mw.ustring.format('| %s = %s%s', b or a, val and prefix or '', val or '') end
end
local function templates(str)
    str = txt.split(str, '%b{}', false, true)
    for i,v in ipairs(str) do
        v = mw.ustring.gsub(v, '{lc§(.*)}', '* %1:')
        v = mw.ustring.gsub(v, '{kolor§([^§]*)}', '%1')
        v = mw.ustring.gsub(v, '{ap§([^§]*)§([^§]*)§([^§]*)§([^§]*)§([^§]*)}', '%1/%2/%3/%4/%5')
        v = mw.ustring.gsub(v, '{ap§([^§]*)§([^§]*)§([^§]*)§([^§]*)}', '%1/%2/%3/%4')
        v = mw.ustring.gsub(v, '{ap§([^§]*)§([^§]*)§([^§]*)}', '%1/%2/%3')
        v = mw.ustring.gsub(v, '{ap§([^§]*)§([^§]*)}', '%1/%2')
        v = mw.ustring.gsub(v, '{ap§([^§]*)}', '%1')
        v = mw.ustring.gsub(v, '{ap§?}', '')
 
        if mw.ustring.sub(v, 1, 1) == '{' then
            v = '{' .. v .. '}'
        end
        str[i] = v
    end
    str = table.concat(str, '')
    str = mw.ustring.gsub(str, '§', '|')
    return str
end
local function makeSkill(skill, details)
    local result = {''}
    if skill['1'] then result[1] = '|' .. skill['1'] end
 
    result[#result+1] = arg(skill, 'Nazwa', nil, true)
    result[#result+1] = arg(skill, 'Zasięg', nil, true)
    result[#result+1] = arg(skill, 'Koszt', nil, true)
    result[#result+1] = arg(skill, 'Czas', nil, true)
    result[#result+1] = ''
 
    result[#result+1] = arg(skill, 'Ikona', nil, false)
    result[#result+1] = arg(skill, 'Opis', nil, true)
    result[#result+1] = arg(skill, 'Poziomy', nil, true)
    result[#result+1] = ''
 
    for i=1,20,1 do
        if skill['Opis '..i] then
            result[#result+1] = arg(skill, 'Ikona '..i, nil, false)
            result[#result+1] = arg(skill, 'Opis '..i, nil, true)
            result[#result+1] = arg(skill, 'Poziomy '..i, nil, true)
            result[#result+1] = ''
        end
    end
 
    result[#result+1] = arg(details, 'Celowanie', nil, true, '* ')
    result[#result+1] = arg(details, 'Obrażenia', nil, true)
    result[#result+1] = arg(details, 'Efekty czarów', nil, true)
    result[#result+1] = arg(details, 'Efekty przy trafieniu', nil, true)
    result[#result+1] = arg(details, 'Trafienie krytyczne', nil, true)
    result[#result+1] = arg(details, 'Struktury', nil, true)
    result[#result+1] = arg(details, 'Blokowanie', nil, true)
    result[#result+1] = arg(details, 'Pocisk', nil, true)
    result[#result+1] = arg(details, 'Bariery', nil, true)
    result[#result+1] = arg(details, 'Tarcze czarów', nil, true)
    result[#result+1] = arg(details, 'Dodatkowe informacje', nil, true)
    result[#result+1] = arg(details, 'Film', nil, true)
 
    return '{{Umiejętność2' .. templates(table.concat(result, '\n')) .. '\n}}'
end
 
function S.result(frame)
    local input = tostring(frame.args[1] or '')
    local skills, details = {}, {}
 
    local pattern = '*%s*(%w*):(.-)//:'
    local s, e, t, v = string.find(input, pattern)
    while s do
        mw.log(t, v)
        if t == 'Skill' then
            skills[#skills+1] = json.decode(v)
        elseif t == 'Details' then
            details[#details+1] = json.decode(v)
        end
        s, e, t, v = string.find(input, pattern, e)
    end
 
    local result = {}
    for i,skill in ipairs(skills) do
        mw.log(skill['Nazwa'])
        result[#result+1] = mw.text.nowiki(makeSkill(skill or {}, details[i] or {}))
    end
    return '<pre>' .. table.concat(result, '\n</pre>\n<hr />\n<pre>') .. '</pre>'
end
 
return S

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.