Outward Wiki
No edit summary
No edit summary
 
(35 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
   
function p.main(frame)
+
function p.incense(frame)
 
if frame == mw.getCurrentFrame() then
 
if frame == mw.getCurrentFrame() then
 
args = require('Module:ProcessArgs').merge(true)
 
args = require('Module:ProcessArgs').merge(true)
Line 7: Line 7:
 
frame = mw.getCurrentFrame()
 
frame = mw.getCurrentFrame()
 
end
 
end
 
-- get some implicit args
 
   
local _name = args.name or mw.title.getCurrentTitle().text
+
local name = mw.title.getCurrentTitle().text
local isWeapon = (args.type == 'Weapon' or args.type == 'Bow')
 
   
  +
local fields = '_pageName, name, incense, effects, DLC'
-- get tags
 
  +
local cargoArgs = { orderBy = '_pageName', groupBy = 'name', where = 'incense="' .. name .. '"', limit = 5000 }
 
local data = mw.ext.cargo.query('EnchantRecipes', fields, cargoArgs)
   
  +
return buildhtml(data, frame)
local tags = {}
 
 
end
if args.tags ~= nil then
 
  +
tags = split(args.tags, ',')
 
  +
function p.main(frame)
  +
if frame == mw.getCurrentFrame() then
  +
args = require('Module:ProcessArgs').merge(true)
  +
else
  +
frame = mw.getCurrentFrame()
 
end
 
end
   
 
-- basic cargo query
 
-- basic cargo query
   
local fields = '_pageName, name, slots, tags, items, effects'
+
local fields = '_pageName, name, tags, slots, items, effects, DLC'
  +
local cargoArgs = { orderBy = '_pageName', groupBy = 'name', limit = 5000 }
local args = {
 
  +
local data = mw.ext.cargo.query('EnchantRecipes', fields, cargoArgs)
orderBy = '_pageName'
 
}
 
local data = mw.ext.cargo.query('Enchantments', fields, args)
 
   
  +
-- actual search
-- build list of compatible enchants (too complex for cargo query)
 
local results = {}
+
local results = search(data, args)
local i = 1
 
local debug = ''
 
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
+
if #results < 1 then
 
return '<b>No results found!</b>'
local enchantTags = split(enchant.tags, ',')
 
  +
end
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
 
   
  +
return buildhtml(results, frame)
if enchant.items ~= nil and enchant.items ~= '' then
 
  +
end
local enchantItems = split(enchant.items, ',')
 
for _,item in ipairs(enchantItems) do
 
if _name == item then
 
metItems = true
 
break
 
end
 
end
 
else
 
metItems = true
 
end
 
   
 
-- build list of compatible enchants (too complex for cargo query)
if metTags and metItems then
 
  +
function search(data, args)
-- actually add it to the matches list
 
 
local itemTags = split(args.tags, ',')
results[i] = enchant
 
i = i + 1
+
local results = {}
 
for _,enchant in ipairs(data) do
 
local isCompatible = false
 
  +
-- check for explicit item requirements
  +
if notempty(enchant.items) then
  +
local name = args.name or mw.title.getCurrentTitle().text
 
local items = split(enchant.items, ',')
 
if contains(items, name) then
 
isCompatible = true
 
end
 
end
 
end
 
 
-- check slot and tags
  +
if not isCompatible and notempty(enchant.slots) then
 
local slots = split(enchant.slots, ',')
 
if hasmatch(slots, itemTags) then
 
if notempty(enchant.tags) then
 
local enchTags = split(enchant.tags, ',')
  +
isCompatible = hasmatch(enchTags, itemTags)
 
else
 
isCompatible = true
 
end
 
end
 
end
 
 
-- actually add it to the matches list
 
if isCompatible then
 
table.insert(results, enchant)
 
end
 
end
 
end
 
end
  +
return results
  +
end
   
if #results < 1 then
+
function buildhtml(results, frame)
return '<b>No results found!</b>'
 
end
 
 
 
-- build table output
 
-- build table output
 
local html = mw.html.create()
 
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]]:'))
+
-- removing hatnote for now: {{hatnote|<i>DLC: {{The Soroboreans}} [[The Soroboreans]]</i>}}
  +
html:wikitext(frame:preprocess('<b>{{PAGENAME}}</b> is compatible with the following [[Enchantments]]:'))
   
 
local table = html:tag('table'):addClass('wikitable sortable')
 
local table = html:tag('table'):addClass('wikitable sortable')
Line 101: Line 91:
 
for _,v in ipairs(results) do
 
for _,v in ipairs(results) do
 
local tr = table:tag('tr')
 
