Модуль:Покемоны: различия между версиями
Материал из Chatmon Wiki
Общий размер спрайтов в покедексе и списках TM и HM |
Единый размер спрайтов из шаблона |
||
| Строка 7: | Строка 7: | ||
local stats = {hp, 'Атака', 'Защита', 'Спец. атака', 'Спец. защита', 'Скорость'} | local stats = {hp, 'Атака', 'Защита', 'Спец. атака', 'Спец. защита', 'Скорость'} | ||
local function picture(pokemon | local function picture(pokemon, mode) | ||
local attrs = 'alt=' .. pokemon.name .. '|link=' .. pokemon.name | local attrs = 'alt=' .. pokemon.name .. '|link=' .. pokemon.name | ||
if mode == 'decorative' then | if mode == 'decorative' then | ||
| Строка 14: | Строка 14: | ||
attrs = 'alt=' .. pokemon.alt .. '|link=' | attrs = 'alt=' .. pokemon.alt .. '|link=' | ||
end | end | ||
return '[[Файл:' .. pokemon.sprite .. '| | return '[[Файл:' .. pokemon.sprite .. '|{{Размер спрайта покемона}}|middle|' .. attrs .. ']] [[' .. pokemon.name .. ']]' | ||
end | end | ||
function export.numberAndSprite(id | function export.numberAndSprite(id) | ||
local pokemon = assert(data.pokemon[id], 'Неизвестный покемон') | local pokemon = assert(data.pokemon[id], 'Неизвестный покемон') | ||
return pokemon.number, picture(pokemon | return pokemon.number, picture(pokemon) | ||
end | end | ||
| Строка 94: | Строка 94: | ||
pokemon.number, | pokemon.number, | ||
'data-sort-value="' .. pokemon.name .. '" style="text-align:left;white-space:nowrap;" | ' .. | 'data-sort-value="' .. pokemon.name .. '" style="text-align:left;white-space:nowrap;" | ' .. | ||
picture(pokemon | picture(pokemon, 'decorative'), | ||
} | } | ||
for _, value in ipairs(pokemon.evs) do | for _, value in ipairs(pokemon.evs) do | ||
| Строка 116: | Строка 116: | ||
if slot[1] == ability then | if slot[1] == ability then | ||
found = true | found = true | ||
appendRow(lines, {pokemon.number, picture(pokemon | appendRow(lines, {pokemon.number, picture(pokemon), slot[2] and 'Скрытая' or 'Обычная'}) | ||
end | end | ||
end | end | ||
| Строка 142: | Строка 142: | ||
for _, row in ipairs(section.rows) do | for _, row in ipairs(section.rows) do | ||
local pokemon = data.pokemon[row.pokemon] | local pokemon = data.pokemon[row.pokemon] | ||
local label = picture(pokemon | local label = picture(pokemon, 'encounter') | ||
local cells = {label, row.levels, row.rarity, row.time} | local cells = {label, row.levels, row.rarity, row.time} | ||
if section.showAreas then | if section.showAreas then | ||
Текущая версия от 19:05, 1 декабря 2026
Для документации этого модуля может быть создана страница Модуль:Покемоны/doc
local data = mw.loadData('Module:Покемоны/данные')
local export = {}
local number = '<abbr title="Номер в национальном покедексе">№</abbr>'
local hp = '<abbr title="Очки здоровья">HP</abbr>'
local sumLabel = '<abbr title="Сумма базовых характеристик">Сумма</abbr>'
local stats = {hp, 'Атака', 'Защита', 'Спец. атака', 'Спец. защита', 'Скорость'}
local function picture(pokemon, mode)
local attrs = 'alt=' .. pokemon.name .. '|link=' .. pokemon.name
if mode == 'decorative' then
attrs = 'link=|alt='
elseif mode == 'encounter' then
attrs = 'alt=' .. pokemon.alt .. '|link='
end
return '[[Файл:' .. pokemon.sprite .. '|{{Размер спрайта покемона}}|middle|' .. attrs .. ']] [[' .. pokemon.name .. ']]'
end
function export.numberAndSprite(id)
local pokemon = assert(data.pokemon[id], 'Неизвестный покемон')
return pokemon.number, picture(pokemon)
end
local function startTable(lines, columns, style, sticky)
lines[#lines + 1] = '{| class="wikitable sortable"' .. (style and ' style="' .. style .. '"' or '')
for _, column in ipairs(columns) do
local numeric = type(column) == 'table'
local title = numeric and column[1] or column
local sort = numeric and ' data-sort-type="number"' or ''
local pin = sticky and ' style="position:sticky;top:0;z-index:1;"' or ''
lines[#lines + 1] = '! scope="col"' .. sort .. pin .. ' | ' .. title
end
end
local function appendRow(lines, cells)
lines[#lines + 1] = '|-\n| ' .. table.concat(cells, '\n| ')
end
local function statRow(pokemon)
local typeBadges, abilities = {}, {}
for _, typeId in ipairs(pokemon.types) do
local badge = data.types[typeId]
typeBadges[#typeBadges + 1] = '{{Метка покедекса|' .. badge[1] .. '|' .. badge[2] .. '|' ..
badge[3] .. '|' .. badge[4] .. '|' .. badge[5] .. '}}'
end
for _, slot in ipairs(pokemon.abilities) do
abilities[#abilities + 1] = '[[' .. data.abilityNames[slot[1]] .. ']]' ..
(slot[2] and ' <small>(скрытая)</small>' or '')
end
local total, values = 0, {}
for _, value in ipairs(pokemon.stats) do
total = total + value
values[#values + 1] = value
end
values[#values + 1] = total
return {
pokemon.number,
'style="text-align:left;" | <span style="white-space:nowrap;">' .. picture(pokemon) .. '</span>',
table.concat(typeBadges, '<br />'),
'style="text-align:left;" | ' .. table.concat(abilities, '<br />'),
table.concat(values, ' || '),
}
end
export['покедекс'] = function(frame)
local region = frame.args[1]
local regional = region and region ~= ''
local order = regional and assert(data.starters[region], 'Неизвестный регион') or data.order
local columns = {{number}, 'Покемон', 'Тип', 'Способности'}
for _, stat in ipairs(stats) do
columns[#columns + 1] = {stat}
end
columns[#columns + 1] = {sumLabel}
local lines = {}
local style = regional and 'text-align:center;margin:0;font-size:93%;' or 'text-align:center;'
startTable(lines, columns, style, not regional)
for _, id in ipairs(order) do
appendRow(lines, statRow(data.pokemon[id]))
end
lines[#lines + 1] = '|}'
return frame:preprocess(table.concat(lines, '\n'))
end
export['приростEV'] = function(frame)
local columns = {{number}, 'Покемон', {'HP'}}
for index = 2, #stats do
columns[#columns + 1] = {stats[index]}
end
local lines = {}
startTable(lines, columns, 'text-align:center;')
for _, id in ipairs(data.evOrder) do
local pokemon = data.pokemon[id]
local cells = {
pokemon.number,
'data-sort-value="' .. pokemon.name .. '" style="text-align:left;white-space:nowrap;" | ' ..
picture(pokemon, 'decorative'),
}
for _, value in ipairs(pokemon.evs) do
cells[#cells + 1] = value == 0 and 'data-sort-value="0" |' or value
end
appendRow(lines, cells)
end
lines[#lines + 1] = '|}'
return frame:preprocess(table.concat(lines, '\n'))
end
export['соСпособностью'] = function(frame)
local ability = frame.args[1]
assert(data.abilityNames[ability], 'Неизвестная способность')
local lines = {}
startTable(lines, {'№', 'Покемон', 'Слот способности'})
local found = false
for _, id in ipairs(data.order) do
local pokemon = data.pokemon[id]
for _, slot in ipairs(pokemon.abilities) do
if slot[1] == ability then
found = true
appendRow(lines, {pokemon.number, picture(pokemon), slot[2] and 'Скрытая' or 'Обычная'})
end
end
end
if not found then
return 'В текущем покедексе нет покемонов с этой природной способностью.'
end
lines[#lines + 1] = '|}'
return frame:preprocess(table.concat(lines, '\n'))
end
export['встречи'] = function(frame)
local allEncounters = mw.loadData('Module:Покемоны/встречи')
local region = assert(allEncounters[frame.args[1]], 'Неизвестный регион')
local place = assert(region[frame.args[2]], 'Нет встреч для этой локации')
local lines = {}
for _, section in ipairs(place.sections) do
local heading = section.headingLink and ('[[' .. section.heading .. ']]') or section.heading
lines[#lines + 1] = '=== ' .. heading .. ' ==='
local columns = {'Покемон', 'Уровни', 'Редкость', 'Время (МСК)'}
if section.showAreas then
columns[#columns + 1] = 'Где встречается'
end
startTable(lines, columns)
for _, row in ipairs(section.rows) do
local pokemon = data.pokemon[row.pokemon]
local label = picture(pokemon, 'encounter')
local cells = {label, row.levels, row.rarity, row.time}
if section.showAreas then
local areas = {}
for _, area in ipairs(row.areas) do
areas[#areas + 1] = area[3] and ('[[#loc-' .. area[1] .. '|' .. area[2] .. ']]') or area[2]
end
cells[#cells + 1] = row.everywhere and 'Все части' or table.concat(areas, ', ')
end
appendRow(lines, cells)
end
lines[#lines + 1] = '|}'
lines[#lines + 1] = ''
end
return frame:preprocess(table.concat(lines, '\n'))
end
return export
