More actions
No edit summary  | 
				m 1 revision imported  | 
				
| (One intermediate revision by the same user not shown) | |
(No difference) 
 | |
Latest revision as of 19:56, 12 April 2025
Documentation for this module may be created at Module:Slot/doc
local p = {}
function p.slot( frame )
    local function getFileUrl(fileName)
        return mw.getCurrentFrame():callParserFunction("filepath", fileName)
    end
    local args = frame.args
    local scale = args.scale or 1
    local html = mw.html.create("div")
        :addClass("slots")
        :css{
            position = "relative",
            width = "100%",
            height = 18 * scale .. "px",
            ["align-items"] = "center",
            ["justify-content"] = "center",
            display = "flex",
        }
    local slots = {}
    for i, v in pairs( args ) do
        if i:sub(1, #"slot") == "slot" and tonumber(i:sub(5)) then
            slots[tonumber(i:sub(5))] = v
        end
    end
    for slot, name in ipairs( slots ) do
        local slot = html:tag("div")
            :addClass("slot")
            :css{
                position = "relative",
                width = 18 * scale .. "px",
                height = 18 * scale .. "px",
                margin = scale .. "px",
            }
        slot:tag("img")
            :attr("src", getFileUrl("Slot.png"))
            :css{
                position = "absolute",
                ["image-rendering"] = "pixelated",
                width = 18 * scale .. "px",
                height = 18 * scale .. "px",
            
                -- The image is shifted to the right when in an Infobox if the top and left are not set to 0
                top = "0",
                left = "0",
            }
        
        slot:tag("img")
            :attr("src", getFileUrl(name))
            :css{
                position = "absolute",
                
                ["image-rendering"] = "pixelated",
                top = scale .. "px",
                left = scale .. "px",
                width = 16 * scale .. "px",
                height = 16 * scale .. "px",
            }
    end
       
    return frame:extensionTag("html", tostring(html))
end
return p