Module:WeaponList
Revision as of 13:13, 22 February 2019 by imported>Elaeagnifolia (Created page with "local Util = require('Module:Util') local p = {} local cargo = mw.ext.cargo function p._weaponList(frame) -- Cargo Query local tables = 'Weapons' local queryFields = "B...")
Documentation for this module may be created at Module:WeaponList/doc
local Util = require('Module:Util')
local p = {}
local cargo = mw.ext.cargo
function p._weaponList(frame)
-- Cargo Query
local tables = 'Weapons'
local queryFields = "BaseId,FormId,_pageName,Name,Rarity,ElementalType,Type,MaxHp,MaxAtk,SkillName,ReleaseDate,Abilities11,Abilities21"
local queryArgs = {
where = 'WeaponName!="Zethia\'s Staff" AND ReleaseDate <= NOW()',
groupBy = '_pageName',
limit = '9999',
orderBy = "CASE ElementalType" ..
"WHEN 'Flame' THEN 1" ..
"WHEN 'Water' THEN 2" ..
"WHEN 'Wind' THEN 3" ..
"WHEN 'Light' THEN 4" ..
"WHEN 'Shadow' THEN 5" ..
"ELSE 6" ..
"END ASC, " ..
"CASE Type" ..
"WHEN 'Sword' THEN 1" ..
"WHEN 'Blade' THEN 2" ..
"WHEN 'Dagger' THEN 3" ..
"WHEN 'Axe' THEN 4" ..
"WHEN 'Lance' THEN 5" ..
"WHEN 'Bow' THEN 6" ..
"WHEN 'Wand' THEN 7" ..
"WHEN 'Staff' THEN 8" ..
"ELSE 0" ..
"END ASC," ..
"Rarity DESC, Id DESC"
}
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')
: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-elemenet', weapon.ElementalType)
:attr('data-rarity', weapon.Rarity)
: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.Name .. ']]' )
-- 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( weapon.Rarity .. frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Weapon',
weapon.Type
}
})
-- Element
tr:tag('td')
:css('text-align', 'left')
:wikitext( weapon.Rarity .. frame:expandTemplate{
title = 'InlineIcon',
args = {
'Icon Element',
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')
: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')
: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')
:wikitext(
frame:expandTemplate{
title = 'AbilityText',
args = {
Id = weapon.Abilities21,
}
}
)
else
tr:tag('td')
:wikitext('-')
end
-- Release Date
tr:tag('td')
:wikitext(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