Модуль:Предмет: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 19: Строка 19:
     -- Формирование строки изображения
     -- Формирование строки изображения
     local image = ""
     local image = ""
     if args["image"] and args["image"] ~= "" then
     if args["image"] ~= nil then
        image = string.format("[[Файл:%s|%s]]", args["image"], size)
        if args["image"] ~= "" then
    elseif not args["image"] then
            image = string.format("[[Файл:%s|%s]]", args["image"], size)
        else
            image = ""
        end
    else
         image = string.format("[[Файл:%s.png|%s]]", id, size)
         image = string.format("[[Файл:%s.png|%s]]", id, size)
     end
     end
Строка 58: Строка 62:
             wrapperInfo = label .. prefix
             wrapperInfo = label .. prefix
         end
         end
         local imageParam = args["image"] or (id .. ".png")
         local imageParam = ""
        if args["image"] ~= nil then
            if args["image"] ~= "" then
                imageParam = args["image"]
            else
                imageParam = ""
            end
        else
            imageParam = id .. ".png"
        end
 
         local linkParam = args["link"]
         local linkParam = args["link"]
         if not linkParam or linkParam == "" then
         if not linkParam or linkParam == "" then

Версия от 06:45, 4 апреля 2025

Для документации этого модуля может быть создана страница Модуль:Предмет/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame)
    local id = args[1] or ""

    -- Инициализация данных предмета
    local itemStack = frame:preprocess(string.format('{{#invoke:Prototypes/Хранилище/Предмет|main|framing|stack|%s}}', id))
    local itemContained = frame:preprocess(string.format('{{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|%s}}', id))
    local itemSlot = frame:preprocess(string.format('{{#invoke:Prototypes/Хранилище/Предмет|main|framing|slot|%s}}', id))
    local itemChem = frame:preprocess(string.format('{{СollapsibleMenu|color=#3e7c82|{{#invoke:Prototypes/Хранилище/Предмет|main|chem|%s}}}}', id))
    local itemName = frame:preprocess("{{#invoke:Entity Lookup|getname|" .. id .. "}}")

    local prefix = args[2] or ""
    local label = args["label"] or itemName
    local size = args["size"] or "32px"

    -- Формирование строки изображения
    local image = ""
    if args["image"] ~= nil then
        if args["image"] ~= "" then
            image = string.format("[[Файл:%s|%s]]", args["image"], size)
        else
            image = ""
        end
    else
        image = string.format("[[Файл:%s.png|%s]]", id, size)
    end

    -- Формирование ярлыка с ссылкой, если задана
    local labelOutput = label
    if args["link"] then
        local linkTarget = args["link"]
        if linkTarget == "" then
            linkTarget = itemName
        end
        if label ~= "" then
            labelOutput = string.format("[[%s|%s]]", linkTarget, label)
        else
            labelOutput = ""
        end
    end

    -- Сбор информации в зависимости от наличия репозитория
    local additionalInfo
    if args["repository"] then
        additionalInfo = itemStack .. " " .. labelOutput .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
    else
        additionalInfo = prefix .. " " .. labelOutput
    end

    local result = image .. " " .. additionalInfo

    -- Формирование вывода через LinkCard, если указан обёртка
    if args["wrapper"] and args["wrapper"] ~= "" then
        local pixel = string.match(size, "(%d+)")
        local wrapperInfo
        if args["repository"] then
            wrapperInfo = label .. itemStack .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
        else
            wrapperInfo = label .. prefix
        end
        local imageParam = ""
        if args["image"] ~= nil then
            if args["image"] ~= "" then
                imageParam = args["image"]
            else
                imageParam = ""
            end
        else
            imageParam = id .. ".png"
        end

        local linkParam = args["link"]
        if not linkParam or linkParam == "" then
            linkParam = itemName
        end

        return frame:preprocess(string.format("{{LinkCard|name=%s|image=%s|pixel=%s|link=%s|SideStyle=1}}", wrapperInfo, imageParam, pixel, linkParam))
    end

    return frame:preprocess("<span>" .. result .. "</span>")
end

return p