七日内新公告:全站维护公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:SekaiCard

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳转到导航 跳转到搜索
模块文档  [查看] [编辑] [历史] [刷新]

用于{{SekaiCard}}

local getArgs = require('Module:Arguments').getArgs

local p = {}

-- 构造卡名
local function genCardName(cardName, textColor)
	if cardName and cardName ~= '' then
		textColor = textColor or 'black'
		return '<span style="color:' .. textColor .. '">' .. cardName .. '</span>'
	end
end

-- 构造桌面版卡面
local function genDeskCard(cardId, cardRarity)
	if cardId and cardId ~= '' then
		-- 四星和三星卡面,hover特训切换
		if cardRarity == '四星' or cardRarity == '三星' then
			return '<div class="hover-change">'
				.. '<div class="hover-change-before">[[File:Sekai card ' .. cardId .. '.png|600px|link=https://sekai.best/card/' .. cardId .. ']]</div>'
				.. '<div class="hover-change-after">[[File:Sekai card ' .. cardId .. ' trained.png|600px|link=https://sekai.best/card/' .. cardId .. ']]</div></div>'

		-- 其他卡面
		else
			return '[[File:Sekai card ' .. cardId .. '.png|600px|link=https://sekai.best/card/' .. cardId .. ']]'
		end
	end
end

-- 构造移动版卡面
local function genMobiCard(cardId, cardRarity, frame, args)
	if cardId and cardId ~= '' then
		-- 四星和三星卡面,tabs特训切换
		if cardRarity == '四星' or cardRarity == '三星' then
			local tabArgs = {
				LabelColor = args['Shadowcolor'] or '#d39a62',
				LabelBorderColor = 'transparent',
				TextBorderColor = 'transparent',
				TextBackgroundColor = 'transparent',
				TextPadding = '0',
				LabelBackgroundColor = args['color'] or '#ca8',
				bt1  = '特训前',
				tab1 = '[[File:Sekai card ' .. cardId .. '.png|600px|link=https://sekai.best/card/' .. cardId .. ']]',
				bt2  = '特训后',
				tab2 = '[[File:Sekai card ' .. cardId .. ' trained.png|600px|link=https://sekai.best/card/' .. cardId .. ']]'
			}
			return frame:expandTemplate{ title = 'tabs', args = tabArgs }

		-- 其他卡面
		else
			return '[[File:Sekai card ' .. cardId .. '.png|600px|link=https://sekai.best/card/' .. cardId .. ']]'
		end
	end
end

-- 归并指定类型的所有卡
local function collectCards(cardType, frame, args)
	local cards = {}
	local i = 1

	while args[cardType .. '卡名' .. i] do
		local cardName = args[cardType .. '卡名' .. i]
		local cardId   = args[cardType .. '卡ID' .. i]

		if cardName and cardName ~= '' then
			table.insert(cards, {
				name = genCardName(cardName, args['Textcolor']),
				desk = genDeskCard(cardId, cardType),
				mobi = genMobiCard(cardId, cardType, frame, args),
				id = cardId
			})
		end

		i = i + 1
	end

	return cards
end

-- 构造稀有度tabs
local function genRarityTabs(cards, cardType, frame, args, isMobi)
	if #cards ~= 0 then
		local tabArgs = {
			LabelColor = args['Shadowcolor'] or '#d39a62',
			LabelBorderColor = 'transparent',
			TextBorderColor = 'transparent',
			TextBackgroundColor = 'transparent',
			TextPadding = '0',
			LabelBackgroundColor = args['color'] or '#ca8'
		}

		if not isMobi then
			tabArgs['LabelSide'] = 'left'
		end

		for i, card in ipairs(cards) do
			tabArgs['bt' .. i] = card.name
			if isMobi and (cardType == '四星' or cardType == '三星') then
				tabArgs['tab' .. i] = card.mobi
			else
				tabArgs['tab' .. i] = card.desk
			end
		end

		return frame:expandTemplate{ title = 'tabs', args = tabArgs }
	end
end

