Module:Collectible

From Arknights Terra Wiki
Jump to navigation Jump to search
local p = {}
local themeNameLookup = {
	cf = "Ceobe's Fungimist", 
	ej = "Expeditioner's Joklumarkar",
	mca = "Mizuki & Caerula Arbor",
	pcs = "Phantom & Crimson Solitaire",
	sff = "Sarkaz's Furnaceside Fables",
}
local qualityLookup = {
	normal = 1,
	rare = 2,
	superrare = 3,
}
local data = {
	cf = mw.loadData('Module:Collectible/cf'),
	ej = mw.loadData('Module:Collectible/ej'),
	mca = mw.loadData('Module:Collectible/mca'),
	pcs = mw.loadData('Module:Collectible/pcs'),
	sff = mw.loadData('Module:Collectible/sff'),
}
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
function p.main(frame)
	local args = getArgs(frame, {
		wrappers = 'Template:Collectible'
	})
	return p._main(args)
end
function p._main(args)
	local key = args[1]
	local themeName
	local col
	for k, v in pairs(data) do
		col = v[key]
		if col then
			themeName = themeNameLookup[k]
			break
		end
	end
	if not col then return '&#32;<i>Collectible not found</i>&#32;' end
	local name = col.name or key
	local image = col.image or col.name
	local text = col.title or col.name
	local link = col.link or col.name
	local attrs = {
		['data-name'] = name,
		['data-title'] = col.title,
		['data-num'] = col.num,
		['data-qlt'] = qualityLookup[col.qlt],
		['data-use'] = col.use,
		['data-desc'] = col.desc,
		['data-theme'] = themeName,
		['data-cond'] = col.cond,
	}
	local root = mw.html.create('')
	if yesno(args.gridview) then
		local div = root:tag('div')
		:attr('style', 'display:inline-block; position:relative; margin:5px;')
		local a = div:tag('div')
		:addClass('a')
		local tt = a:tag('div')
		:addClass('collectible-tooltip')
		:attr(attrs)
		:wikitext('[[File:'..image..'.png|60x60px|link='..link..']]')
		:tag('div')
		:attr('style', "margin-top:2px;")
		:wikitext('[['..link..'|'..text..']]')
	else
		local span = root:tag('span')
		:attr('style', 'display:inline-block;')
		local tt = span:tag('span')
		:addClass('collectible-tooltip')
		:attr(attrs)
		:wikitext('[[File:'..image..'.png|20x20px|link='..link..']]&#32;')
		:wikitext('[['..link..'|'..text..']]')
	end
	return root
end
return p