Jump to content

Module:Recipe

From SankoQuest Wiki

Documentation for this module may be created at Module:Recipe/doc

local inventory = require('Module:InventorySlot')
local p = {}

local function arg(frame, name, fallback)
    local parent = frame:getParent()
    local parentArgs = parent and parent.args or {}
    local value = frame.args[name] or parentArgs[name]
    if value == nil or value == '' then
        return fallback or ''
    end
    return value
end

function p.box(frame)
    local root = mw.html.create('div')
        :addClass('sanko-recipe')

    local meta = root:tag('div')
        :addClass('sanko-recipe-meta')

    local station = arg(frame, 'station')
    local skill = arg(frame, 'skill')
    local level = arg(frame, 'level_req')
    local xp = arg(frame, 'xp')
    local recipeKind = arg(frame, 'recipe_kind', 'Crafting')
    local element = arg(frame, 'element')
    local baseMaxHit = arg(frame, 'base_max_hit')

    if recipeKind ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext(recipeKind)
    end
    if station ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext(station)
    end
    if skill ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext(skill)
    end
    if level ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext('Level ' .. level)
    end
    if xp ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext(xp .. ' XP')
    end
    if element ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext(element)
    end
    if baseMaxHit ~= '' then
        meta:tag('span'):addClass('sanko-pill'):wikitext('Max hit ' .. baseMaxHit)
    end

    local body = root:tag('div')
        :addClass('sanko-recipe-body')

    local inputs = body:tag('div')
        :addClass('sanko-recipe-inputs')

    for index = 1, 6 do
        local item = arg(frame, 'input' .. index)
        if item ~= '' then
            inputs:wikitext(inventory._slot(frame, item, arg(frame, 'input' .. index .. '_qty', '1')))
        end
    end

    body:tag('div')
        :addClass('sanko-recipe-arrow')
        :wikitext('→')

    local outputItem = arg(frame, 'output', arg(frame, 'output_item'))
    local outputQty = arg(frame, 'output_qty', '1')
    local output = body:tag('div')
        :addClass('sanko-recipe-output')
    if recipeKind == 'Spell' then
        output:tag('div')
            :addClass('sanko-spell-output')
            :wikitext(outputItem)
        if outputQty ~= '' and outputQty ~= '1' then
            output:tag('small'):wikitext('x' .. outputQty)
        end
    else
        output:wikitext(inventory._slot(frame, outputItem, outputQty))
    end

    return tostring(root)
end

return p