Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 3: Строка 3:
function p.main(frame)
function p.main(frame)
     local args = frame.args
     local args = frame.args
     local id = args[1]
     local id = args[1]
     if not id then
     if not id then
Строка 9: Строка 8:
     end
     end


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


     local prefix = args[2] or ""
     local prefix = args[2] or ""
     local label = args["label"]
     local label = args["label"] or itemName
     if label == nil then
     local size = args["size"] or "32px"
        label = itemName
    end


    -- Формирование строки изображения
     local image
     local image
    local size = args["size"] or "32px"
     if args["image"] then
     if args["image"] then
         image = string.format("[[Файл:%s|%s]]", args["image"], size)
         image = string.format("[[Файл:%s|%s]]", args["image"], size)
Строка 30: Строка 27:
     end
     end


    -- Формирование ярлыка с ссылкой, если задана
     local labelOutput = label
     local labelOutput = label
     if args["link"] then
     if args["link"] then
Строка 43: Строка 41:
     end
     end


     local result = image .. " "
    -- Сбор информации в зависимости от наличия репозитория
     local additionalInfo
     if args["repository"] then
     if args["repository"] then
         result = result .. itemStack .. " " .. labelOutput .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
         additionalInfo = itemStack .. " " .. labelOutput .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
     else
     else
         result = result .. prefix .. " " .. labelOutput
         additionalInfo = prefix .. " " .. labelOutput
    end
 
    local result = image .. " " .. additionalInfo
 
    -- Формирование вывода через LinkCard, если указан обёртка
    if 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 = args["image"] or (id .. ".png")
        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
     end