跳转到内容

Module:ACT

来自Deltarune Wiki

local data = mw.loadData('Module:ACT/data')
local act = {}

local util = require('Module:Util')
local title = mw.title.getCurrentTitle()

function act.header(frame)
	local name = frame.args[1]
	local zhName = data.acts[name] or name
	local level = frame.args[2]
	local icons = {}
	for _, member in ipairs(util.parseCommaList(frame.args[3])) do
		if member ~= '' then
			table.insert(icons, string.format(
				'[[File:%s face battlemenu.png|24x24px|link=|%s]]',
				member, member
			))
		end
	end
	local class = ''
	if name == 'S-Action' then
		class = 'violet'
	elseif name == 'R-Action' then
		class = 'lightgreen'
	elseif name == 'N-Action' then
		class = 'lightyellow'
	end
	return string.format(
		'<h%s class="%s">%s%s</h%s>',
		level, class, table.concat(icons), string.format('%s(%s)', zhName, name), level
	)
end

function act.image(frame)
	local name = frame.args[1]
	local image = frame.args[2]
	if image == '' then
		local subject = title.text
		if title:inNamespace(2) and title.isSubpage then
			subject = title.subpageText
		end
		
		subject = data.characters[subject] or subject
		for _, file in ipairs(mw.title.newBatch{
			string.format('File:%s act %s.gif', subject, name),
			string.format('File:%s act %s.png', subject, name)
		}:lookupExistence():getTitles()) do
			if file.exists then
				image = file.text
				break
			end
		end
	end
	if image == '' then
		return
	end
	return string.format(
		'<p>[[File:%s|320px|%s]]</p>',
		image, name
	)
end

return act