FANDOM


local p = {}
 
local mods = mw.loadData( 'Module:Mods/mods' )
local guns = mw.loadData( 'Module:Mods/guns' )
 
local mod_table = [[<table class="va-table va-table-full-infobox va-table-center">
<tr>
<th colspan = "4">Weapon Modifications</th>
</tr>
<tr>
<th rowspan= "1">Name</th>
<th rowspan= "1">Effects</th>
<th rowspan= "1">Value</th>
<th rowspan= "1">Base ID</th>
</tr>]]
 
--
-- join_table - joins a table with ,'s
--
-- parameter [table] table - list of values to join
--
-- returns [string] - joined values
--
function join_table( table )
    local str = ''
    for k,v in ipairs( table ) do
        str = str .. v .. ', '
    end
 
    return str:match( "(.*), " )
end
 
--
-- list_verbose - generates verbose list entries
--
-- parameter [string] name - mod name
-- parameter [table] effects - list of effects for the mod
--
-- returns [string] - fully generated HTML list
--
function list_verbose( name, effects )
    local entry = "[[" .. name .. "]] - "
 
    for k,v in ipairs( effects ) do
        local op, val, skill = v:match( "([%+%-])(%d+) (.*)" )
 
        mw.log( op )
 
        if op == '+' then
            entry = entry .. 'adds ' .. val .. ' points to ' .. skill .. ', '
        elseif op == '-' then
            entry = entry .. 'reduces ' .. skill .. ' by ' .. val .. ' points, '
        end
    end
 
    return entry:match( "(.*), " )
end
 
--
-- generate_list - generates an HTML list
--
-- parameter [table] modifications - list of mod info for the weapon
-- parameter [bool] verbose - generate verbose entries
--
-- returns [string] - fully generated HTML list
--
function generate_list( modifications, verbose )
    local list = "<ul>\n"
 
    for key,value in ipairs( modifications ) do
        if verbose then
            list = list .. "<li>" .. list_verbose( value['name'], value['mods']['effects'] ) .. "\n"
        else
            list = list .. "<li>[[" .. value['name'] .. "]]\n"
        end
    end
 
    list = list .. '</ul>'
 
    return list
end
 
--
-- generate_table - generates an HTML table
--
-- parameter [table] modifications - list of mod info for the weapon
--
-- returns [string] - fully generated HTML table
--
function generate_table( modifications )
    for key,value in ipairs( modifications ) do
        mod_table = mod_table .. '<tr>'
 
        if value['name'] == 'INVALID' then
            mod_table = '<td>ERROR</td><td>ERROR</td><td>ERROR</td><td>ERROR</td></tr><tr>'
        else
            mod_table = mod_table .. '<td>[[' .. value['name'] .. ']]</td>'
            mod_table = mod_table .. '<td>' .. join_table( value['mods']['effects'] ) .. '</td>'
            mod_table = mod_table .. '<td>' .. value['mods']['value'] .. '</td>'
            mod_table = mod_table .. '<td><code>' .. value['mods']['base id'] .. '</code></td>'
        end
 
        mod_table = mod_table .. '</tr>'
    end
 
    mod_table = mod_table .. '</table>'
 
    return mod_table
end
 
--
-- parse_modifications - returns information on individual mods
--
-- parameter [string] mod - information about the mod to get
--
-- returns [table] - mod information
--
function parse_modification( mod )
    local type, name = mod:match( "([^:]+):([^:]+)" )
 
    if mods[type] then
        if mods[type][name] then
            return { ['name'] = name, ['mods'] = mods[type][name] }
        else
            return { ['name'] = 'INVALID' }
        end
    else
        return { ['name'] = 'INVALID' }
    end
end
 
--
-- get_modifications - grabs and assembles a table based on a weapons mods
--
-- parameter [table] weapon - list of mods for the weapon
--
-- returns [string] - fully generated HTML table
--
function get_modifications( weapon )
    local modifications = {}
 
    for key,value in ipairs( weapon ) do
        modifications[key] = parse_modification( value )
    end
 
    return modifications
end
 
--
-- p.list - entry point for mod list generation
--
-- parameters [table] frame - all arguments
--
-- returns [string] - fully generated HTML list
--
function p.list( frame )
    local type, gun = tostring( frame.args[1] ), tostring( frame.args[2] )
 
    if guns[type] then
        if guns[type][gun] then
            modifications = get_modifications( guns[type][gun] )
            return frame:preprocess( generate_list( modifications, false ) )
        else
            return 'Invalid query: gun "' .. gun .. '" does not exist'
        end
    else
        return 'Invalid query: type "' .. type .. '" does not exist'
    end
end
 
--
-- p.listv - entry point for verbose mod list generation
--
-- parameters [table] frame - all arguments
--
-- returns [string] - fully generated HTML list
--
function p.listv( frame )
    local type, gun = tostring( frame.args[1] ), tostring( frame.args[2] )
 
    if guns[type] then
        if guns[type][gun] then
            modifications = get_modifications( guns[type][gun] )
            return frame:preprocess( generate_list( modifications, true ) )
        else
            return 'Invalid query: gun "' .. gun .. '" does not exist'
        end
    else
        return 'Invalid query: type "' .. type .. '" does not exist'
    end
end
 
--
-- p.table - entry point for mod table generation
--
-- parameters [table] frame - all arguments
--
-- returns [string] - fully generated HTML table
--
function p.table( frame )
    local type, gun = tostring( frame.args[1] ), tostring( frame.args[2] )
 
    if guns[type] then
        if guns[type][gun] then
            modifications = get_modifications( guns[type][gun] )
            return frame:preprocess( generate_table( modifications ) )
        else
            return 'Invalid query: gun "' .. gun .. '" does not exist'
        end
    else
        return 'Invalid query: type "' .. type .. '" does not exist'
    end
end
 
return p

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.