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

local Util = require('Module:Util')

local p = {}

function p.getClasses(card)
	return card.multiClassGroup and mw.text.split(card.multiClassGroup,'_') or card.classes or {card.cardClass}
end

function p.getClassesCN(card) -- mw.logObject(p.getClassesCN(p.getByName('魔杖窃贼')))
	return Util.map(p.getClasses(card), require('Module:Data/class').get_name)
end

-- 设置接下来的卡牌数据缓存,避免多次查询
function p.cache(frame)
	local args = frame.args
	local name = args[1]
	return mw.getCurrentFrame():preprocess('{{#vardefine:card_data_cache|'..name..'}}')
end

function p.getByName(name)
	local cache = mw.getCurrentFrame():preprocess('{{#var:card_data_cache}}')
	if cache and cache~='' then
		return mw.loadData('Module:'..cache)[name]
	end
	return mw.huiji.db.findOne{
		main_category = 'card_data',
		collectible = true,
		name = name
	}
end

function p.getById(id)
	return mw.huiji.db.findOne{
		main_category = 'card_data',
		id = id
	}
end

return p
0.0
0人评价
avatar