Module:Weapons

-- local p = {}

local data = require("Module:Weapons/Data")

- Weapon Infobox - local infobox_template = [=[

]=]

function p.Infobox(frame) local weapon_name = frame.args[1] or mw.title.getCurrentTitle.text local weapon = data.weapons[weapon_name] if weapon == nil then return "Weapon infobox data not found for \"" .. weapon_name .. "\". Check the parameter or add the data to Module:Weapons/Data." end local category = "" return frame:preprocess(string.format(infobox_template, weapon_name, weapon_name, weapon.Class or "", weapon.Damage.Common or "-", weapon.Damage.Rare or "-", weapon.Damage.Epic or "-", weapon.Damage.Legendary or "-", weapon.Reload or "", weapon.Magsize or "", weapon.Firerate or "", weapon.Description, category )) end

- Weapon List - function WeaponList local weapons = {} for weapon_name, weapon in pairs(data.weapons) do   weapon.Name = weapon_name table.insert(weapons, weapon) end table.sort(weapons, function(a, b) return a.Name < b.Name end) return weapons end

- Weapon Table (Any class) - local weapons_table_head = [=[ {| class="article-table sortable" style="text-align:center;font-size:75%" width="100%" ! style="text-align:center" class="unsortable" | Icon ! style="text-align:center" | Weapon ! style="text-align:center" data-sort-type="number" | Reload Time ! style="text-align:center" data-sort-type="number" | Magsize ! style="text-align:center" data-sort-type="number" | Firerate ! style="text-align:center" data-sort-type="number" | Damage ]=]

local weapons_table_row = [=[ ]=]
 * Weapon_%s.png
 * %s
 * data-sort-value="%s" | %s
 * data-sort-value="%s" | %s
 * %s
 * %s / %s / %s / %s
 * %s / %s / %s / %s

function p.List(frame) local list = weapons_table_head for _, weapon in pairs(WeaponList) do   if weapon.Class == nil then list = list .. string.format(weapons_table_row,       weapon.Name,        weapon.Name,        weapon.Name,        weapon.Reload or 0,        weapon.Reload or "-",        weapon.Magsize == "∞" and 999 or weapon.Magsize,        weapon.Magsize or "-",        weapon.Firerate or "-",        weapon.Damage.Common or "-",        weapon.Damage.Rare or "-",        weapon.Damage.Epic or "-",        weapon.Damage.Legendary or "-"      ) end end list = list .. "|}" return list end

- Weapon Table (Class specific) - local weapons_class_table_head = [=[ {| class="article-table sortable" style="text-align:center;font-size:75%" width="100%" ! style="text-align:center" class="unsortable" | Icon ! style="text-align:center" | Weapon ! style="text-align:center" | Class ! style="text-align:center" data-sort-type="number" | Reload Time ! style="text-align:center" data-sort-type="number" | Magsize ! style="text-align:center" data-sort-type="number" | Firerate ! style="text-align:center" data-sort-type="number" | Damage ]=]

local weapons_class_table_row = [=[ ]=]
 * Weapon_%s.png
 * %s
 * %s
 * data-sort-value="%s" | %s
 * data-sort-value="%s" | %s
 * %s
 * %s
 * %s

function p.ListClass(frame) local list = weapons_class_table_head for _, weapon in pairs(WeaponList) do   if weapon.Class ~= nil then list = list .. string.format(weapons_class_table_row,       weapon.Name,        weapon.Name,        weapon.Name,        weapon.Class,        weapon.Reload or 0,        weapon.Reload or "-",        weapon.Magsize == "∞" and 999 or weapon.Magsize,        weapon.Magsize or "-",        weapon.Firerate or "-",        weapon.Damage.Legendary      ) end end list = list .. "|}" return list end

return p --