Module:Craft

From The Blockheads Wiki
Revision as of 20:44, 14 September 2026 by FloofyPlasma (talk | contribs) (Created page with "local p = {} function p.render(frame) local args = frame:getParent().args local bench = args.Bench or "" local output = args.Output or "" local outputQty = args.OutputQty or "1" local level = args.Level or nil local rushCost = args.RushCost or nil local doubleCost = args.DoubleCost or nil local inputs = {} for i = 1, 5 do local inputKey = "Input" .. i local qtyKey = "Input" .. i .. "Qty" if args[...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    
    local bench = args.Bench or ""
    local output = args.Output or ""
    local outputQty = args.OutputQty or "1"
    
    local level = args.Level or nil
    local rushCost = args.RushCost or nil
    local doubleCost = args.DoubleCost or nil
    
    local inputs = {}
    for i = 1, 5 do
        local inputKey = "Input" .. i
        local qtyKey = "Input" .. i .. "Qty"
        if args[inputKey] and args[inputKey] ~= "" then
            table.insert(inputs, {
                name = args[inputKey],
                qty = args[qtyKey] or "1"
            })
        end
    end
    
    local html = mw.html.create("div")
    html:addClass("craft-recipe")
    
    local header = html:tag("div"):addClass("craft-header")
    
    local benchIcon = mw.html.create("span"):addClass("craft-bench-icon")
    benchIcon:wikitext("[[File:" .. bench .. " Icon.png|20px]]")
    header:node(benchIcon)
    
    local benchText = ""
    if level then
        benchText = "Lvl. " .. level .. " [[" .. bench .. "]]"
    else
        benchText = "[[" .. bench .. "]]"
    end
    header:wikitext(benchText)
    
    if rushCost then
        header:wikitext(" • ")
        local rushIcon = mw.html.create("span"):addClass("craft-rush-icon")
        rushIcon:wikitext("[[File:Time Crystal Icon.png|16px]]")
        header:node(rushIcon)
        header:wikitext(" " .. rushCost)
        if doubleCost then
            header:wikitext(" (2x: " .. doubleCost .. ")")
        end
    end
    
    local row = html:tag("div"):addClass("craft-row")
    
    for i, input in ipairs(inputs) do
        if i > 1 then
            row:tag("div"):addClass("craft-plus"):wikitext("+")
        end
        
        local itemDiv = row:tag("div"):addClass("craft-item")
        local iconDiv = itemDiv:tag("div"):addClass("craft-icon")
        iconDiv:wikitext("[[File:" .. input.name .. " Icon.png|32px]]")
        itemDiv:tag("div"):addClass("craft-qty"):wikitext(input.qty .. "x")
        itemDiv:tag("div"):addClass("craft-name"):wikitext("[[" .. input.name .. "]]")
    end
    
    row:tag("div"):addClass("craft-equals"):wikitext("=")
    
    local outputDiv = row:tag("div"):addClass("craft-item")
    local outputIconDiv = outputDiv:tag("div"):addClass("craft-icon")
    outputIconDiv:wikitext("[[File:" .. output .. " Icon.png|32px]]")
    outputDiv:tag("div"):addClass("craft-qty"):wikitext(outputQty .. "x")
    outputDiv:tag("div"):addClass("craft-name"):wikitext("[[" .. output .. "]]")
    
    return tostring(html)
end

return p