Module:WeaponListDiv
Jump to navigation
Jump to search
Documentation for this module may be created at Module:WeaponListDiv/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 = '9999',
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 container = mw.html.create('div')
:addClass('weapon-list-container')
-- Table headers
container:tag('div')
:wikitext('Icon')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Name')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Rarity')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Type')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Element')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('HP')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Str')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Skills')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Ability 1')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Ability 2')
:addClass('weapon-list-header')
container:tag('div')
:wikitext('Release date')
:addClass('weapon-list-header')
if type( queryResult ) == "table" then
-- Go through all the weapons in the query result
for _, weapon in ipairs(queryResult) do
local weaponDiv = container:tag('div')
weaponDiv:addClass('weapon-list-element')
: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
weaponDiv:tag('div')
:wikitext('[[File:' .. weapon.BaseId .. ' 01 ' .. weapon.FormId .. '.png|60px|link=' .. weapon._pageName .. ']]')
:addClass('weapon-icon')
-- Weapon Name
weaponDiv:tag('div')
:wikitext( '[[' .. weapon._pageName .. '|' .. weapon.WeaponName .. ']]' )
:addClass('weapon-name')
-- Rarity
weaponDiv:tag('div')
:wikitext( weapon.Rarity .. ' ' .. frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Rarity',
weapon.Rarity
}
})
:addClass('weapon-rarity')
-- Type
weaponDiv:tag('div')
:wikitext( frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Weapon',
weapon.Type
}
} .. ' ' .. weapon.Type )
:addClass('weapon-type')
-- Element
weaponDiv:tag('div')
:wikitext( frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Element',
weapon.ElementalType
}
} .. ' ' .. weapon.ElementalType )
:addClass('weapon-element')
-- HP
weaponDiv:tag('div'):wikitext(weapon.MaxHp):addClass('weapon-hp'):done()
-- Str
weaponDiv:tag('div'):wikitext(weapon.MaxAtk):addClass('weapon-str'):done()
-- Skill
if (weapon.SkillName ~= 'nil' and weapon.SkillName ~= '') then
weaponDiv:tag('div')
:wikitext(
frame:expandTemplate{
title = 'SkillText',
args = {
Name = weapon.SkillName,
Level = '1'
}
} .. '<br/>' ..
frame:expandTemplate{
title = 'SkillText',
args = {
Name = weapon.SkillName,
Level = '2'
}
}
)
:addClass('weapon-skill')
else
weaponDiv:tag('div')
:wikitext('-')
:addClass('weapon-skill')
end
-- Ability 1
if (weapon.Abilities11 ~= 'nil' and weapon.Abilities11 ~= '' and weapon.Abilities11 ~= '0') then
weaponDiv:tag('div')
:wikitext(
frame:expandTemplate{
title = 'AbilityText',
args = {
Id = weapon.Abilities11,
}
}
)
:addClass('weapon-ability')
else
weaponDiv:tag('div')
:wikitext('-')
:addClass('weapon-ability')
end
-- Ability 2
if (weapon.Abilities21 ~= 'nil' and weapon.Abilities21 ~= '' and weapon.Abilities21 ~= '0') then
weaponDiv:tag('div')
:wikitext(
frame:expandTemplate{
title = 'AbilityText',
args = {
Id = weapon.Abilities21,
}
}
)
:addClass('weapon-ability')
else
weaponDiv:tag('div')
:wikitext('-')
:addClass('weapon-ability')
end
-- Release Date
weaponDiv:tag('div')
:wikitext(
frame:expandTemplate{
title = 'ModuleReleaseDate',
args = {
Date = weapon.ReleaseDate,
}
}
)
:addClass('weapon-release-date')
end
return tostring(container)
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