FANDOM


-- NB: Depends on {{Stats}} and {{Stats 2}}; use {{CharacterStats}} instead of invoking this module directly.
-- <nowiki>
local p = {}
 
local data = mw.loadData('Module:Stats/data')
local ranks = {
    ['S+'] = '6',
    ['S' ] = '6',
    ['S-'] = '6',
    ['A+'] = '5',
    ['A' ] = '5',
    ['A-'] = '5',
    ['B+'] = '4',
    ['B' ] = '4',
    ['B-'] = '4',
    ['C+'] = '3',
    ['C' ] = '3',
    ['C-'] = '3',
    ['D+'] = '2',
    ['D' ] = '2',
    ['D-'] = '2',
    ['E+'] = '1',
    ['E' ] = '1',
    ['E-'] = '1',
    ['?' ] = '?'
}
 
function p.render(frame)
    -- NB: Ideally we'd use the frontier pattern (like `^%f[%u].*%a$`),
    --     but `mw.ustring` is missing the [backport](https://github.com/Wikia/app/pull/15769).
    local full_name = assert(mw.ustring.match(frame.args[1], '^%u.*%a$'))
    local stats = assert(data[full_name])
    assert(type(stats[1]) == 'boolean')
 
    local short_name = stats[1] and assert(mw.ustring.match(full_name, '^[^%s]+')) or full_name
    local fragments = {}
 
    if type(stats[2]) == 'table' then
        local length = 0
        for i, v in ipairs(stats[2]) do
            if i <= 5 then
                assert(mw.ustring.match(stats[2][i], '^[SABCDE?]$'))
            end
            length = length + 1
        end
        assert(length == 5)
        table.insert(fragments, {'Ultra Archive', '{{Stats|character='       .. short_name         ..
                                                         '|power='           .. ranks[stats[2][1]] ..
                                                         '|powergrade='      ..       stats[2][1]  ..
                                                         '|speed='           .. ranks[stats[2][2]] ..
                                                         '|speedgrade='      ..       stats[2][2]  ..
                                                         '|technique='       .. ranks[stats[2][3]] ..
                                                         '|techgrade='       ..       stats[2][3]  ..
                                                         '|intelligence='    .. ranks[stats[2][4]] ..
                                                         '|intgrade='        ..       stats[2][4]  ..
                                                         '|cooperativeness=' .. ranks[stats[2][5]] ..
                                                         '|coopgrade='       ..       stats[2][5]  .. '}}'})
    end
 
    if type(stats[3]) == 'table' then
        local length = 0
        for i, v in ipairs(stats[3]) do
            if i <= 5 then
                assert(mw.ustring.match(stats[3][i], '^[SABCDE][+-]?$') or stats[3][i] == '?')
            end
            length = length + 1
        end
        assert(length == 6)
        assert(mw.ustring.match(stats[3][6], '^%u.*%a$'))
        table.insert(fragments, {'Ultra Analysis', '{{Stats 2|character='    .. short_name         ..
                                                            '|power='        .. ranks[stats[3][1]] ..
                                                            '|powergrade='   ..       stats[3][1]  ..
                                                            '|speed='        .. ranks[stats[3][2]] ..
                                                            '|speedgrade='   ..       stats[3][2]  ..
                                                            '|technique='    .. ranks[stats[3][3]] ..
                                                            '|techgrade='    ..       stats[3][3]  ..
                                                            '|intelligence=' .. ranks[stats[3][4]] ..
                                                            '|intgrade='     ..       stats[3][4]  ..
                                                            '|bonusname='    ..       stats[3][6]  ..
                                                            '|bonus='        .. ranks[stats[3][5]] ..
                                                            '|bonusgrade='   ..       stats[3][5]  .. '}}'})
    end
 
    local wikitext
    if #fragments == 0 then
        return ''
    elseif #fragments == 1 then
        wikitext = fragments[1][2]
    else
        wikitext = '<center><tabber>\n'
        for i, v in ipairs(fragments) do
            wikitext = wikitext .. (i > 1 and '|-|\n' or '') .. v[1] .. '=' .. v[2] .. '\n'
        end
        wikitext = wikitext .. '</tabber></center>'
    end
    return frame:preprocess(wikitext)
end
 
return p
-- </nowiki>
*Disclosure: Some of the links above are affiliate links, meaning, at no additional cost to you, Fandom will earn a commission if you click through and make a purchase. Community content is available under CC-BY-SA unless otherwise noted.

Fandom may earn an affiliate commission on sales made from links on this page.

Stream the best stories.

Fandom may earn an affiliate commission on sales made from links on this page.

Get Disney+