Module:WeaponList
Revision as of 15:12, 13 January 2020 by imported>LikableBrute (checking to see if this helps with page load times)
Documentation for this module may be created at Module:WeaponList/doc
local p = {}
local cargo = mw.ext.cargo
function p._weaponList(frame)
-- Cargo Query
local tables = 'Weapons'
local queryFields = "BaseId,FormId,_pageName,WeaponName,Rarity,Availability,ElementalType,Type,MaxHp,MaxAtk,SkillName,ReleaseDate,Abilities11,Abilities21"
local queryArgs = {
where = 'WeaponName!="Zethia\'s Staff" AND ReleaseDate <= NOW()',
groupBy = '_pageName',
limit = '100',
orderBy = "AvailabilityId ASC, Rarity DESC, ElementalTypeId ASC, TypeId ASC, Id DESC, WeaponName ASC"
}
local queryResult = cargo.query(tables, queryFields, queryArgs)
if queryResult == nil then
return "(no values)"
end
-- Initialize the table
local tbl = mw.html.create('table')
:addClass('wikitable sortable center')
:css('text-align','center')
:css('width','100%')
-- Table headers
tbl:tag('th')
:wikitext('Icon')
:addClass('unsortable')
tbl:tag('th')
:wikitext('Name')
tbl:tag('th')
:wikitext('Rarity')
tbl:tag('th')
:wikitext('Type')
tbl:tag('th')
:wikitext('Element')
tbl:tag('th')
:wikitext('HP')
tbl:tag('th')
:wikitext('Str')
tbl:tag('th')
:wikitext('Skills')
tbl:tag('th')
:wikitext('Ability 1')
tbl:tag('th')
:wikitext('Ability 2')
tbl:tag('th')
:wikitext('Release date')
:css('width', '12%')
if type( queryResult ) == "table" then
-- Go through all the weapons in the query result
for _, weapon in ipairs(queryResult) do
local tr = tbl:tag('tr')
tr:addClass('character-grid-entry')
:addClass('grid-entry')
:attr('data-weapon', weapon.Type)
:attr('data-element', weapon.ElementalType)
:attr('data-rarity', weapon.Rarity)
:attr('data-availability', weapon.Availability)
:attr('data-weapon-group', getWeaponGroup(weapon))
-- Icon
tr:tag('td')
:wikitext('[[File:' .. weapon.BaseId .. ' 01 ' .. weapon.FormId .. '.png|60px|link=' .. weapon._pageName .. ']]')
-- Weapon Name
tr:tag('td')
:wikitext( '[[' .. weapon._pageName .. '|' .. weapon.WeaponName .. ']]' )
-- Rarity
tr:tag('td')
:wikitext( weapon.Rarity .. ' ' .. frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Rarity',
weapon.Rarity
}
})
-- Type
tr:tag('td')
:css('text-align', 'left')
:wikitext( frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Weapon',
weapon.Type
}
} .. ' ' .. weapon.Type )
-- Element
tr:tag('td')
:css('text-align', 'left')
:wikitext( frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Element',
weapon.ElementalType
}
} .. ' ' .. weapon.ElementalType )
-- HP
tr:tag('td'):wikitext(weapon.MaxHp):done()
-- Str
tr:tag('td'):wikitext(weapon.MaxAtk):done()
-- Skill
if (weapon.SkillName ~= 'nil' and weapon.SkillName ~= '') then
tr:tag('td')
:css('text-align', 'left')
:wikitext(
frame:expandTemplate{
title = 'SkillText',
args = {
Name = weapon.SkillName,
Level = '1'
}
} .. '<br/>' ..
frame:expandTemplate{
title = 'SkillText',
args = {
Name = weapon.SkillName,
Level = '2'
}
}
)
else
tr:tag('td')
:wikitext('-')
end
-- Ability 1
if (weapon.Abilities11 ~= 'nil' and weapon.Abilities11 ~= '' and weapon.Abilities11 ~= '0') then
tr:tag('td')
:css('text-align', 'left')
:wikitext(
frame:expandTemplate{
title = 'AbilityText',
args = {
Id = weapon.Abilities11,
}
}
)
else
tr:tag('td')
:wikitext('-')
end
-- Ability 2
if (weapon.Abilities21 ~= 'nil' and weapon.Abilities21 ~= '' and weapon.Abilities21 ~= '0') then
tr:tag('td')
:css('text-align', 'left')
:wikitext(
frame:expandTemplate{
title = 'AbilityText',
args = {
Id = weapon.Abilities21,
}
}
)
else
tr:tag('td')
:wikitext('-')
end
-- Release Date
tr:tag('td')
:wikitext(
frame:expandTemplate{
title = 'ModuleReleaseDate',
args = {
Date = weapon.ReleaseDate,
}
}
)
end
return tostring(tbl)
end
end
function getWeaponGroup(weapon)
if (weapon.Abilities11 ~= 'nil' and weapon.Abilities11 ~= '' and weapon.Abilities11 ~= '0') then
return 'void'
end
return 'standard'
end
function p.weaponList(frame)
return p._weaponList(frame)
end
return p