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

мНет описания правки
мНет описания правки
Строка 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))
Строка 17: Строка 16:


     local prefix = args[2] or ""
     local prefix = args[2] or ""
    local label = args["label"] or itemName
     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
         label = input_label
if input_label == "" then
            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)
    elseif input_image == "" then
         image = ""
         image = ""
     else
     else
         image = string.format("[[Файл:%s|%s]]", input_image, size)
if input_image == "" then
            image = string.format("[[Файл:%s.png|%s]]", id, size)
         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
Строка 48: Строка 51:
             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)
Строка 56: Строка 58:
     end
     end


     -- Формирование описания репозитория
     -- Сбор информации в зависимости от наличия репозитория
     local input_repository = argsWithWhitespace.repository
     local additionalInfo = args["repository"]
    local repository
     if additionalInfo == nil then
     if input_repository == nil then
         additionalInfo = labelOutput .. " " .. itemStack .. " " .. prefix .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
         repository = prefix .. " " .. labelOutput
     else
     else
         repository = table.concat({
         additionalInfo = labelOutput .. " " .. prefix
            labelOutput,
            itemStack,
            prefix,
            itemContained,
            itemSlot,
            itemChem
        }, " ")
     end
     end


     -- Обработка LinkCard, если указан параметр wrapper
    local result = image .. " " .. additionalInfo
     local input_wrapper = argsWithWhitespace.wrapper
 
    local wrapper
     -- Формирование вывода через LinkCard, если указан непустой обёртка
    if input_wrapper == nil then
     if args["wrapper"] and args["wrapper"] ~= "" then
         wrapper = ""
         local pixel = string.match(size, "(%d+)")
    else
        local wrapperInfo
    local pixel = string.match(size, "(%d+)")
        if args["repository"] then
   
            wrapperInfo = additionalInfo
    local wrapperInfo
        else
    if input_repository == nil then
            wrapperInfo = label .. prefix
        wrapperInfo = label .. prefix
        end
    else
 
        wrapperInfo = repository
        local imageParam
    end
        if args["image"] then
            if args["image"] == "" then
    local imageParam = args["image"]
                imageParam = ""
    if imageParam == nil then
            else
        imageParam = id .. ".png"
                imageParam = args["image"]
    elseif imageParam == "" then
            end
        imageParam = ""
        else
    end
            imageParam = id .. ".png"
        end
    local linkParam = args["link"]
 
    if not linkParam or linkParam == "" then
        local linkParam = args["link"]
        linkParam = itemName
        if not linkParam or linkParam == "" then
    end
            linkParam = itemName
        end
    return frame:preprocess(string.format(
 
        "{{LinkCard|name=%s|image=%s|pixel=%s|link=%s|SideStyle=1}}",
        return frame:preprocess(string.format("{{LinkCard|name=%s|image=%s|pixel=%s|link=%s|SideStyle=1}}", wrapperInfo, imageParam, pixel, linkParam))
        wrapperInfo, imageParam, pixel, linkParam
    end
    ))
end


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


return p
return p