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

мНет описания правки
Нет описания правки
 
(не показано 80 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


function p.main(frame)
function p.main(frame)
     local args = frame.args
     local args = getArgs(frame, { removeBlanks = false })
 
    local name = args[1] or ""
     local id = args[1]
     local attributes = args[2] or ""
     if not id then
     if name == "" then
         return "Ошибка: не указан обязательный параметр id."
         return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
     end
     end
    local ext = (args["ext"] or "png"):gsub("^%.", "")
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")


     local itemStack = frame:preprocess(string.format('{{#invoke:Prototypes/Хранилище/Предмет|main|framing|stack|%s}}', id))
     local found = {}
    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 ""
     if include_base then
    local label = args["label"]
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    if label == nil then
        if t and t.exists then
         label = itemName
            table.insert(found, "")
         end
     end
     end


     local image
     for i = 1, max do
    local size = args["size"] or "32px"
         local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
    if args["image"] then
        if t and t.exists then
         image = string.format("[[Файл:%s|%s]]", args["image"], size)
            table.insert(found, "-" .. i)
    else
        end
        image = string.format("[[Файл:%s.png|%s]]", id, size)
     end
     end


    local labelOutput = label
     if #found == 0 then
     if args["link"] then
         return ""
        local linkTarget = args["link"]
        if linkTarget == "" then
            linkTarget = itemName
        end
        if label ~= "" then
            labelOutput = string.format("[[%s|%s]]", linkTarget, label)
         else
            labelOutput = ""
        end
     end
     end


     local result = image .. " "
     local before = "[[" .. namespace .. ":" .. name
     if args["repository"] then
     local after = "." .. ext .. "|" .. attributes .. "]]"
        result = result .. itemStack .. " " .. labelOutput .. " " .. itemContained .. " " .. itemSlot .. " " .. itemChem
 
     else
    local parts = {}
         result = result .. prefix .. " " .. labelOutput
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
     for _, suf in ipairs(found) do
         table.insert(parts, "<option>" .. suf .. "</option>")
     end
     end
    table.insert(parts, "</choose>")


     return frame:preprocess("<span>" .. result .. "</span>")
     return frame:preprocess(table.concat(parts, "\n"))
end
end


return p
return p