Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Fabricator

From Fisk's Superheroes Wiki
Revision as of 20:56, 12 April 2025 by Lok (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.gui( frame )
    local function split(str, sep)
        if (str == nil) then return {} end
        local result = {}
        for match in (str..sep):gmatch("([^"..sep.."]+)") do
            table.insert(result, match)
        end
        return result
    end

    local function getFileUrl(fileName)
        return mw.getCurrentFrame():callParserFunction("filepath", fileName)
    end

    local args = frame.args
    local scale = tonumber(args.scale) or 1
    
    local html = mw.html.create("div")
        :attr("class", "frame")
        :css{
            position = "relative",
            width = 166 * scale .. "px",
            height = 48 * scale .. "px",
            display = "inline-block",
            overflow = "hidden"
        }

    html:tag("img")
        :attr("src", getFileUrl("Fabricator.png"))
        :css{
            ["image-rendering"] = "pixelated",
            width = "100%",
            height = "100%",
            display = "block"
        }
    
    for i = 1, 10 do
        local item = args['I'..i]
        if (item) then
            item = split(item, ";")
            local amount = item[2] or 1
            item = item[1]
            local xOffset
            if (i == 1 or i == 6) then
                xOffset = 30 * scale
            else
                xOffset = (30 + ((i - 1) % 5) * 18) * scale
            end
            local yOffset
            if (i > 5) then
                yOffset = 25 * scale
            else
                yOffset = 7 * scale
            end

            local container = mw.html.create("div")
                :attr("class", "item")
                :css{
                    position = "absolute",
                    left = xOffset .. "px",
                    top = yOffset .. "px",
                    width = 16 * scale .. "px",
                    height = 16 * scale .. "px"
                }

            container:tag("img")
                :attr("src", getFileUrl(item))
                :css{
                    ["image-rendering"] = "pixelated",
                    width = 16 * scale .. "px",
                    height = 16 * scale .. "px"
                }

            
            container:tag("span")
                :attr("class", "micro-5-regular")
                :wikitext(amount)
                :css{
                    position = "absolute",
                    right = 0,
                    bottom = 0,
                    ["font-size"] = (12 * scale) .. "px",
                    ["line-height"] = (12 * scale) - (scale * 4) .. "px",
                    color = "#FFFFFF",
                    ["-webkit-text-stroke"] = math.max(1, scale / 2) .. "px #000000",
                }

            html:node(container)
        end
    end

    if (args.output) then
        html:tag("img")
            :attr("src", getFileUrl(args.output))
            :css{
                position = "absolute",
                left = 142 * scale .. "px",
                top = 16 * scale .. "px",
                width = 16 * scale .. "px",
                height = 16 * scale .. "px",
                ["image-rendering"] = "pixelated",
            }
    end

    html:tag("img")
        :attr("src", getFileUrl(args.drive or "Suit_Data_Drive_Black_Active.gif"))
        :css{
            position = "absolute",
            left = 8 * scale .. "px",
            top = 7 * scale .. "px",
            width = 16 * scale .. "px",
            height = 16 * scale .. "px",
            ["image-rendering"] = "pixelated",
        }

    html:tag("img")
        :attr("src", getFileUrl(args.core or "Suit_Core.png"))
        :css{
            position = "absolute",
            left = 8 * scale .. "px",
            top = 25 * scale .. "px",
            width = 16 * scale .. "px",
            height = 16 * scale .. "px",
            ["image-rendering"] = "pixelated",
        }

    local tooltip = mw.html.create("div")
        :attr("id", "item-tooltip")
        :css{
            display = "none"
        }
    
    tooltip:tag("span")
        :attr("class", "micro-5-regular")
        :css{
            ["font-size"] = (12 * scale) .. "px",
            ["line-height"] = (12 * scale) - (scale * 4) .. "px",
            color = "#FFFFFF"
        }
        :wikitext("Test")
    
    html:node(tooltip)

    return frame:extensionTag("html", tostring(html))
end

return p