No edit summary |
No edit summary |
||
Line 30: | Line 30: | ||
-- build list of compatible enchants (too complex for cargo query) |
-- build list of compatible enchants (too complex for cargo query) |
||
local results = {} |
local results = {} |
||
− | local i = 1 |
||
− | local debug = '' |
||
for _,enchant in ipairs(data) do |
for _,enchant in ipairs(data) do |
||
Line 43: | Line 41: | ||
isSlot = true |
isSlot = true |
||
elseif args.type == 'Helmet' and slot == 'Helmet' then |
elseif args.type == 'Helmet' and slot == 'Helmet' then |
||
− | + | isSlot = true |
|
end |
end |
||
end |
end |
||
Line 79: | Line 77: | ||
if metTags and metItems then |
if metTags and metItems then |
||
-- actually add it to the matches list |
-- actually add it to the matches list |
||
− | results |
+ | results.insert(1, enchant) |
− | i = i + 1 |
||
end |
end |
||
end |
end |
Revision as of 18:06, 26 June 2020
Module invoked by Template:UsedInEnchantments.
The above documentation is transcluded from Module:UsedInEnchantments/doc. (edit | history)
local p = {}
function p.main(frame)
if frame == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
else
frame = mw.getCurrentFrame()
end
-- get some implicit args
local _name = args.name or mw.title.getCurrentTitle().text
local isWeapon = (args.type == 'Weapon' or args.type == 'Bow')
-- get tags
local tags = {}
if args.tags ~= nil then
tags = split(args.tags, ',')
end
-- basic cargo query
local fields = '_pageName, name, slots, tags, items, effects'
local args = {
orderBy = '_pageName'
}
local data = mw.ext.cargo.query('Enchantments', fields, args)
-- build list of compatible enchants (too complex for cargo query)
local results = {}
for _,enchant in ipairs(data) do
-- see if our slot is compatible
local isSlot = false
local enchantSlots = split(enchant.slots, ',')
for _,slot in ipairs(enchantSlots) do
if isWeapon and slot == 'Weapon' then
isSlot = true
elseif args.type == 'Bow' and slot == 'Bow' then
isSlot = true
elseif args.type == 'Helmet' and slot == 'Helmet' then
isSlot = true
end
end
if isSlot then
local metTags = false
local metItems = false
if enchant.tags ~= nil and enchant.tags ~= '' then
local enchantTags = split(enchant.tags, ',')
for _,tag in ipairs(enchantTags) do
for _,ourTag in ipairs(tags) do
if ourTag == tag then
metTags = true
break
end
end
if metTags then break end
end
else
metTags = true
end
if enchant.items ~= nil and enchant.items ~= '' then
local enchantItems = split(enchant.items, ',')
for _,item in ipairs(enchantItems) do
if _name == item then
metItems = true
break
end
end
else
metItems = true
end
if metTags and metItems then
-- actually add it to the matches list
results.insert(1, enchant)
end
end
end
if #results < 1 then
return '<b>No results found!</b>'
end
-- build table output
local html = mw.html.create()
html:wikitext(frame:preprocess('{{hatnote|<i>DLC: {{The Soroboreans}} [[The Soroboreans]]</i>}}<br><b>{{PAGENAME}}</b> is compatible with the following [[Enchantments]]:'))
local table = html:tag('table'):addClass('wikitable sortable')
local header = table:tag('tr')
header:tag('th'):wikitext('Enchantment')
header:tag('th'):wikitext('Effects')
for _,v in ipairs(results) do
local tr = table:tag('tr')
tr:tag('td'):cssText('text-align:center'):wikitext(frame:preprocess('[[' .. v._pageName .. ']]'))
tr:tag('td'):wikitext(frame:preprocess(v.effects))
end
return html
end
function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
return p