Модуль:Карточка покемона: различия между версиями
Материал из Chatmon Wiki
Общие шаблоны и справочные данные Chatmon |
Общие шаблоны и справочные данные Chatmon |
||
| Строка 18: | Строка 18: | ||
local function gender(rate) | local function gender(rate) | ||
if rate < 0 then return ' | if rate < 0 then return 'пола не имеет' end | ||
if rate == 0 then return 'только самцы' end | if rate == 0 then return 'только самцы' end | ||
if rate == 8 then return 'только самки' end | if rate == 8 then return 'только самки' end | ||
Текущая версия от 18:57, 1 декабря 2026
Для документации этого модуля может быть создана страница Модуль:Карточка покемона/doc
local data = mw.loadData('Module:Покемоны/данные')
local export = {}
local statNames = {'HP', 'Атака', 'Защита', 'Спец. Атака', 'Спец. Защита', 'Скорость'}
local cellStyle = 'margin:0;padding:.38em .65em;border-top:1px solid var(--border-color-subtle,#a2a9b1);overflow-wrap:anywhere;'
local function row(out, label, content, style)
out[#out + 1] = '<dt style="' .. cellStyle .. '">' .. label .. '</dt><dd style="' ..
cellStyle .. 'min-width:0;' .. (style or '') .. '">' .. content .. '</dd>'
end
local function decimal(number)
return (string.format('%.1f', number):gsub('%.', ','))
end
local function percentage(number)
return (string.format('%g', number):gsub('%.', ',')) .. '%'
end
local function gender(rate)
if rate < 0 then return 'пола не имеет' end
if rate == 0 then return 'только самцы' end
if rate == 8 then return 'только самки' end
return 'самцов ' .. percentage((8 - rate) * 12.5) .. ', самок ' .. percentage(rate * 12.5)
end
local function picture(art)
return '[[Файл:' .. art[1] .. '|240px|link=|alt=' .. art[2] .. ']]'
end
function export.card(frame)
local pokemon = assert(data.pokemon[frame.args[1]], 'Неизвестный покемон')
local out = {
'<div class="chatmon-card-info" style="box-sizing:border-box;max-width:100%;border:1px solid var(--border-color-subtle,#a2a9b1);background-color:var(--background-color-neutral-subtle,transparent);">',
'<div class="chatmon-card-info-title" style="text-align:center;font-weight:bold;padding:.45em .65em;">№' .. pokemon.number .. ' ' .. pokemon.name .. '</div>',
'<div style="text-align:center;padding:.25em .45em .55em;">' .. picture(pokemon.art[1]),
'<div class="mw-collapsible mw-collapsed" style="margin-top:.5em;"><div style="text-align:left;">Шайни-окрас</div><div class="mw-collapsible-content">' ..
picture(pokemon.art[2]) .. '</div></div></div>',
'<dl style="display:grid;grid-template-columns:minmax(0,2fr) minmax(0,3fr);margin:0;">',
}
local types = {}
for _, id in ipairs(pokemon.types) do
local badge = data.types[id]
types[#types + 1] = '{{Метка покедекса|' .. badge[1] .. '|' .. badge[2] .. '|' .. badge[3] .. '}}'
end
row(out, 'Тип', table.concat(types, ' '), 'text-align:center;')
local normal, hidden = {}, {}
for _, slot in ipairs(pokemon.abilities) do
local labels = slot[2] and hidden or normal
labels[#labels + 1] = '[[' .. data.abilityNames[slot[1]] .. ']]'
end
row(out, 'Способности', table.concat(normal, ', '))
if hidden[1] then
row(out, 'Скрытая способность', table.concat(hidden, ', '))
end
row(out, 'Рост', decimal(pokemon.height / 10) .. ' м')
row(out, 'Вес', decimal(pokemon.weight / 10) .. ' кг')
row(out, 'Пол', gender(pokemon.genderRate))
local evs, held = {}, {}
for index, value in ipairs(pokemon.evs) do
if value > 0 then
evs[#evs + 1] = value .. ' ' .. statNames[index]
end
end
row(out, 'EV за победу', evs[1] and table.concat(evs, ', ') or '—')
for _, title in ipairs(pokemon.heldItems) do
held[#held + 1] = '[[' .. title .. ']]'
end
if held[1] then
row(out, 'Предметы у диких', table.concat(held, ', '))
end
out[#out + 1] = '</dl></div>'
return frame:preprocess(table.concat(out))
end
function export.neighbors(frame)
local id = frame.args[1]
local position
for index, key in ipairs(data.order) do
if key == id then
position = index
break
end
end
assert(position, 'Неизвестный покемон')
local args = {['раздел'] = 'Покемоны'}
local function neighbor(key, neighborId)
if neighborId then
local record = data.pokemon[neighborId]
args[key] = record.name
args[key .. '_спрайт'] = string.format('%03d', record.number)
args[key .. '_имя'] = record.name
args[key .. '_номер'] = record.number
end
end
neighbor('предыдущий', data.order[position - 1])
neighbor('следующий', data.order[position + 1])
return frame:expandTemplate{title = 'Листание по покедексу', args = args}
end
function export.stats(frame)
local pokemon = assert(data.pokemon[frame.args[1]], 'Неизвестный покемон')
local out = {'{| class="wikitable"', '! scope="col" | Характеристика', '! scope="col" | Значение', '! scope="col" | Шкала'}
local total = 0
for index, value in ipairs(pokemon.stats) do
total = total + value
local width = math.floor(value * 100 / 255 + 0.5)
local bar = '<div style="width:10em;max-width:100%;background-color:#dce5ed;border-radius:.2em;overflow:hidden;">' ..
'<div style="width:' .. width .. '%;height:.6em;background-color:#4c789c;"> </div></div>'
out[#out + 1] = '|-\n| ' .. statNames[index] .. '\n| ' .. value .. '\n| ' .. bar
end
out[#out + 1] = "|-\n| '''Сумма'''\n| " .. total .. '\n|\n|}'
return frame:preprocess(table.concat(out, '\n'))
end
return export