function p.main(frame)
	local args = getArgs(frame)

	-- 归并各类卡
	local birthdayCards  = collectCards('生日', frame, args)
	local fourStarCards  = collectCards('四星', frame, args)
	local threeStarCards = collectCards('三星', frame, args)
	local twoStarCards   = collectCards('二星', frame, args)
	local oneStarCards   = collectCards('一星', frame, args)

	-- 说明文字
	local ps = '{{ps|卡名前的icon代表{{mousetext|附属团体|仅Virtual Singer}}及[[世界计划 缤纷舞台! feat. 初音未来/游戏系统#成员卡片信息|卡牌属性]]<br>'
			.. ' {{Gradient Text|gold,orange|金黄色}}卡名代表这是一张{{mousetext|banner|对应活动的主角}}卡<br>'
			.. ' {{Gradient Text|pink,magenta|粉红色}}卡名代表这是一张[[世界计划 缤纷舞台! feat. 初音未来/游戏系统#普通(Pick UP)扭蛋|普通限定]]卡<br>'
			.. ' {{Gradient Text|aqua,silver|水蓝色}}卡名代表这是一张[[世界计划 缤纷舞台! feat. 初音未来/游戏系统#特殊扭蛋|Fes限定]]卡<br>'
			.. ' {{Gradient Text|lime,green|青绿色}}卡名代表这是一张{{mousetext|[[世界计划 缤纷舞台! feat. 初音未来/游戏系统#特殊扭蛋|箱活限定]]卡|即World Link}}<br>'
			.. ' {{Gradient Text|purple,violet|蓝紫色}}卡名代表这是一张{{mousetext|特殊活动|包括游戏内联动与线下活动}}限定卡}}'

	local tips = {
		desk = 'Tip:将鼠标移入三、四星卡面即可查看特训后卡面。想查看特训前的卡面请点击特训后的卡面后再选择查看~<br>' .. ps,
		mobi = 'Tip:若图片长时间未加载,请点击图片区域以查看~ 亲测有效<br><br>' .. ps
	}

	-- 构建外层tabs
	local function genOuterTabs(isMobi)
		local outerArgs = {
			LabelColor = args['Shadowcolor'] or '#d39a62',
			LabelBorderColor = 'transparent',
			TextBorderColor = 'transparent',
			TextBackgroundColor = 'transparent',
			TextPadding = '0',
			LabelBackgroundColor = args['color'] or '#ca8'
		}

		-- 生日卡
		if #birthdayCards > 0 then
			outerArgs['bt1']  = frame:expandTemplate{ title = 'Project Sekai/Icon', args = { '生日', '16' } }
			outerArgs['tab1'] = genRarityTabs(birthdayCards, '生日', frame, args, isMobi)
		end

		-- 四星卡
		if #fourStarCards > 0 then
			outerArgs['bt2']  = frame:expandTemplate{ title = 'Project Sekai/Icon', args = { '四星', '16' } }
			outerArgs['tab2'] = genRarityTabs(fourStarCards, '四星', frame, args, isMobi)
		end

		-- 三星卡
		if #threeStarCards > 0 then
			outerArgs['bt3']  = frame:expandTemplate{ title = 'Project Sekai/Icon', args = { '三星', '16' } }
			outerArgs['tab3'] = genRarityTabs(threeStarCards, '三星', frame, args, isMobi)
		end

		-- 二星卡
		if #twoStarCards > 0 then
			outerArgs['bt4']  = frame:expandTemplate{ title = 'Project Sekai/Icon', args = { '二星', '16' } }
			outerArgs['tab4'] = genRarityTabs(twoStarCards, '二星', frame, args, isMobi)
		end

		-- 一星卡
		if #oneStarCards > 0 then
			outerArgs['bt5']  = frame:expandTemplate{ title = 'Project Sekai/Icon', args = { '一星', '16' } }
			outerArgs['tab5'] = genRarityTabs(oneStarCards, '一星', frame, args, isMobi)
		end

		return frame:expandTemplate{ title = 'tabs', args = outerArgs }
	end

	local out = {}

	-- 桌面版
	table.insert(out, '<div class="nomobile">')
	table.insert(out, tips['desk'])
	table.insert(out, genOuterTabs(false))
	table.insert(out, '</div>')

	-- 移动版
	table.insert(out, '<div class="mobileonly">')
	table.insert(out, tips['mobi'])
	table.insert(out, genOuterTabs(true))
	table.insert(out, '</div>')

	return frame:preprocess(table.concat(out))
end

return p