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

мНет описания правки
Нет описания правки
 
(не показано 69 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- Загружаем данных
local p = {}
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo/bounty.json/base")
local getArgs = require('Module:Arguments').getArgs
 
function p.main(frame)
    local args = getArgs(frame, { removeBlanks = false })
    local name = args[1] or ""
    local attributes = args[2] or ""
    if name == "" then
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    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 p = {}
    local found = {}
 
    if include_base then
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
        if t and t.exists then
            table.insert(found, "")
        end
    end


function p.table(frame)
     for i = 1, max do
     local output = {}
         local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
    for _, item in pairs(cargoData) do
        if t and t.exists then
         local reward = item.reward or ""
            table.insert(found, "-" .. i)
        local description = item.description or ""
        if item.entries then
            for _, entry in ipairs(item.entries) do
                local product = entry.name or ""
                local amount = entry.amount or ""
                table.insert(output, '|data-sort-value=' .. reward .. '|')
                local cellTemplate = string.format(
                    "{{Cut-Layout|1=<b>{{color|#{{ColorPalette|Threat codes|Gamma}}|%s x%s}}</b>|2={{ColorPalette|Other|price|$%s}}|3=%s}}",
                    frame:preprocess('{{#invoke:Ftl|main|translation|' .. product .. '}}'),
                    amount,
                    reward,
                    frame:preprocess('{{#invoke:Ftl|main|translation|' .. description .. '}}')
                )
                table.insert(output, cellTemplate)
                table.insert(output, '|-')
            end
         end
         end
     end
     end
     return frame:preprocess(table.concat(output, "\n"))
 
    if #found == 0 then
        return ""
    end
 
    local before = "[[" .. namespace .. ":" .. name
    local after = "." .. ext .. "|" .. attributes .. "]]"
 
    local parts = {}
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
    for _, suf in ipairs(found) do
        table.insert(parts, "<option>" .. suf .. "</option>")
    end
    table.insert(parts, "</choose>")
 
     return frame:preprocess(table.concat(parts, "\n"))
end
end


return p
return p