Outward Wiki
Advertisement
Template-info.png Documentation

Lua module used by UsedInCombos Template and SkillCombinations Template to list skill combinations.

Takes a name argument, which is used as a filter for the result (either one of the combo steps, or the prereq).

  • If name is blank, it will list all combos.

local p = {}

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

    local fields = '_pageName, name, prereq, action0, action1, action2, effects'

    local wheres = ''
    if (args.name ~= nil) then
        local name = args.name
        wheres = 'prereq LIKE "%%' .. name .. '%%" OR action0="' .. name .. '" OR action1="' .. name .. '" OR action2="' .. name .. '"'
    end

    local cargoArgs = {
        where = wheres, 
        orderBy = 'SkillCombinations.name'
    }

    local result = p.doQuery(fields, cargoArgs)
	if not result then
		return ''
    end

    local html = mw.html.create()
    local tbl = html:tag('table'):addClass('wikitable sortable')

    -- header row
    local trHeader = tbl:tag('tr')
    trHeader:tag('th'):wikitext('Combo Name')    
    trHeader:tag('th'):wikitext('Combination')
    trHeader:tag('th'):cssText('min-width: 200px;'):wikitext('Effects')
    trHeader:tag('th'):wikitext('Prerequisite')

    for _, row in ipairs(result) do
        local tr = tbl:tag('tr')
        -- name
        tr:tag('td'):wikitext(frame:preprocess('[[' .. row._pageName .. '|' .. row.name .. ']]'))
        -- combination
        local combo = ''
        if (row.action0 ~= nil and row.action0 ~= '') then
            combo = '[[' .. row.action0 .. ']] > '
        end
        combo = combo .. '[[' .. row.action1 .. ']] > [[' .. row.action2 .. ']]'
        tr:tag('td'):wikitext(frame:preprocess(combo))
        -- effects
        tr:tag('td'):wikitext(frame:preprocess(row.effects))
        -- prereq
        tr:tag('td'):wikitext(frame:preprocess(row.prereq ~= '' and row.prereq or '<i>None</i>'))
        tr:done()
    end

    return html
end

function p.doQuery(fields, cargoArgs)
    local result = mw.ext.cargo.query('SkillCombinations', fields, cargoArgs)
	if not next(result) then
		return nil
	else
		return result
    end    
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
Advertisement