Module:Partnertable

来自Arcaea中文维基
盐棋讨论 | 贡献2024年12月14日 (六) 01:24的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

可在Module:Partnertable/doc创建此模块的帮助文档

local getArgs = require 'Module:Arguments'.getArgs
local lang = mw.getContentLanguage()
local p = {}

function labelText(text)
	return mw.html.create 'span':addClass 'label-text':wikitext(text)
end

function updateReplace(version)
	-- local result = string.gsub(version, 'V(%d+%.%d+)', 'v%1')
	-- local result = string.gsub(version, '(%d+c?)%(', '%1<br>(')
	-- local result = string.gsub(version, '[^]%f[(]', '<br>(')
	local result = string.gsub(version, '(%d+c?)%(', '%1<br>(')
	return result
end

function update(version, device, awakenyes, version2) --更新时间
	local deviceEpitaxy = (device == 'ns') and 'NS版' or '移动版'
	local versionEpitaxy = (awakenyes and version ~= version2 and version2)
		and {'搭档:', updateReplace(version), '<br>觉醒形态:', updateReplace(version2)}
		or {updateReplace(version)}
	local dataBox = mw.html.create 'div':addClass 'date-box'
	dataBox:tag 'div':node(labelText(deviceEpitaxy)):done()
		:tag 'div':wikitext(unpack(versionEpitaxy)):done()
	return dataBox
end

function skill(text, skilldiff, label)
	local result = mw.html.create()
	if skilldiff then result:tag 'div':node(labelText(label)) end
	result:wikitext(text)
	return result
end

function title(...)
	return mw.text.listToText({...}, '<br>', '<br>')
end

function version(time)
	return ({string.find(time, '([vV]%d+%.%d+%.%d+c?)')})[3] or 'unknown'
end

