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

local p = {}
local Util = require('Module:Util')
local Metadata = require('Module:Metadata')

local function GetName(id, list)
	return (Util.find(list, function(t) return t.id==id end) or {}).name or ''
end

local function TagByClass(classList)
	local map = {}
	for _,v in ipairs(require('Module:Data/class').list) do
		map[v.key] = v
	end
    local h = mw.html.create('span')
	for _, classId in ipairs(classList) do
		local class = ((Util.find(Metadata.classes, function(t) return t.id==classId end) or {}).slug or ''):upper()
    	local style_class = (map[class] or map['NEUTRAL']).class
    	h:tag('span'):addClass(style_class):wikitext(GetName(classId, Metadata.classes))
    end
    return h
end
local function CardTd(card)
	local res_html = mw.html.create()
	local rarity_icon = {
		[1] = '<div class ="C"></div>',
		[3] = '<div class ="R"></div>',
		[4] = '<div class ="E"></div>',
		[5] = '<div class ="L"></div>',
    }
	local rarity_res = rarity_icon[card.rarityId] or ''
	local name_link = require('Module:Card/link').plain(card)
	local type_res = GetName(card.cardTypeId, Metadata.types)
	local collectible_res = card.collectible~=1 and '<span class="text-danger">不可收集</span>' or ''
	res_html
        :tag('div'):addClass('card_name_title'):wikitext(rarity_res..' '..name_link):done()
        :tag('div'):addClass('card_name_subtitle'):wikitext(card.name_enUS or ''):done()
        :tag('div')
            :node(TagByClass(#card.multiClassIds>0 and card.multiClassIds or {card.classId}):addClass('card_class_subtitle'))
            :tag('span'):addClass('card_class_subtitle'):wikitext(' '..type_res..' '..collectible_res):done()
	return tostring(res_html)
end

function p.listTable(data, args)
	local top_div = mw.html.create()
	:tag('div'):cssText('width:100%;overflow-x:auto;')
	:tag('table'):addClass('wikitable sortable'):cssText('width:max-content;font-size:12px;margin:auto')
	:tag('tr')
		:tag('th'):wikitext('卡牌'):done()
		:tag('th'):wikitext('来源'):done()
		:tag('th'):wikitext('[[文件:Mana_icon.png|16px|link=]]'):done()
		:tag('th'):wikitext('[[文件:Attack_icon.png|16px|link=]]'):done()
		:tag('th'):wikitext('[[文件:Health_icon.png|16px|link=]]/[[文件:Weapon-durability.png|14px|link=]]'):done()
		:tag('th'):wikitext('卡牌描述'):done()
		:done()

	for _, card in ipairs(data) do
		card = require('Module:Card/adapter/as_battlenet')(card)
		local text = (card['text'] or ''):gsub('\\n',' ')
		local health = ''
		if card['health'] then
			health = health ..card['health']
			if card['durability'] then
				health = health ..'/' ..card['durability']
			end
		elseif card['durability'] then
			health = card['durability']
		end
		local set = '[['..GetName(card.cardSetId, Metadata.sets)..']]'

		top_div
        :tag('tr')
        	:tag('td'):wikitext(CardTd(card)):done()
        	:tag('td'):wikitext(set):done()
        	:tag('td'):wikitext(card['manaCost'] or ''):cssText('font-size:14px;text-align:center;'):done()
        	:tag('td'):wikitext(card['attack'] or ''):cssText('font-size:14px;text-align:center;'):done()
        	:tag('td'):wikitext(health):cssText('font-size:14px;text-align:center;'):done()
        	:tag('td'):wikitext(text)
    end
    return tostring(top_div)
end

return p
0.0
0人评价
avatar