Toggle menu
66
63
2
559
Fisk's Superheroes Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Slot: Difference between revisions

From Fisk's Superheroes Wiki
mNo edit summary
Tag: Reverted
mNo edit summary
Tags: Manual revert Reverted
Line 1: Line 1:
local p = {}
local p = {}


local function isUrl(value)
function p.slot( frame )
     return type(value) == "string" and value:match("^https?://")
     local function getFileUrl(fileName)
end
        return mw.getCurrentFrame():callParserFunction("filepath", fileName)
 
local function isHtmlImg(value)
    return type(value) == "string" and value:match("^<img")
end
 
local function getFileUrl(fileName)
    if isUrl(fileName) then
        return fileName
     end
     end


    if isHtmlImg(fileName) then
        return fileName
    end
    return mw.getCurrentFrame():callParserFunction("filepath", fileName)
end
function p.slot(frame)
     local args = frame.args
     local args = frame.args
     local scale = tonumber(args.scale) or 1
     local scale = args.scale or 1


     local html = mw.html.create("div")
     local html = mw.html.create("div")
Line 31: Line 15:
             width = "100%",
             width = "100%",
             height = 18 * scale .. "px",
             height = 18 * scale .. "px",
             ["align-items"] = "center",
             ["align-items"] = "center",
             ["justify-content"] = "center",
             ["justify-content"] = "center",
Line 37: Line 22:


     local slots = {}
     local slots = {}
     for key, value in pairs(args) do
     for i, v in pairs( args ) do
         if key:match("^slot%d+$") then
         if i:sub(1, #"slot") == "slot" and tonumber(i:sub(5)) then
            local index = tonumber(key:sub(5))
             slots[tonumber(i:sub(5))] = v
             slots[index] = value
         end
         end
     end
     end


     for _, name in ipairs(slots) do
     for slot, name in ipairs( slots ) do
         local slot = html:tag("div")
         local slot = html:tag("div")
             :addClass("slot")
             :addClass("slot")
             :css{
             :css{
                 position = "relative",
                 position = "relative",
                 width = 18 * scale .. "px",
                 width = 18 * scale .. "px",
                 height = 18 * scale .. "px",
                 height = 18 * scale .. "px",
Line 58: Line 43:
             :css{
             :css{
                 position = "absolute",
                 position = "absolute",
                 ["image-rendering"] = "pixelated",
                 ["image-rendering"] = "pixelated",
                 width = 18 * scale .. "px",
                 width = 18 * scale .. "px",
                 height = 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
                -- The image is shifted to the right when in an Infobox if the top and left are not set to 0
                 top = "0",
                 top = "0",
                 left = "0",
                 left = "0",
             }
             }
 
          
        local value = name
         slot:tag("img")
         if isHtmlImg(value) then
            :attr("src", getFileUrl(name))
            slot:wikitext(value)
            :css{
         else
                position = "absolute",
            slot:tag("img")
               
                :attr("src", getFileUrl(value))
                ["image-rendering"] = "pixelated",
                :css{
                top = scale .. "px",
                    position = "absolute",
                left = scale .. "px",
                    ["image-rendering"] = "pixelated",
                width = 16 * scale .. "px",
                    top = scale .. "px",
                height = 16 * scale .. "px",
                    left = scale .. "px",
            }
                    width = 16 * scale .. "px",
                    height = 16 * scale .. "px",
                }
        end
     end
     end
 
     
     return frame:extensionTag("html", tostring(html))
     return frame:extensionTag("html", tostring(html))
end
end


return p
return p

Revision as of 21:26, 15 November 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