local p = {}
local getArgs = require('Module:Arguments').getArgs
local games = {
-- 通用
{ '', '图片' },
{ 'Normal', '常服' },
{ 'Phantom', '怪盗服' },
-- 正作
'P1',
'P2IS',
'P2EP',
'P3',
'P3F',
'P3P',
'P3R',
'P4',
'P4G',
'P4R',
'P5',
'P5R',
'P5X',
-- 外传
'P3D',
'P4A',
'P4AU',
'P4D',
'P5D',
'PQ',
'PQ2',
'P5S',
'P5T',
-- 其他
{ 'Persona', '初始人格面具' },
}
local colors = {
['Default'] = {
['top-bcolor'] = '#6fc67e',
},
['P1'] = {
['top-bcolor'] = '#65c',
['t-bcolor'] = '#65c',
['t-color'] = '#fff',
['l-bcolor'] = '#eef',
['l-color'] = '#000',
},
['P2'] = {
['top-bcolor'] = '#c66',
['t-bcolor'] = '#c66',
['t-color'] = '#fff',
['l-bcolor'] = '#fdd',
['l-color'] = '#000',
},
['P3'] = {
['top-bcolor'] = '#0bf',
['t-bcolor'] = '#0bf',
['t-color'] = '#fff',
['l-bcolor'] = '#9ef',
['l-color'] = '#000',
},
['P4'] = {
['top-bcolor'] = '#fe0',
['t-bcolor'] = '#fe0',
['t-color'] = '#000',
['l-bcolor'] = '#ffc',
['l-color'] = '#000',
},
['P5'] = {
['top-bcolor'] = '#c00',
['t-bcolor'] = '#c00',
['t-color'] = '#fff',
['l-bcolor'] = '#333',
['l-color'] = '#fff',
},
['Velvet Room'] = {
['top-bcolor'] = '#02b',
['t-bcolor'] = '#02b',
['t-color'] = '#fff',
['l-bcolor'] = '#36c',
['l-color'] = '#fff',
},
}
local tab_configuration = {
['P1'] = 'p1',
['P2'] = 'p2',
['P3'] = 'p3',
['P4'] = 'p4',
['P5'] = 'p5',
}
local arguments_configuration = {
{ '基本资料', {
{ '中文名', function(frame, args)
return args['中文名'] or args['译名'] or '{{PAGENAME}}'
end },
{ '日文名', function(frame, args)
return args['日文名'] or args['本名'] or ''
end },
'代号',
'别号',
{ '发色', function(frame, args)
local hair_color = args['发色'] or ''
if hair_color ~= '' then
return '{{Hair color|' .. hair_color .. '}}'
else
return args['多种发色'] or ''
end
end },
{ '瞳色', function(frame, args)
local eye_color = args['瞳色'] or ''
if eye_color ~= '' then
return '{{Eye color|' .. eye_color .. '}}'
else
return args['多种瞳色'] or ''
end
end },
{ '身高', function(frame, args)
local height = tonumber(args['身高'])
if height ~= nil then
return height .. 'cm'
else
return args['身高'] or ''
end
end },
{ '体重', function(frame, args)
local weight = tonumber(args['体重'])
if weight ~= nil then
return weight .. 'kg'
else
return args['体重'] or ''
end
end },
{ '年龄', function(frame, args)
local age = tonumber(args['年龄'])
if age ~= nil then
return age .. '岁'
else
return args['年龄'] or ''
end
end },
{ '生日', function(frame, args)
local birthday = args['生日'] or ''
if birthday ~= '' then
return '{{Birthday|' .. birthday .. '}}'
else
return args['特殊生日'] or ''
end
end },
{ '血型', function(frame, args)
local blood_type = args['血型'] or ''
if blood_type ~= '' then
if mw.ustring.sub(blood_type, -1) ~= '型' then
blood_type = blood_type .. '型'
end
return '[[:Category:' .. blood_type .. '|' .. blood_type .. ']]{{ArticleCategory|' .. blood_type .. '}}'
else
return args['特殊血型'] or ''
end
end },
{ '星座', function(frame, args)
local constellation = args['星座'] or ''
if constellation ~= '' then
return '{{星座分类|' .. constellation .. '}}'
else
return ''
end
end },
{ '声优', function(frame, args)
local cv = args['声优'] or ''
if cv ~= '' then
return '{{声优|' .. cv .. '}}'
else
local cv_ja = args['日文声优'] or ''
if cv_ja ~= '' then
return '日文:{{声优|' .. cv_ja .. '}}<br />中文:{{声优|' .. (args['中文声优'] or '') .. '}}'
else
return args['多位声优'] or ''
end
end
end },
'演员',
'萌点',
'职业',
'出身地区',
'活动范围',
'所属团体',
'个人状态',
}},
{ '人格面具相关', {
'阿尔卡那',
'初始人格面具',
'二觉人格面具',
'三觉人格面具',
'近战武器',
'远程武器',
'宫殿形象',
'现实位置',
'宝物',
'代表寓意',
}},
{ '社群等级', {
'Rank 1',
'Rank 2',
'Rank 3',
'Rank 4',
'Rank 5',
'Rank 6',
'Rank 7',
'Rank 8',
'Rank 9',
'Rank 10',
'Rank 11',
'Rank 12',
'Rank 13',
'Rank 14',
'Rank 15',
'Rank 16',
'Rank 17',
'Rank 18',
'Rank 19',
'Rank 20',
'Rank Max'
}},
{ '亲属或相关人', {
{ '_', function(frame, args)
return args['相关人士'] or ''
end },
}},
{ '总攻击', {
{ '_', function(frame, args)
if args['scheme'] ~= 'P5' and args['scheme'] ~= 'Velvet Room' then
return ''
end
local file_name = args['image-总攻击'] or ''
if file_name ~= '' then
return '[[File:' .. file_name .. '|280x600px]]'
else
return ''
end
end },
}},
{ '总攻击最后一击', {
{ '_', function(frame, args)
if args['scheme'] ~= 'P5' and args['scheme'] ~= 'Velvet Room' then
return ''
end
local file_name = args['image-总攻击最后一击'] or ''
if file_name ~= '' then
return '[[File:' .. file_name .. '|280x600px]]'
else
return ''
end
end },
}},
}
function p._main(frame, args)
local output = {
['notitle'] = '1',
['l-width'] = '6em',
['i-style'] = 'margin: 3px 0; padding: 0;',
}
local scheme = colors[args['scheme'] or 'Default'] or {}
local color_theme = scheme['top-bcolor'] or '#6fc67e'
for k, v in pairs(scheme) do
output[k] = v
end
local tabs = args['tabs'] or ''
if tabs ~= '' then
output['tabs'] = tabs
else
local tabs_output = {
['LabelBackgroundColor'] = '#fff',
['TextBackgroundColor'] = '#fff',
['LabelColor'] = color_theme,
['LabelBorderColor'] = color_theme,
['TextBorderColor'] = color_theme,
['TextPadding'] = '0',
['DefaultTab'] = args['default-image'] or '1',
}
local tab_index = 1
local insert_tab = function(label, content)
if content and content ~= '' then
tabs_output['bt' .. tab_index] = label
tabs_output['tab' .. tab_index] = frame:preprocess(content)
tab_index = tab_index + 1
end
end
for _, game in ipairs(games) do
local key, game_label = nil, nil
if type(game) == 'table' then
key = game[1]
game_label = game[2]
else
key = game
game_label = game
end
local image = nil
if key ~= '' then
image = args['image-' .. key] or ''
else
image = args['image'] or ''
end
if image ~= '' then
insert_tab(game_label, '[[File:' .. image .. '|280x600px]]')
end
end
local i = 1
while true do
local label = args['image-label-' .. i]
if label ~= nil then
insert_tab(label, '[[File:' .. args['image-' .. i] .. '|280x600px]]')
i = i + 1
else
break
end
end
if tab_index < 3 then
output['tabs'] = tabs_output['tab1'] or ''
else
output['tabs'] = '<div class="PTabs ' .. (tab_configuration[args['scheme'] or 'Default'] or '') .. '">' .. frame:expandTemplate{
title = 'Tabs',
args = tabs_output,
} .. '</div>' .. frame:extensionTag('templatestyles', nil, {
['src'] = 'PTabs/styles.css',
})
end
end
output['图片说明'] = args['图片说明'] or ''
for _, group in ipairs(arguments_configuration) do
local group_name = group[1]
local active = false
for _, item in ipairs(group[2]) 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 processor then
value = processor(frame, args)
else
value = args[key] or ''
end
if value and value ~= '' then
if not active then
table.insert(output, '- :: ' .. group_name)
active = true
end
table.insert(output, key .. ' :: ' .. frame:preprocess(value))
end
end
end
return frame:expandTemplate{
title = 'Infobox3',
args = output,
}
end
function p.main(frame)
return p._main(frame, getArgs(frame))
end
return p