local p = {}
local getArgs = require('Module:Arguments').getArgs
local render_rate = function(code)
if code == '255' then return '无性别' end
if code == '254' then return '全为雌性' end
if code == '223' then return '雄性:雌性 = 1:7' end
if code == '191' then return '雄性:雌性 = 1:3' end
if code == '127' then return '雄性:雌性 = 1:1' end
if code == '63' then return '雄性:雌性 = 3:1' end
if code == '31' then return '雄性:雌性 = 7:1' end
if code == '0' then return '全为雄性' end
return code
end
local get_enname = function(code)
code = mw.ustring.gsub(code, '[%-_]', ' ')
local match = mw.ustring.match(code, 'File:%d+%S+ (.+)%.png')
return match or code
end
local arguments_configuration = {
{ '中文', 'name' },
{ '日文', 'jname' },
{ '英文', 'enname' },
{ '编号', 'ndex' },
{ 'gen', function(frame, args)
local index = tonumber(args['ndex'])
if not index then return end
if index <= 151 then return '1' end
if index <= 251 then return '2' end
if index <= 386 then return '3' end
if index <= 493 then return '4' end
if index <= 649 then return '5' end
if index <= 721 then return '6' end
if index <= 802 then return '7' end
if index <= 807 then return '7-2' end
if index <= 809 then return '7-3' end
if index <= 898 then return '8' end
if index <= 905 then return '8-2' end
if index <= 1025 then return '9' end
return '10'
end },
{ 'form1', 'form1' },
{ 'form2', 'form2' },
{ '英文2', function(frame, args)
local code = args['imagecode2']
if not code then return end
return get_enname(code)
end },
{ 'form3', 'form3' },
{ '英文3', function(frame, args)
local code = args['imagecode3']
if not code then return end
return get_enname(code)
end },
{ 'form4', 'form4' },
{ '英文4', function(frame, args)
local code = args['imagecode4']
if not code then return end
return get_enname(code)
end },
{ 'form5', 'form5' },
{ '英文5', function(frame, args)
local code = args['imagecode5']
if not code then return end
return get_enname(code)
end },
{ 'form6', 'form6' },
{ '英文6', function(frame, args)
local code = args['imagecode6']
if not code then return end
return get_enname(code)
end },
{ 'type1', 'type1' },
{ 'type2', 'type2' },
{ 'type2-1', 'type1-2' },
{ 'type2-2', 'type2-2' },
{ 'type3-1', 'type1-3' },
{ 'type3-2', 'type2-3' },
{ 'type4-1', 'type1-4' },
{ 'type4-2', 'type2-4' },
{ 'type5-1', 'type1-5' },
{ 'type5-2', 'type2-5' },
{ 'type6-1', 'type1-6' },
{ 'type6-2', 'type2-6' },
{ '旧译', function(frame, args)
return frame:expandTemplate { title = 'User:Xzonn/旧译', args = { args['name'] } }
end },
{ '常用称呼', function(frame, args)
return ' '
end },
{ '分类', 'species' },
{ '分类2', 'species2' },
{ '分类3', 'species3' },
{ '分类4', 'species4' },
{ '分类5', 'species5' },
{ '分类6', 'species6' },
{ '特性', function(frame, args)
if not args['ability1'] then return end
return args['ability1'] .. (args['ability2'] and '/' .. args['ability2'] or '')
end },
{ '特性2', function(frame, args)
if not args['ability1-2'] then return end
return args['ability1-2'] .. (args['ability2-2'] and '/' .. args['ability2-2'] or '')
end },
{ '特性3', function(frame, args)
if not args['ability1-3'] then return end
return args['ability1-3'] .. (args['ability2-3'] and '/' .. args['ability2-3'] or '')
end },
{ '特性4', function(frame, args)
if not args['ability1-4'] then return end
return args['ability1-4'] .. (args['ability2-4'] and '/' .. args['ability2-4'] or '')
end },
{ '特性5', function(frame, args)
if not args['ability1-5'] then return end
return args['ability1-5'] .. (args['ability2-5'] and '/' .. args['ability2-5'] or '')
end },
{ '特性6', function(frame, args)
if not args['ability1-6'] then return end
return args['ability1-6'] .. (args['ability2-6'] and '/' .. args['ability2-6'] or '')
end },
{ '隐藏特性', 'abilityd' },
{ '隐藏特性2', 'abilityd2' },
{ '隐藏特性3', 'abilityd3' },
{ '隐藏特性4', 'abilityd4' },
{ '隐藏特性5', 'abilityd5' },
{ '隐藏特性6', 'abilityd6' },
{ '身高', function(frame, args)
local height = args['height']
if not height then return end
return height .. 'm'
end },
{ '身高2', function(frame, args)
local height = args['height2']
if not height then return end
return height .. 'm'
end },
{ '身高3', function(frame, args)
local height = args['height3']
if not height then return end
return height .. 'm'
end },
{ '身高4', function(frame, args)
local height = args['height4']
if not height then return end
return height .. 'm'
end },
{ '身高5', function(frame, args)
local height = args['height5']
if not height then return end
return height .. 'm'
end },
{ '身高6', function(frame, args)
local height = args['height6']
if not height then return end
return height .. 'm'
end },
{ '体重', function(frame, args)
local weight = args['weight']
if not weight then return end
return weight .. 'kg'
end },
{ '体重2', function(frame, args)
local weight = args['weight2']
if not weight then return end
return weight .. 'kg'
end },
{ '体重3', function(frame, args)
local weight = args['weight3']
if not weight then return end
return weight .. 'kg'
end },
{ '体重4', function(frame, args)
local weight = args['weight4']
if not weight then return end
return weight .. 'kg'
end },
{ '体重5', function(frame, args)
local weight = args['weight5']
if not weight then return end
return weight .. 'kg'
end },
{ '体重6', function(frame, args)
local weight = args['weight6']
if not weight then return end
return weight .. 'kg'
end },
{ '性别比例', function(frame, args)
local code = args['gendercode']
if not code then return end
return render_rate(code)
end },
{ '性别比例2', function(frame, args)
local code = args['gendercode2']
if not code then return end
return render_rate(code)
end },
{ '性别比例3', function(frame, args)
local code = args['gendercode3']
if not code then return end
return render_rate(code)
end },
{ '性别比例4', function(frame, args)
local code = args['gendercode4']
if not code then return end
return render_rate(code)
end },
{ '性别比例5', function(frame, args)
local code = args['gendercode5']
if not code then return end
return render_rate(code)
end },
{ '性别比例6', function(frame, args)
local code = args['gendercode6']
if not code then return end
return render_rate(code)
end },
{ '蛋群', function(frame, args)
if not args['egggroup1'] then return end
return args['egggroup1'] .. (args['egggroup2'] and '/' .. args['egggroup2'] or '')
end },
{ '蛋群2', function(frame, args)
if not args['egggroup1-2'] then return end
return args['egggroup1-2'] .. (args['egggroup2-2'] and '/' .. args['egggroup2-2'] or '')
end },
{ '蛋群3', function(frame, args)
if not args['egggroup1-3'] then return end
return args['egggroup1-3'] .. (args['egggroup2-3'] and '/' .. args['egggroup2-3'] or '')
end },
{ '蛋群4', function(frame, args)
if not args['egggroup1-4'] then return end
return args['egggroup1-4'] .. (args['egggroup2-4'] and '/' .. args['egggroup2-4'] or '')
end },
{ '蛋群5', function(frame, args)
if not args['egggroup1-5'] then return end
return args['egggroup1-5'] .. (args['egggroup2-5'] and '/' .. args['egggroup2-5'] or '')
end },
{ '蛋群6', function(frame, args)
if not args['egggroup1-6'] then return end
return args['egggroup1-6'] .. (args['egggroup2-6'] and '/' .. args['egggroup2-6'] or '')
end },
{ '进化链', function(frame, args)
return ' '
end },
{ '多位声优', function(frame, args)
return ' '
end },
{ '萌点', function(frame, args)
return ' '
end },
{ '相关条目', function(frame, args)
return ' '
end },
{ 'info', function(frame, args)
return 'true'
end },
}
function p._main(frame, args)
local output = {
'{{Pokemon Infobox'
}
for _, item in ipairs(arguments_configuration) do
local key, processor = nil, nil
if type(item) == 'table' then
key = item[1]
processor = item[2]
else
key = item
end
local value = nil
if type(processor) == 'function' then
value = processor(frame, args)
elseif type(processor) == 'string' then
value = args[processor] or ''
else
value = args[key] or ''
end
if value and value ~= '' then
if value == ' ' then value = '' end
table.insert(output, '|' .. key .. ' = ' .. value)
end
end
table.insert(output, '}}')
return table.concat(output, '\n')
end
function p.main(frame)
return frame:preprocess(p._main(frame, getArgs(frame)))
end
function p.source(frame)
return frame:extensionTag('pre', '-{zh-cn|' .. p._main(frame, getArgs(frame)) .. '}-')
end
return p