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

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


local p = {}
local p = {}


function p.table(frame)
function p.table(frame)
    local targetId = frame.args[1] or ""
    if targetId == "" then
        return "Ошибка: не указан параметр id."
    end
    local foundData = nil
    for _, item in ipairs(accentData) do
        if item.id == targetId then
            foundData = item
            break
        end
    end
    if not foundData then
        return "Ошибка: данные по id '" .. targetId .. "' не найдены."
    end
     local output = {}
     local output = {}
     for _, item in pairs(cargoData) do
 
         local reward = item.reward or ""
     for key, value in pairs(foundData.wordReplacements) do
        local description = item.description or ""
         table.insert(output, string.format("| {{Cut-Layout|background-color=var(--bg-color-message-subtle)|%s|%s}}", key, value))
        if item.entries then
        table.insert(output, "|-")
            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
     return frame:preprocess(table.concat(output, "\n"))
 
     return table.concat(output, "\n")
end
end


return p
return p

Версия от 21:09, 15 апреля 2025

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

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

local p = {}

function p.table(frame)
    local targetId = frame.args[1] or ""
    if targetId == "" then
        return "Ошибка: не указан параметр id."
    end

    local foundData = nil

    for _, item in ipairs(accentData) do
        if item.id == targetId then
            foundData = item
            break
        end
    end

    if not foundData then
        return "Ошибка: данные по id '" .. targetId .. "' не найдены."
    end

    local output = {}

    for key, value in pairs(foundData.wordReplacements) do
        table.insert(output, string.format("| {{Cut-Layout|background-color=var(--bg-color-message-subtle)|%s|%s}}", key, value))
        table.insert(output, "|-")
    end

    return table.concat(output, "\n")
end

return p