Module:Weapon

-- NOTICE: --    PLEASE DO NOT EDIT THIS MODULE OR IT'S SUBPAGES --    WITHOUT FIRST ASKING USER:SHINING-ARMOR -- --    THIS MODULE IS STILL BEING ADAPTED TO PRODUCTION USE --    PLEASE BE PATIENT AND DO NOT USE ON WIKI PAGES YET

local p = {}

local mods = mw.loadData( 'Module:Weapon/mods' ) local guns = mw.loadData( 'Module:Weapon/guns' )

local mod_table = [[ '       end        mod_table = mod_table .. ' '    end    mod_table = mod_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