local tr = table:tag('tr')
tr:tag('td'):cssText('text-align:center'):wikitext(frame:preprocess('[[' .. v._pageName .. ']]'))
+
tr:tag('td'):cssText('text-align:center'):wikitext(frame:preprocess('[[' .. v._pageName .. '|' .. v.name .. ']]' .. " {{" .. v.DLC .. "}}"))
 
tr:tag('td'):wikitext(frame:preprocess(v.effects))
 
tr:tag('td'):wikitext(frame:preprocess(v.effects))
 
end
 
end
  +
 
 
return html
 
return html
  +
end
  +
  +
----------------------------------------------------------------
  +
--------------------------- HELPERS ----------------------------
  +
  +
function find(tbl, val)
  +
for k, v in pairs(tbl) do
 
if k == val then return v end
 
end
  +
return nil
  +
end
  +
  +
function notempty(string)
  +
return string ~= nil and string ~= ''
  +
end
  +
  +
function hasmatch(table1, table2)
 
for _,v in ipairs(table1) do
  +
if contains(table2, v) then
 
return true
 
end
  +
end
  +
return false
  +
end
  +
  +
function contains(table, value)
 
for _,v in ipairs(table) do
 
if v == value then
 
return true
 
end
  +
end
  +
return false
 
end
 
end
   
Line 113: Line 135:
 
end
 
end
 
local t={}
 
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+
if notempty(inputstr) then
  +
for str in string.gmatch(inputstr .. ',', "([^"..sep.."]+)") do
table.insert(t, str)
+
table.insert(t, str)
 
end
 
end
 
end
 
return t
 
return t

Latest revision as of 18:26, 23 December 2020

Template-info Documentation

Module invoked by Template:UsedInEnchantments.


local p = {}

function p.incense(frame)
    if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
    end

    local name = mw.title.getCurrentTitle().text

    local fields = '_pageName, name, incense, effects, DLC'
    local cargoArgs = { orderBy = '_pageName', groupBy = 'name', where = 'incense="' .. name .. '"', limit = 5000 }
    local data = mw.ext.cargo.query('EnchantRecipes', fields, cargoArgs)

    return buildhtml(data, frame)
end

function p.main(frame)
    if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
    end

    -- basic cargo query

    local fields = '_pageName, name, tags, slots, items, effects, DLC'
    local cargoArgs = { orderBy = '_pageName', groupBy = 'name', limit = 5000 }
    local data = mw.ext.cargo.query('EnchantRecipes', fields, cargoArgs)

    -- actual search
    local results = search(data, args)

    if #results < 1 then
        return '<b>No results found!</b>'
    end

    return buildhtml(results, frame)
end

-- build list of compatible enchants (too complex for cargo query)
function search(data, args)
    local itemTags = split(args.tags, ',')
    local results = {}
    for _,enchant in ipairs(data) do        
        local isCompatible = false
    
        -- check for explicit item requirements
        if notempty(enchant.items) then            
            local name = args.name or mw.title.getCurrentTitle().text
            local items = split(enchant.items, ',')
            if contains(items, name) then
                isCompatible = true
            end
        end
    
        -- check slot and tags
        if not isCompatible and notempty(enchant.slots) then
            local slots = split(enchant.slots, ',')
            if hasmatch(slots, itemTags) then
                if notempty(enchant.tags) then
                    local enchTags = split(enchant.tags, ',')
                    isCompatible = hasmatch(enchTags, itemTags)
                else
                    isCompatible = true
                end            
            end
        end
    
        -- actually add it to the matches list
        if isCompatible then
            table.insert(results, enchant)
        end
    end
    return results
end

function buildhtml(results, frame)
    -- build table output 
    local html = mw.html.create()
    -- removing hatnote for now: {{hatnote|<i>DLC: {{The Soroboreans}} [[The Soroboreans]]</i>}}
    html:wikitext(frame:preprocess('<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 .. '|' .. v.name  .. ']]' .. " {{" .. v.DLC .. "}}"))
        tr:tag('td'):wikitext(frame:preprocess(v.effects))
    end

    return html
end

----------------------------------------------------------------
--------------------------- HELPERS ----------------------------

function find(tbl, val)
    for k, v in pairs(tbl) do
        if k == val then return v end
    end
    return nil
end

function notempty(string)
    return string ~= nil and string ~= ''
end

function hasmatch(table1, table2)
    for _,v in ipairs(table1) do
        if contains(table2, v) then
            return true
        end
    end
    return false
end

function contains(table, value)
    for _,v in ipairs(table) do
        if v == value then
            return true
        end
    end
    return false
end

function split(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={}
    if notempty(inputstr) then
        for str in string.gmatch(inputstr .. ',', "([^"..sep.."]+)") do
            table.insert(t, str)
        end
    end
    return t
end

return p