◆42Lab是非盈利性、非官方的云图计划维基百科。
◆诚邀指挥官们加入编辑部共同建设wiki。点这里加入42Lab
如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易!
◆有任何意见、建议、纠错,欢迎在任意评论区评论
◆编辑讨论QQ群741423564 微博@GFwiki少前百科 欢迎您

模块:SkillTable

来自42LAB

可在模块:SkillTable/doc创建此模块的帮助文档

local p = {}
local root
local args
local descs = {}
local lvs = {}
local note
local notes = {}

local function addNote(num)
	local notename = args['注释' .. tostring(num)]
	if notename and notename ~= '' then
		notes[#notes+1] = mw.getCurrentFrame():expandTemplate{title = '注释调用', args = { notename }}
	end
end

local function addLvRow(lv)
	local lvl = lvs[lv]
	if tonumber(lvl) == nil then lvl = 'x<sub>' .. string.sub(lvl, 2) .. '</sub>' end
	root:tag('tr'):tag('td'):css('text-align', 'center'):wikitext('LV.' .. lvl):done():tag('td'):wikitext(descs[lv])
end

local function addLvRows()
	for i = 1, 10 do
		local argname = '描述' .. tostring(i)
		if args[argname] and args[argname] ~= '' then
			descs[#descs+1] = args[argname]
			lvs[#lvs+1] = tostring(i)
		end
	end
	for i = 1, 9 do
		local argname = '描述x' .. tostring(i)
		if args[argname] and args[argname] ~= '' then
			descs[#descs+1] = args[argname]
			lvs[#lvs+1] = 'x' .. tostring(i)
		end
	end
	for i = 1, #descs do addLvRow(i) end
	root:addClass('mw-collapsed')
end

function p.skill(frame)
	args = frame == mw.getCurrentFrame() and frame:getParent().args or frame
	local icon = mw.getCurrentFrame():expandTemplate{ title = '技能图标', args = {
		['编号'] = args['编号'] or args['ID'] or args['id'] or 40000,
		['技能主被动'] = args['主被动'] or '被动',
		['技能类型'] = args['类型'] or '治疗',
		size = 80
	}}
	root = mw.html.create('table')
		:addClass('wikitable mw-collapsible'):css('width', '100%')
		:tag('tr'):tag('td'):wikitext(icon):done():tag('td'):css('width', '90%')
		:wikitext(string.format(
			[['''%s'''<br><span style="background:#%s;padding:.2em .6em .3em;font-weight:bold;line-height:1;color:white;text-align:left;white-space:nowrap;vertical-align:baseline;display:inline-block;">%s</span>%s<br>%s]],
			args['技能'], args['主被动'] == '自动' and '0B8FFF' or '474950',
			args['主被动'] or '被动',
			tonumber(args['冷却']) ~= nil and '<span style="margin-left:2em">⧗ ' .. args['冷却'] .. 's</span>' or '',
			args['精简']))
		:allDone()
	if args['描述'] and args['描述'] ~= '' then
		root:tag('tr'):tag('td'):css('text-align', 'center'):wikitext('无等级变化'):done():tag('td'):wikitext(args['描述'])
	else addLvRows() end
	for i = 1, 4 do
		argname = '注释' .. tostring(i)
		if args[argname] and args[argname] ~= '' then
			note = root:tag('tr'):tag('td'):wikitext([['''注释''']]):done():tag('td')
			for j = i, 4 do addNote(j) end
			note:wikitext(table.concat(notes, '<br>'))
			break
		end
	end
	return tostring(root)
end
return p