Jump to content

Module:Multiblock Slot: Difference between revisions

From Horizon's End Wiki
SherbetS (talk | contribs)
Created page with " local p = {} local aliases = mw.loadData( "Module:Inventory slot/Aliases" ) local function resolveAlias(material) local alias = aliases[material] if type(alias) == "string" then return alias end if type(alias) == "table" then if alias.name then return alias.name end if alias[1] then if type(alias[1]) == "string" then return alias[1] elseif alias[1].name then..."
 
SherbetS (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
local p = {}
local p = {}


-- Load existing inventory aliases
local aliases = mw.loadData(
local aliases = mw.loadData(
     "Module:Inventory slot/Aliases"
     "Module:Inventory slot/Aliases"
)
)


-- Resolve material aliases
local function resolveAlias(material)
local function resolveAlias(material)
     local alias = aliases[material]
     local alias = aliases[material]
Line 30: Line 32:
end
end


-- Render inventory slot
function p.render(frame)
function p.render(frame)
     local args = frame.args or frame:getParent().args
     local args = frame.args or frame:getParent().args


Line 40: Line 44:
     end
     end


    -- Resolve sprite filename
     local spriteName = resolveAlias(material)
     local spriteName = resolveAlias(material)
     local filename = "Invicon " .. spriteName .. ".png"
     local filename = "Invicon " .. spriteName .. ".png"


    -- Create icon container
     local icon = mw.html.create("span")
     local icon = mw.html.create("span")
         :addClass("multiblock-slot")
         :addClass("invslot")
         :wikitext(
        :addClass("invslot-item")
            "[[File:" .. filename ..
        :css("position", "relative")
            "|32x32px|link=" .. material ..
        :css("display", "inline-block")
            "|alt=" .. material .. "]]"
         :css("width", "32px")
         )
        :css("height", "32px")
 
    -- Add inventory sprite
    icon:wikitext(
        "[[File:" .. filename ..
        "|32x32px|link=" .. material ..
        "|alt=" .. material .. "]]"
    )
 
    -- Add stack number using original inventory styling
    local numericAmount = tonumber(amount)
 
    if numericAmount and numericAmount > 1
         and numericAmount < 1000 then


    if tonumber(amount) and tonumber(amount) > 1 then
         icon:tag("span")
         icon:tag("span")
             :addClass("multiblock-slot-amount")
             :addClass("invslot-stacksize")
            :attr("title", material)
             :wikitext(amount)
             :wikitext(amount)
     end
     end

Latest revision as of 04:42, 1 November 2026

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


local p = {}

-- Load existing inventory aliases
local aliases = mw.loadData(
    "Module:Inventory slot/Aliases"
)

-- Resolve material aliases
local function resolveAlias(material)
    local alias = aliases[material]

    if type(alias) == "string" then
        return alias
    end

    if type(alias) == "table" then
        if alias.name then
            return alias.name
        end

        if alias[1] then
            if type(alias[1]) == "string" then
                return alias[1]
            elseif alias[1].name then
                return alias[1].name
            end
        end
    end

    return material
end

-- Render inventory slot
function p.render(frame)

    local args = frame.args or frame:getParent().args

    local material = mw.text.trim(args[1] or "")
    local amount = mw.text.trim(args[2] or "")

    if material == "" then
        return ""
    end

    -- Resolve sprite filename
    local spriteName = resolveAlias(material)
    local filename = "Invicon " .. spriteName .. ".png"

    -- Create icon container
    local icon = mw.html.create("span")
        :addClass("invslot")
        :addClass("invslot-item")
        :css("position", "relative")
        :css("display", "inline-block")
        :css("width", "32px")
        :css("height", "32px")

    -- Add inventory sprite
    icon:wikitext(
        "[[File:" .. filename ..
        "|32x32px|link=" .. material ..
        "|alt=" .. material .. "]]"
    )

    -- Add stack number using original inventory styling
    local numericAmount = tonumber(amount)

    if numericAmount and numericAmount > 1
        and numericAmount < 1000 then

        icon:tag("span")
            :addClass("invslot-stacksize")
            :attr("title", material)
            :wikitext(amount)
    end

    return tostring(icon)
end

return p