Module:Craft Usage

Revision as of 23:29, 28 June 2026 by Toster234 (talk | contribs)

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

local p = {}

local recipeParams = {
  station = true,
  time = true,
  output = true,
  yield = true,
}

local labels = {
  craftTitle = 'Crafting',
  craftInputText = 'The item can be used in the following craft recipes',
  craftOutputText = 'The item can be created in the following craft recipes',
  incineratorTitle = 'Incinerator',
  cookingTitle = 'Cooking',
  farmingTitle = 'Farming',
  waterTitle = 'Water Source',
}

local function split(str, delimiter)
    local result = {}
    if not str then return result end

    for part in string.gmatch(str, "([^" .. delimiter .. "]+)") do
        table.insert(result, part)
    end

    return result
end

function p.main(frame)
    local args = require('Module:Arguments').getArgs(frame)

    local item = args.item or mw.title.getCurrentTitle().text
    local mode = args.mode or 'input'

    local title = mw.title.new('Recipes')
    local content = title and title:getContent() or ''

    local wrapper = mw.html.create('div')

    local function processRecipes(typeName, sectionTitle)
        local block = wrapper:tag('div')

        block:tag('h3'):wikitext(sectionTitle)

        local tableHtml = block:tag('table')

        tableHtml:tag('tr')
            :tag('th'):wikitext('Ingredients'):done()
            :tag('th'):wikitext('Output')

        for recipe in content:gmatch('{{Recipe|[^}]*}}') do
            if recipe:find(item) then
                local ingredients = recipe:match('input=(.-)|') or ' - '
                local output = recipe:match('output=(.-)|') or ' - '

                local tr = tableHtml:tag('tr')
                tr:tag('td'):wikitext(ingredients)
                tr:tag('td'):wikitext(output)
            end
        end
    end

    processRecipes('craft', labels.craftTitle)

    return wrapper
end

return p