Module:Ammo comparison table

local p = {} local u = require('Module:Util') local i = require('Module:Icons') require('Module:Ammo comparison table/data')

function cells(data, default, modifier, pattern) if u.exists(data) then return data else return default end end

function p.compare(frame) local ammo = frame.args['ammo'] ammo = ammoList[ammo] for k,v in ipairs(ammo) do		if u.exists(v.other) then other = true end end

local legend = mw.html.create('table') :addClass('va-table-collapse mw-collapsible mw-collapsed') :cssText('text-align: left; border: none;') :attr('cellspacing', '0') :attr('cellpadding', '2') :tag('tr') :tag('th') :attr('colspan', '5') :tag('b') :wikitext('Legend') :done :done :done :tag('tr') :tag('td') :wikitext(i.moduleIcons('mag', nil, '', 'Ammunition type', nil, '18px')) :done :tag('td') :wikitext('- Ammunition Type') :tag('td') :wikitext(i.moduleIcons('spread', nil, '', 'Weapons Spread', nil, '18px')) :done :tag('td') :wikitext('Weapon Spread modifer') :done :done :tag('tr') :tag('td') :wikitext(i.moduleIcons('damage', nil, 'Damage', 'Damage Modifier', nil, '18px')) :done :tag('td') :wikitext('- Weapon Damage modifier') :done :tag('td') :wikitext(i.moduleIcons('effect', nil, '', 'Bonus effect', nil, '18px')) :done :tag('td') :wikitext('Ammo bonus effect') :done :done :tag('tr') :tag('td') :wikitext(i.moduleIcons('dt', nil, 'Damage Threshold', 'Damage Threshold modifier', nil, '18px')) :done :tag('td') :wikitext('- Target Damage Threshold modifier') :done :tag('td') :wikitext(i.moduleIcons('craft', nil, 'Fallout: New Vega crafting', 'Craftable', nil, '18px')) :done :tag('td') :wikitext('- Ammo is craftable') :done :done :tag('tr') :tag('td') :wikitext(i.moduleIcons('repair', nil, 'Equipment Condition', 'Condition pentaly', nil, '18px')) :done :tag('td') :wikitext('- Weapon condition modifier') :done :tag('td') :wikitext(i.moduleIcons('chance', nil, '', 'Percentage chance of empty casing', nil, '18px')) :done :tag('td') :wikitext('- Percentage change of empty casing, hull or drained cell/pack/tank') :done :done :done -- Start datatable dataTable = mw.html.create('table') :addClass('va-table va-table-full va-table-center sortable') --Check if any ammo has an other component and add the column if so		if other then otherHead = mw.html.create('th') :wikitext(i.moduleIcons('effect', nil, '', 'Bonus effect', nil, '18px')) :done end -- Set the table header dataHeader = mw.html.create('tr') :tag('tr') :tag('th') :wikitext(i.moduleIcons('mag', nil, '', 'Ammunition type', nil, '18px')) :done :tag('th') :wikitext(i.moduleIcons('damage', nil, '', 'Damage modifer', nil, '18px')) :done :tag('th') :wikitext(i.moduleIcons('dt', nil, 'Damage Threshold', 'Damage Threshold modifier', nil, '18px')) :done :tag('th') :wikitext(i.moduleIcons('repair', nil, 'Equipment condition', 'Condition penalty', nil, '18px')) :done :tag('th') :wikitext(i.moduleIcons('spread', nil, 'Weapons Spread', 'Spread modifier', nil, '18px')) :done :node(otherHead) :tag('th') :wikitext(i.moduleIcons('craft', nil, 'Fallout: New Vegas crafting', 'Craftable', nil, '18px')) :done :tag('th') :wikitext(i.moduleIcons('chance', nil, '', 'Percentage chance of empty casing', nil, '18px')) :done :done --Insert the header into the table. dataTable:node(dataHeader) for k,v in ipairs(ammo) do name = string.gsub(v.name, ',', frame.args['ammo'] .. ',', 1) if u.exists(v.game) then name = name .. ' ' .. i.moduleIcons(v.game, nil, nil, nil, nil, 'x14px') end if u.exists(v.multipliericon) then multiplierIns = i.moduleIcons(v.multipliericon, nil, nil, nil, nil, 'x14px') multiplier = string.gsub(v.multiplier, '', multiplierIns) else multiplier = v.multiplier end dataRow = mw.html.create('tr') :tag('td') :wikitext(cells(name, '', frame.args['ammo'] .. ',', ','))					:done :tag('td') :wikitext(cells(multiplier, 'x 1')) :done :tag('td') :wikitext(cells(v.dtmultiplier, 'x 1')) :done :tag('td') :wikitext(cells(v.condition, 'x 1')) :done :tag('td') :wikitext(cells(v.spread, 'x 1')) :done -- Insert other column if any ammo has a value if other then otherText = cells(v.other, '') if u.exists(v.othericon) then iconIns = i.moduleIcons(v.othericon, nil, nil, nil, nil, 'x14px') otherText = string.gsub(otherText, '', iconIns) end dataRow:tag('td') :wikitext(otherText) :done end --determine if item is craftable and return the correct icon if u.exists(v.craftable) then dataRow:tag('td') :wikitext(i.moduleIcons('yes', nil, '', 'Yes', nil, 'x14px')) :done else dataRow:tag('td') :wikitext(i.moduleIcons('no', nil, '', 'No', nil, 'x14px')) :done end dataRow:tag('td') :wikitext(cells(v.chance, '0') .. '% chance') :done --Insert row into table dataTable:node(dataRow) end return tostring(legend) .. tostring(dataTable)

end

return p