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

мНет описания правки
Нет описания правки
 
(не показаны 72 промежуточные версии этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
local priceData = mw.loadData("Модуль:IanComradeBot/prototypes/StaticPrice.json/data")
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


function p.main(frame)
function p.main(frame)
     local id = frame.args[1] or frame.args.id
     local args = getArgs(frame, { removeBlanks = false })
     if not id then
    local name = args[1] or ""
         return "Ошибка: не передан id"
    local attributes = args[2] or ""
     if name == "" then
         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")


     for _, item in ipairs(priceData) do
     local found = {}
        if item.id == id then
 
            return frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
    if include_base then
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
        if t and t.exists then
            table.insert(found, "")
         end
         end
     end
     end


     -- Если не нашли совпадение, возвращаем стандартный текст
     for i = 1, max do
    return frame:preprocess("нет")
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
end
        if t and t.exists then
            table.insert(found, "-" .. i)
        end
    end


function p.table(frame)
     if #found == 0 then
     local output = {}
        return ""
     for _, item in ipairs(priceData) do
     end
        if tonumber(item.StaticPrice.price) ~= 0 then
 
            local name = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}')
    local before = "[[" .. namespace .. ":" .. name
            local price = frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
    local after = "." .. ext .. "|" .. attributes .. "]]"
            table.insert(output, '|data-sort-value=' .. item.StaticPrice.price .. '|{{Cut-Layout|1=[[File:' .. item.id .. '.png|32px]] ' .. name .. '|2=' .. price .. '}}')
 
            table.insert(output, '|-')
    local parts = {}
        end
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
    for _, suf in ipairs(found) do
        table.insert(parts, "<option>" .. suf .. "</option>")
     end
     end
     return frame:preprocess(table.concat(output, "\n"))
    table.insert(parts, "</choose>")
 
     return frame:preprocess(table.concat(parts, "\n"))
end
end


return p
return p