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
-- SSR和SR卡面,hover解放切换
if cardRarity == 'SSR' or cardRarity == 'SR' then
return '<div class="hover-change">'
.. '<div class="hover-change-before">[[File:18TRIP card ' .. cardRarity .. ' ' .. cardId .. '.png|600px]]</div>'
.. '<div class="hover-change-after">[[File:18TRIP card ' .. cardRarity .. ' ' .. cardId .. ' trained.png|600px]]</div></div>'
-- R卡面
else
return '[[File:18TRIP card R ' .. cardId .. '.png|600px]]'
end
end
end
-- 构造移动版卡面
local function genMobiCard(cardId, cardRarity, frame, args)
if cardId and cardId ~= '' then
-- SSR和SR卡面,tabs解放切换
if cardRarity == 'SSR' or cardRarity == 'SR' then
local tabArgs = {
LabelColor = args['Shadowcolor'] or '#d39a62',
LabelBorderColor = 'transparent',
TextBorderColor = 'transparent',
TextBackgroundColor = 'transparent',
TextPadding = '0',
LabelBackgroundColor = args['color'] or '#ca8',
bt1 = '解放前',
tab1 = '[[File:18TRIP card ' .. cardRarity .. ' ' .. cardId .. '.png|600px]]',
bt2 = '解放后',
tab2 = '[[File:18TRIP card ' .. cardRarity .. ' ' .. cardId .. ' trained.png|600px]]'
}
return frame:expandTemplate{ title = 'tabs', args = tabArgs }
-- R卡面
else
return '[[File:18TRIP card R ' .. cardId .. '.png|600px]]'
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 == 'SSR' or cardType == 'SR') 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 ssrCards = collectCards('SSR', frame, args)
local srCards = collectCards('SR', frame, args)
local rCards = collectCards('R', frame, args)
-- 说明文字
local ps = '{{ps|卡名前的图示代表卡牌的职业<br>'
.. ' {{Gradient Text|gold,orange|金黄色}}卡名代表这是一张{{mousetext|生日招募|只能透过生日限定招募获得}}卡<br>'
.. ' {{Gradient Text|pink,magenta|粉红色}}卡名代表这是一张{{mousetext|活动看板|对应活动的主角}}卡<br>'
.. ' {{Gradient Text|lime,green|青绿色}}卡名代表这是一张{{mousetext|活动报酬|活动的奖励}}卡}}'
local tips = {
desk = 'Tip:将鼠标移入SR、SSR卡面即可查看解放后卡面,想查看解放前的卡面请点击解放后的卡面后再选择查看!<br>' .. ps,
mobi = 'Tip:若图片长时间未加载,请点击图片区域以查看,亲测有效!<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'
}
-- SSR卡
if #ssrCards > 0 then
outerArgs['bt1'] = frame:expandTemplate{ title = '18TRIP/Icon', args = { 'SSR' } }
outerArgs['tab1'] = genRarityTabs(ssrCards, 'SSR', frame, args, isMobi)
end
-- SR卡
if #srCards > 0 then
outerArgs['bt2'] = frame:expandTemplate{ title = '18TRIP/Icon', args = { 'SR' } }
outerArgs['tab2'] = genRarityTabs(srCards, 'SR', frame, args, isMobi)
end
-- R卡
if #rCards > 0 then
outerArgs['bt3'] = frame:expandTemplate{ title = '18TRIP/Icon', args = { 'R' } }
outerArgs['tab3'] = genRarityTabs(rCards, 'R', 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