此模块的文档可以在模块:Card/link/doc创建

local Card = require('Module:Card')
local Util = require('Module:Util')

local p = {}

function p.fromTitle(frame) --=p.fromTitle{args={'Card/59670_bg'}}
	local args = frame.args
	local title = args[1] or '0'
	local id = tonumber(title:match('%d+'))
	local card = {}
	if id then
		card = mw.huiji.db.findOne{
			_source = {['$exists'] = true},
			['$or'] = {
				{dbfId = id},
				{id = id}
			}
		}
		if card.id then
			local bg = not not title:match('bg')
			return p.plain(card, bg)
		end
	else
		card = mw.huiji.db.findOne{
			_source = {['$exists'] = true},
			name = title
		}
		if card.name then
			return p.plain(card)
		end
	end
	return '[['..title..']]'
end

function p.plain(card, bg) --=p.plain(mw.huiji.db.findOne{_id='Data:Card/7.json'}) =p.plain(mw.huiji.db.findOne{_id='Data:Card/AT_006.json'})
	card = type(card._src)=='table' and card._src or card
	local func = card.dbfId and p.hsjson or p.battlenet
	return func(card, bg)
end
function p.hsjson(card, bg)
	if tonumber(card.id) then --转格式
		card = require('Module:Card/adapter/as_hsjson')(card)
	end
	if not card.dbfId then
		return '-'
	end
	if card.type=='ENCHANTMENT' then
		return 	require('Module:tooltip').simple(card.name, card.text, '[[状态'..(card.name and '|'..card.name or '')..']]')
	end
	local link = 'Card/'..card.dbfId
	if bg or bg~=false and (card.battlegroundsNormalDbfId or card.battlegroundsPremiumDbfId or card.battlegroundsHero) then link = link..' bg' end
	if type(card.name)=='table' then error(mw.dumpObject(card)) end
	return '<span class="huiji-tt" data-type="@Card/link" data-name="'..card.id..'">'
		..'[['..link..(card.name and '|'..card.name or '')..']]'
		..'</span>'
end
function p.battlenet(card, bg)
	if tonumber(card.id)==nil then --转格式
		card = require('Module:Card/adapter/as_battlenet')(card)
	end
	if tonumber(card.id)==nil then
		return '-'
	end
	local id = card.id
	if bg or bg~=false and card.battlegrounds then id = id..' bg' end
	local link = 'Card/'..id
	return '<span class="huiji-tt" data-type="@Card/link" data-name="'..id..'">'
		..'[['..link..(card.name and '|'..card.name or '')..']]'
		..'</span>'
end
function p.tooltip(frame)
	local id = frame.args[1]
	return '[[file:Card '..id..'.png|300px|link=]]'
end

function p.cost(frame)
	local args = frame:getParent().args
	local name = args[1]
	local text = args[2] or args[1]
	local id = require('Module:Card/name_to_id')(name)
	local cost = require('Module:Card/id_to_cost')(id)
	
	return '<span class="huiji-tt" data-type="@Card/link" data-name="'..id..'"'..(args['style'] and (' style="' .. args['style'] .. '"') or '')..'>'
		..'['..cost..'][['..name..'|'..text..']]</span>'
end

local function style(card)
	card = Util.clone(card)
	local name = card.name
	if mw.ustring.len(name)>7 then
		name = mw.ustring.sub(name,1,6)..'...'
	end
	return '<div class="huiji-tt" data-type="@Card/link" data-name="'..card.id..'" '
		..'style="border:1px solid #000;display:inline-flex;flex-wrap:nowrap;;width:180px;height:30px;margin:1px 2px;background:#333;color:#fff;">'
		..'<div class="bg_'..(card.rarity or 'FREE')..'" style="display:inline-flex;align-items:center;justify-content:center;padding:4px;width:25px;">'
			..(card.cost and '<b>'..card.cost..'</b>' or '')
		..'</div>'
		..'<span style="overflow:hidden;flex:1;">'
			..'[[Card/'..card.dbfId..'|'
				..'<span style="color:#fff;display:flex;height:100%;align-items:center;white-space:nowrap;padding:0 6px;">'
				..name..'</span>]]'
		..'</span>'
		..'<div class="bg_'..card.cardClass..'" style="display:flex;width:33px;align-items:center;justify-content:center;">'
			..'[[file:icon_'..card.cardClass:lower()..'.png|20px|link=]]'
		..'</div>'
	..'</div>'
end

-- 模板:Card link/style
function p.style(frame) --=p.style{'幼龙鹰'} =p.style{808}
	local data
	local key
	if frame._id then
		data = frame
	else
		local args = frame.getParent and frame:getParent().args or frame.args or frame
		key = args[1]
		data = Card.getOne(key)
	end
	if not data.name then return '未能找到对应的卡牌:'..key end
	return style(data)
end

return p
0.0
0人评价
avatar