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

мНет описания правки
мНет описания правки
Строка 3: Строка 3:


function p.main(frame)
function p.main(frame)
    -- Получение аргументов шаблона
     local args = getArgs(frame)
     local args = getArgs(frame)
     local argsWithWhitespace = getArgs(frame, { trim = false, removeBlanks = false })
     local argsWithWhitespace = getArgs(frame, { trim = false, removeBlanks = false })
   
 
     local id = args[1] or ""
     local id = args[1] or ""


     -- Инициализация данных предмета
     -- Получение данных о предмете через другие модули
     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))
Строка 18: Строка 19:
     local size = args["size"] or "32px"
     local size = args["size"] or "32px"


    -- Обработка ярлыка
     local input_label = argsWithWhitespace.label or argsWithWhitespace.l
     local input_label = argsWithWhitespace.label or argsWithWhitespace.l
     local label
     local label
     if input_label == nil then
     if input_label == nil then
         label = itemName
         label = itemName
    elseif input_label == "" then
        label = ""
     else
     else
if input_label == "" then
         label = input_label
            label = ""
         else
            label = input_label
        end
     end
     end


     -- Формирование строки изображения с проверкой на пустое значение
     -- Обработка изображения
     local input_image = argsWithWhitespace.image or argsWithWhitespace.img
     local input_image = argsWithWhitespace.image or argsWithWhitespace.img
     local image
     local image
     if input_image == nil then
     if input_image == nil then
         image = string.format("[[Файл:%s.png|%s]]", id, size)
         image = string.format("[[Файл:%s.png|%s]]", id, size)
    elseif input_image == "" then
        image = ""
     else
     else
if input_image == "" then
         image = string.format("[[Файл:%s|%s]]", input_image, size)
            image = ""
         else
            image = string.format("[[Файл:%s|%s]]", input_image, size)
        end
     end
     end


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


     -- Сбор информации в зависимости от наличия репозитория
     -- Формирование описания репозитория
     local input_repository = argsWithWhitespace.repository
     local input_repository = argsWithWhitespace.repository
     local repository
     local repository
Строка 63: Строка 62:
         repository = prefix .. " " .. labelOutput
         repository = prefix .. " " .. labelOutput
     else
     else
repository = itemStack .. " " .. labelOutput .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
        repository = table.concat({
            itemStack,
            labelOutput,
            itemContained,
            itemSlot,
            itemChem
        }, " ")
     end
     end


     local result = image .. " " .. repository
     local result = image .. " " .. repository


     -- Формирование вывода через LinkCard, если указан непустой обёртка
     -- Обработка LinkCard, если указан параметр wrapper
     if args["wrapper"] and args["wrapper"] ~= "" then
     if args["wrapper"] and args["wrapper"] ~= "" then
         local pixel = string.match(size, "(%d+)")
         local pixel = string.match(size, "(%d+)")
       
         local wrapperInfo
         local wrapperInfo
         if input_repository == nil then
         if input_repository == nil then
Строка 78: Строка 84:
         end
         end


         local imageParam
         local imageParam = args["image"]
        if args["image"] then
        if imageParam == nil then
            if args["image"] == "" then
                imageParam = ""
            else
                imageParam = args["image"]
            end
        else
             imageParam = id .. ".png"
             imageParam = id .. ".png"
        elseif imageParam == "" then
            imageParam = ""
         end
         end


Строка 94: Строка 96:
         end
         end


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