Модуль:Таблица предметов

Материал из Chatmon Wiki
Версия от 18:54, 1 декабря 2026; ChatmonWikiEditor (обсуждение | вклад) (Общие шаблоны и справочные данные Chatmon)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

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

local catalog = mw.loadData('Module:Таблица предметов/данные')
local effects = require('Module:Эффекты')
local export = {}

local function selectRewards(day)
    if not day then return nil end
    local data = mw.loadData('Module:Награды поручений/данные')
    local included = {}
    for _, group in ipairs(assert(data.daily[day], 'Неизвестный день серии')) do
        for _, item in ipairs(group[1]) do included[item] = true end
    end
    return included
end

function export.render(frame)
    local kind = frame.args[1]
    local entries = assert(catalog[kind], 'Неизвестный каталог предметов')
    local included = selectRewards(tonumber(frame.args[2]))
    local handheld = kind == 'held'
    local headings = handheld and {'Предмет', 'Эффект'} or {'Машина'}
    if not handheld then
        for _, label in ipairs(effects.moveHeadings()) do
            headings[#headings + 1] = label
        end
    end
    headings[#headings + 1] = {'Выкуп в Покемаркете'}
    local lines = {'<div style="max-width:100%;overflow-x:auto;">', '{| class="wikitable sortable"'}
    for _, label in ipairs(headings) do
        local numeric = type(label) == 'table'
        local sort = numeric and ' data-sort-type="number"' or ''
        lines[#lines + 1] = '! scope="col"' .. sort .. ' | ' .. (numeric and label[1] or label)
    end
    for _, entry in ipairs(entries) do
        if not included or included[entry[1]] then
            local row = {entry[2]}
            if handheld then
                row[#row + 1] = entry[3]
            else
                for _, cell in ipairs(effects.moveRow(entry[3])) do
                    row[#row + 1] = cell
                end
            end
            row[#row + 1] = 'data-sort-value="' .. entry[5] .. '" | ' .. entry[4]
            lines[#lines + 1] = '|-\n| ' .. table.concat(row, '\n| ')
        end
    end
    lines[#lines + 1] = '|}'
    lines[#lines + 1] = '</div>'
    return frame:preprocess(table.concat(lines, '\n'))
end

return export