Jump to content

Module:Multiblock: Difference between revisions

From Horizon's End Wiki
SherbetS (talk | contribs)
No edit summary
SherbetS (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 51: Line 51:
     end
     end


  -- Load the inventory slot module near the top of Module:Multiblock
local slotModule = require("Module:Multiblock Slot")
-- Resource requirements
args.header27 = "Resource Requirements"
for i = 1, 20 do
    local material = getArg(source, "resource_title" .. i)
    local amount = getArg(source, "resource_value" .. i)
    local resourceName = getArg(source, "resource_name" .. i)
    if material ~= "" then
        -- Generate simplified inventory slot
        local slot = slotModule.render({
            args = {
                [1] = material,
                [2] = amount
            }
        })
        -- Custom display name or material name
        local displayName = resourceName ~= ""
            and resourceName
            or material
        -- Resource display
        local row = mw.html.create("div")
            :css("float", "left")
            :css("width", "85%")
            :css("text-align", "left")
            :css("display", "flex")
            :css("align-content", "center")
        row:tag("div")
            :css("float", "left")
            :wikitext(slot)
        row:tag("div")
            :css("padding-left", "5%")
            :css("display", "flex")
            :css("align-items", "center")
            :tag("b")
                :wikitext(displayName)
        local quantity = mw.html.create("div")
            :css("float", "right")
            :css("width", "15%")
            :css("text-align", "left")
            :wikitext(amount)
        args["data" .. (27 + i)] =
            tostring(row) .. tostring(quantity)
    end
end


     -- Render the standard infobox
     -- Render the standard infobox

Latest revision as of 04:33, 1 November 2026

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


local p = {}

local function getArg(args, name)
    return args[name] or ""
end

function p.main(frame)
    local parent = frame:getParent()
    local source = parent.args
    local args = {}

    -- Basic infobox settings
    args.above = getArg(source, "name")
    args.subheader = getArg(source, "subheader")
    args.autoheaders = "y"

    args.abovestyle = "background:#eaecee;font-size:130%;padding:0.3em;"
    args.headerstyle = "background:#eaecee;"

    -- Images
    for i = 1, 2 do
        local image = getArg(source, "image" .. (i == 1 and "" or i))

        if image ~= "" then
            args["image" .. (i == 1 and "" or i)] =
                "[[File:" .. image ..
                "|frameless|alt=" .. getArg(source, "alt") ..
                "|border|upright=1|]]"
        end
    end

    if getArg(source, "image3") ~= "" then
        args.image3 = getArg(source, "image3")
    end

    args.caption = getArg(source, "caption")
    args.caption2 = getArg(source, "caption2")

    -- Properties
    args.header10 = "Properties"
    args.label11 = "Maximum Power Storage"
    args.data11 = getArg(source, "powerstorage")

    for i = 1, 15 do
        args["label" .. (11 + i)] =
            getArg(source, "custom_property_title" .. i)

        args["data" .. (11 + i)] =
            getArg(source, "custom_property_value" .. i)
    end

  -- Load the inventory slot module near the top of Module:Multiblock
local slotModule = require("Module:Multiblock Slot")


-- Resource requirements
args.header27 = "Resource Requirements"

for i = 1, 20 do
    local material = getArg(source, "resource_title" .. i)
    local amount = getArg(source, "resource_value" .. i)
    local resourceName = getArg(source, "resource_name" .. i)

    if material ~= "" then

        -- Generate simplified inventory slot
        local slot = slotModule.render({
            args = {
                [1] = material,
                [2] = amount
            }
        })

        -- Custom display name or material name
        local displayName = resourceName ~= ""
            and resourceName
            or material

        -- Resource display
        local row = mw.html.create("div")
            :css("float", "left")
            :css("width", "85%")
            :css("text-align", "left")
            :css("display", "flex")
            :css("align-content", "center")

        row:tag("div")
            :css("float", "left")
            :wikitext(slot)

        row:tag("div")
            :css("padding-left", "5%")
            :css("display", "flex")
            :css("align-items", "center")
            :tag("b")
                :wikitext(displayName)

        local quantity = mw.html.create("div")
            :css("float", "right")
            :css("width", "15%")
            :css("text-align", "left")
            :wikitext(amount)

        args["data" .. (27 + i)] =
            tostring(row) .. tostring(quantity)
    end
end

    -- Render the standard infobox
    return frame:expandTemplate{
        title = "Infobox",
        args = args
    }
end

return p