Модуль:Prototypes/Механика/Награда доставки: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
Нет описания правки
 
(не показано 10 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo/bounty.json/base")
local p = {}
local p = {}


-- Загрузка данных
function p.table(frame)
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo/bounty.json/base")
    local output = {}
    table.insert(output, '{| class="sortable-grid sortable"')
    table.insert(output, '! Сортировка (по награде)')
    table.insert(output, '|-')
   
    for _, item in pairs(cargoData) do
        local reward = item.reward or ""
        local description = item.description or ""
 
        local productLines = {}
        if item.entries then
            for _, entry in ipairs(item.entries) do
                local productName = frame:preprocess(
                    "{{#invoke:Loc|GetRawString|" .. entry.name .. "}}"
                )
                local amount = entry.amount or ""
                table.insert(
                    productLines,
                    string.format("<b>{{цвет|text|gold|c=%s x%s}}</b>", productName, amount)
                )
            end
        end
        local productsParam = table.concat(productLines, "<br/>")


function p.main(frame)
        table.insert(output, '|data-sort-value=' .. reward .. '|' )
local output = {}
        local cellTemplate = string.format(
table.insert(output, '{| class="wikitable"')
            "{{Cut-Layout|1=%s|2=${{ColorPalette|Other|price|%s}}|3=%s}}",
table.insert(output, '|-')
            productsParam,
table.insert(output, '! Название (количество)')
            reward,
table.insert(output, '! Предмет(-ы)')
            frame:preprocess(
table.insert(output, '! Вознаграждение')
                "{{#invoke:Loc|GetString|" .. description .. "}}"
table.insert(output, '! Описание')
            )
        )
for _, item in pairs(cargoData) do
        table.insert(output, cellTemplate)
local reward = item.reward or ""
        table.insert(output, "|-")
local description = item.description or ""
    end
if item.entries then
   
for _, entry in ipairs(item.entries) do
    table.insert(output, "|}")
local product = entry.name or ""
    return frame:preprocess(table.concat(output, "\n"))
local amount = entry.amount or ""
local tagString = ""
if entry.whitelist and entry.whitelist.tags then
for _, tag in ipairs(entry.whitelist.tags) do
tagString = tagString .. " (" .. tag .. ")"
end
end
table.insert(output, '|-')
table.insert(output, string.format("| [[{{#invoke:Ftl|main|translation|%s}}|{{#invoke:Ftl|main|translation|%s}}]] x%s || %s || {{ColorPalette|Other|price|%s}}$ || {{#invoke:Ftl|main|translation|%s}}", product, product, amount, tagString, reward, description))
end
end
end
table.insert(output, "|}")
return frame:preprocess(table.concat(output, "\n"))
end
end


return p
return p

Текущая версия от 12:57, 25 февраля 2026

Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Награда доставки/doc

-- Загрузка данных
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo/bounty.json/base")

local p = {}

function p.table(frame)
    local output = {}
    table.insert(output, '{| class="sortable-grid sortable"')
    table.insert(output, '! Сортировка (по награде)')
    table.insert(output, '|-')
    
    for _, item in pairs(cargoData) do
        local reward = item.reward or ""
        local description = item.description or ""

        local productLines = {}
        if item.entries then
            for _, entry in ipairs(item.entries) do
                local productName = frame:preprocess(
                    "{{#invoke:Loc|GetRawString|" .. entry.name .. "}}"
                )
                local amount = entry.amount or ""
                table.insert(
                    productLines,
                    string.format("<b>{{цвет|text|gold|c=%s x%s}}</b>", productName, amount)
                )
            end
        end
        local productsParam = table.concat(productLines, "<br/>")

        table.insert(output, '|data-sort-value=' .. reward .. '|' )
        local cellTemplate = string.format(
            "{{Cut-Layout|1=%s|2=${{ColorPalette|Other|price|%s}}|3=%s}}",
            productsParam,
            reward,
            frame:preprocess(
                "{{#invoke:Loc|GetString|" .. description .. "}}"
            )
        )
        table.insert(output, cellTemplate)
        table.insert(output, "|-")
    end
    
    table.insert(output, "|}")
    return frame:preprocess(table.concat(output, "\n"))
end

return p