Module:ItemInfoBox

From Alundra
Revision as of 12:07, 17 May 2026 by Sunnix (talk | contribs)

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

local p = {}

local function GenItemProperty(args, label, property, prefix, suffix)
    local value = args[property]

    if value == nil or value == "" then
        return ""
    end

    prefix = prefix or ""
    suffix = suffix or ""

    return string.format(
        '<div style="display:flex; padding-right:10px"><div>%s</div><div style="flex-grow:1;text-align:right;">%s%s%s</div></div>',
        label,
        prefix,
        value,
        suffix
    )
end

function p.render(frame)
    local args = frame:getParent().args

    local newBlockSet = false -- usage of loops

    local out = ""

    local image = args["image"]
    if image and image ~= "" then
        out = out .. string.format(
            '<div style="text-align:center;margin-bottom:0.5rem;">[[File:%s|center|64px]]</div><hr/>',
            image
        )
    end

    out = out .. GenItemProperty(args, "Stack size", "stacksize")
    out = out .. GenItemProperty(args, "Damage", "damage")
    out = out .. GenItemProperty(args, "Damage charged", "damage_charged")
    out = out .. GenItemProperty(args, "Damage reduction", "damage_reduction")
    out = out .. GenItemProperty(args, "Health", "health")
    out = out .. GenItemProperty(args, "Mana", "mana")
    out = out .. GenItemProperty(args, "Price", "price", "", " [[File:Coin_Gold.png]]")

    local info = args["info"]
    if info and info ~= "" then
        out = out .. string.format('<div>%s</div>', info)
    end

    local itemText = args["item_text"]
    if itemText and itemText ~= "" then
        out = out .. string.format('<hr/><div>%s</div>', itemText)
    end

    newBlockSet = false

    for i = 1, 10 do
        local text = args["anim" .. i .. "_text"]
        local file = args["anim" .. i .. "_file"]
        local sFile = args["sound" .. i .. "_file"]

        if file and file ~= "" then
            if newBlockSet == false then
                out = out .. '<hr/>'
                newBlockSet = true
            end
            
            if text and text ~= "" then
                out = out .. string.format('<div>%s</div>', text)    
            end

            out = out .. string.format('<div>[[File:%s]]</div>', file)
        end
        if sFile and sFile ~= "" then
            if newBlockSet == false then
                out = out .. '<hr/>'
                newBlockSet = true
            end
            out = out .. string.format('<div style="width=100%">[[File:%s]]</div>', sFile)
        end
    end

    return out
end

return p