Модуль:Типы

Материал из Chatmon Wiki
Версия от 16:21, 2 декабря 2026; ChatmonWikiEditor (обсуждение | вклад) (Цветные метки и ссылки на страницы типов)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

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

local dex = require('Module:Покемоны')
local dexData = mw.loadData('Module:Покемоны/данные')
local export = {}

local function tableStart(class, headings)
    local lines = {'{| class="wikitable sortable ' .. class .. '"'}
    for _, heading in ipairs(headings) do
        local numeric = type(heading) == 'table'
        local label = numeric and heading[1] or heading
        local attr = numeric and ' data-sort-type="number"' or ''
        lines[#lines + 1] = '! scope="col"' .. attr .. ' | ' .. label
    end
    return lines
end

local function addRow(lines, values)
    lines[#lines + 1] = '|-\n| ' .. table.concat(values, '\n| ')
end

local function render(frame, lines)
    lines[#lines + 1] = '|}'
    return frame:preprocess(table.concat(lines, '\n'))
end

export['покемоны'] = function(frame)
    local tableText = dex.typeDex(frame, frame.args[1])
    return '<div style="max-width:100%;overflow-x:auto;">\n' .. tableText .. '\n</div>'
end

export['атаки'] = function(frame)
    local kind = assert(dexData.types[frame.args[1]], 'Неизвестный тип')
    local effects = require('Module:Эффекты')
    local metadata = mw.loadData('Module:Приёмы/данные').moves
    local details = mw.loadData('Module:Эффекты/данные').moves
    local headings = effects.moveHeadings()
    table.remove(headings, 2)
    local lines = tableStart('chatmon-type-moves', headings)
    local ids, names = {}, {}
    for id, description in pairs(details) do
        local typeCell = metadata[id][2]
        local label = typeCell:match('{{Метка типа|[^|]*|([^|}]+)')
            or typeCell:match('{{Метка покедекса|[^|]*|([^|]+)|')
        if label == kind[2] then
            ids[#ids + 1] = id
            names[id] = description.title:gsub('ё', 'е'):gsub('Ё', 'Е')
        end
    end
    table.sort(ids, function(a, b)
        if names[a] == names[b] then return details[a].title < details[b].title end
        return names[a] < names[b]
    end)
    for _, id in ipairs(ids) do
        local row = effects.moveRow(id)
        table.remove(row, 2)
        addRow(lines, row)
    end
    return render(frame, lines)
end

return export