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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 16: Строка 16:


     local image
     local image
    local size = args["size"] or "32px"
     if args["image"] then
     if args["image"] then
        local size = args["size"] or "32px"
         image = string.format("[[Файл:%s|%s]]", args["image"], size)
         image = string.format("[[Файл:%s|%s]]", args["image"], size)
     else
     else

Версия от 03:00, 4 апреля 2025

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

local p = {}

function p.main(frame)
    local args = frame.args

    local id = args[1]
    if not id then
        return "Ошибка: не указан обязательный параметр id."
    end
    
    local itemName = frame:preprocess("{{#invoke:Entity Lookup|getname|" .. id .. "}}")

    local prefix = args[2] or ""

    local label = args["label"] or itemName

    local image
    local size = args["size"] or "32px"
    if args["image"] then
        image = string.format("[[Файл:%s|%s]]", args["image"], size)
    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
        labelOutput = string.format("[[%s|%s]]", linkTarget, label)
    end

    local result = image .. " " .. prefix .. " " .. labelOutput
    return frame:preprocess(result)
end

return p