function getImage(normal, awaken, normalJacket, awakenJacket, awakenyes, type)
	local container = mw.html.create 'div':addClass 'container'
	local JacketNormal = normalJacket
	if awaken then
		local JacketAwaken = awakenJacket or normalJacket
		container -- tab
			:tag 'div':addClass 'img-tab':attr('id', 'tab-' .. type)
			:tag 'div':wikitext 'Normal':addClass 'img-tab-part normal active':done()
			:tag 'div':wikitext 'Awaken':addClass 'img-tab-part awaken':done()
		container -- part
			:tag 'div':wikitext('[[文件:', normal, '|300px|none]]'):node(labelText '画师'):wikitext(tostring(JacketNormal)):addClass('active tab-text-' .. type):done()
			:tag 'div':wikitext('[[文件:', awaken, '|300px|none]]'):node(labelText '画师'):wikitext(tostring(JacketAwaken)):addClass('tab-text-' .. type):done()
	else
		container
			:tag 'div':wikitext('[[文件:', normal, '|300px]]'):done()
			:tag 'div':node(labelText '画师'):wikitext(JacketNormal):done()
	end
	return container
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local awaken   --觉醒判定
	local size     --图片大小
	local belongs  --所属单位
	local skillawaken --觉醒技能
	local skillsec --第二技能
	if args['觉醒形态'] == '有' then awaken = true else awaken = false end
	if awaken and args['技能'] ~= args['觉醒技能'] and args['觉醒技能'] ~= nil then skillawaken = true else skillawaken = false end
	if args['第二技能'] then skillsec = true else skillsec = false end
	if args['所属曲包'] then
		belongs = '所属曲包'
	elseif args['所属单曲'] then
		belongs = '所属单曲'
	else
		belongs = '所属单曲/曲包'
	end
	local imageA = getImage(args['图片'], args['觉醒图片'], args['画师'], args['觉醒画师'], awaken, 'a')
	local imageB = getImage(args['图片'], args['觉醒图片'], args['画师'], args['觉醒画师'], awaken, 'b')
	local infoList = {
		[1] = {title(args['名称'], args['第二名称']), {id = 'title'}},
		[2] = {imageA, {id = 'top-image'}},
		[3] = {imageB, {id = 'right-image'}},
		[4] = {'搭档信息', {class = 'header'}},
		[5] = {'类型', {class = 'label'}},
		[6] = {args['类型'], {class = 'data'}},
		[7] = {belongs, {class = 'label'}},
		[8] = {args[belongs] or '-', {class = 'data'}},
		[9] = {'种类', {class = 'label'}},
		[10] = {args['种类'] or '-', {class = 'data'}},
		[11] = {'觉醒形态', {class = 'label'}},
		[12] = {args['觉醒形态'] or '无', {class = 'data'}},
		[13] = {'搭档数据', {class = 'header', id = 'all-play-header'}},
		[14] = {'搭档数据 (移动版)', {class = 'header', id = 'mobile-play-header'}},
		[15] = {'等级', {class = 'label'}},
		[16] = {'Lv1', {class = 'level-data'}},
		[17] = {'Lv20', {class = 'level-data'}},
		[18] = {'Lv30', {class = 'awaken-data'}},
		[19] = {'Frag', {class = 'label'}},
		[20] = {args['Frag1'], {class = 'level-data'}},
		[21] = {args['Frag20'], {class = 'level-data'}},
		[22] = {args['Frag30'], {class = 'awaken-data'}},
		[23] = {'Step', {class = 'label'}},
		[24] = {args['Step1'], {class = 'level-data'}},
		[25] = {args['Step20'], {class = 'level-data'}},
		[26] = {args['Step30'], {class = 'awaken-data'}},
		[27] = {'Over', {class = 'label over'}},
		[28] = {args['Over1'], {class = 'level-data over'}},
		[29] = {args['Over20'], {class = 'level-data over'}},
		[30] = {args['Over30'], {class = 'awaken-data over'}},
		[31] = {'搭档数据 (Nintendo Switch版)', {class = 'header ns', id = 'ns-play-header'}},
		[32] = {'等级', {class = 'label ns'}},
		[33] = {'Lv1', {class = 'level-data ns'}},
		[34] = {'Lv20', {class = 'level-data ns'}},
		[35] = {'Lv30', {class = 'awaken-data ns'}},
		[36] = {'Frag', {class = 'label ns'}},
		[37] = {args['Frag1NS'], {class = 'level-data ns'}},
		[38] = {args['Frag20NS'], {class = 'level-data ns'}},
		[39] = {args['Frag30NS'], {class = 'awaken-data ns'}},
		[40] = {'Step', {class = 'label ns'}},
		[41] = {args['Step1NS'], {class = 'level-data ns'}},
		[42] = {args['Step20NS'], {class = 'level-data ns'}},
		[43] = {args['Step30NS'], {class = 'awaken-data ns'}},
		[44] = {'技能', {class = 'label', id = 'skill-label'}},
		[45] = {skill(args['技能'] or '-', skillawaken, '普通形态'), {class = 'data', id = 'skill-normal'}},
		[46] = {skill(args['觉醒技能'] or args['技能'], skillawaken, '觉醒形态'), {class = 'data', id = 'skill-awaken'}},
		[47] = {skill(args['技能'], skillsec, args['第一技能说明'] or '第一技能'), {class = 'data', id = 'skill-first'}},
		[48] = {skill(args['第二技能'], skillsec, args['第二技能说明'] or '第二技能'), {class = 'data', id = 'skill-first'}},
		[49] = {'更新时间', {id = 'update-data-label', class = 'label'}},
		[50] = {update(args['更新时间'] or '无', 'mobile', awaken, args['觉醒更新时间'] or args['更新时间']), {id = 'mobile-date-normal', class = 'data'}},
		[51] = {update(args['更新时间NS'] or '无', 'ns', awaken, args['觉醒更新时间NS'] or args['更新时间NS']), {id = 'ns-date-normal', class = 'data'}}
	}

	local box = mw.html.create 'div'

	--样式控制
	box:addClass 'partnerbox arcaeabox'
	if awaken then box:addClass 'awaken' end
	-- if args['名称'] == '' then box:addClass( "ns-only" ) end
	if skillawaken then box:addClass 'skill-awaken' end
	if skillsec then box:addClass 'skill-second' end
	if args['类型'] == '支援型' then
		box:addClass 'support'
	elseif args['类型'] == '挑战型' then
		box:addClass 'challenge'
	else
		box:addClass 'balance'
	end

	if args['更新时间NS'] then
		box:addClass 'ns-box'
	end

	--表格生成
	local mwHtmlMeta = getmetatable(box)
	for _, v in ipairs(infoList) do
		local cell = box:tag 'div':attr(v[2]):cssText(v[3])
		if getmetatable(v[1]) == mwHtmlMeta then cell:node(v[1]) else cell:wikitext(tostring(v[1])) end
	end

	--分类添加
	local category = mw.html.create()

	--平台
	local plat
	if args['更新时间NS'] then
		if args['更新时间'] then
			plat = '双平台'
		else
			plat = 'NS版'
		end
	else
		plat = '移动版'
	end
	category:wikitext('[[分类:', plat, '搭档]]')

	--觉醒
	category:wikitext('[[分类:', awaken and '有' or '没有', '觉醒形态的', '搭档]]')

	--类型
	local type = args['类型'] or '平衡型'
	local typeSet = {['支援型'] = true, ['平衡型'] = true, ['挑战型'] = true,}
	category:wikitext('[[分类:', typeSet[type] and type or '特殊类型', '搭档]]')
	-- ???/创世型; ???/探索者; ???

	--种类
	local cMap = {['限时'] = '限时活动', ['特殊'] = '获取方式特殊的', ['专辑'] = 'Arcaea原声专辑特典',}
	for c in mw.text.gsplit(args['种类'], '/', true) do
		if c ~= '原创' then
			category:wikitext('[[分类:', cMap[c] or c, '搭档]]')
		end
	end

	--版本
	if args['更新时间'] then
		category:wikitext('[[分类:', lang:ucfirst(version(args['更新时间'])), '添加的', '搭档]]')
	end
	if awaken then
		category:wikitext('[[分类:', lang:ucfirst(version(args['觉醒更新时间'] or args['更新时间'])), '添加觉醒形态的', '搭档]]')
	end
	if args['更新时间NS'] then
		category:wikitext('[[分类:', 'NS ', lang:ucfirst(version(args['更新时间NS'])), '添加的', '搭档]]')
	end

	--手动关闭
	if args['nocat'] then category = '' end

	return tostring(box) .. tostring(category)
end

return p