コンテンツにスキップ

モジュール:Character

提供: Deltarune Wiki

このモジュールについての説明文ページを モジュール:Character/doc に作成できます

--- Methods for managing character data storage and formatting.
--  @module             character
--  @require            Module:Util
--  @require            Module:Yesno
--  @author             [[User:KockaAdmiralac|KockaAdmiralac]]
--  @author             [[User:Jacky720|Jacky720]]
--  <nowiki>
require('strict')
local character = {}

--  Package imports.
local util = require('Module:Util')
local yesno = require('Module:Yesno')

--  Package variables.
local title = mw.title.getCurrentTitle()
local bucket = mw.ext.bucket

--- Formats a given enemy's ACT field in the infobox.
--  @function           character.act
--  @param              {table} frame Scribunto frame object
--  @returns            {string} Formatted ACTs
function character.act(frame)
	local str = {}
	local index = 0
	local nocheck = frame.args[2]
	nocheck = mw.text.trim(nocheck)
	nocheck = mw.text.split(nocheck, '%s*,%s*')
	for _, battle in ipairs(mw.text.split(frame.args[1], '*', true)) do
		-- battle: A given battle's ACTs, passed to the function 
		--  e.g. "Cry (First box encounter)"
		-- acts: The ACTs OTHER than Check
		--  e.g. "Cry"
		-- form: The form or battle with these ACTs
		--  e.g. "First box encounter"
		-- "nocheck" parameter (frame.args[2]) prevents auto-adding Check.
		battle = mw.text.trim(battle)
		if battle ~= '' then
			index = index + 1
			if index == 2 then
				table.insert(str, 1, '* ')
			end
			if index > 1 then
				table.insert(str, '\n* ')
			end
 
			local acts, form = mw.ustring.match(battle, '^([^(]*)%s*%(?([^)]*)%)?$')
			if not yesno(nocheck[index] or nocheck[1], false) then
				if acts ~= '' then
					table.insert(str, 'ぶんせき, ')
				else
					table.insert(str, 'ぶんせき ')
				end
			end
			table.insert(str, acts)
			if form ~= '' then
				table.insert(str, ' (')
				table.insert(str, form)
				table.insert(str, ')')
			end
		end
	end
	return table.concat(str)
end

--- Used for appending the Enemies category if the <code>gold</code> argument
--  is supplied, and the Vendors category if the <code>wares</code> argument
--  is supplied (this is how we determine their respective categories should
--  be applied).
--  @function           character.paramcat
--  @param              {table} frame Scribunto frame object
--  @returns            {string} The same thing with the category added
function character.paramcat(frame)
	local param = frame.args[1]
	if param == nil or param == '' then
		return
	end
	local str = {param}
	util.addCategory(str, frame.args[2])
	return table.concat(str)
end

--- Formats the parameter for linking back to Undertale Wiki.
--  Used only on Deltarune Wiki.
--  @function           character.undertale
--  @param              {table} frame Scribunto frame object
--  @returns            {string} Formatted returning character parameter
function character.undertale(frame)
	local str = {}
	local names = frame.args[1]
	if names == nil or names == '' then
		return
	end
	if yesno(names, false) then
		if frame.args[2] == '' then
			-- No name specified
			names = title.text
		else
			names = frame.args[2]
		end
	end
	
	-- Iterate over multiple names
	local namesList = {}
	for _, splitName in ipairs(mw.text.split(names, ',', true)) do
		local name = mw.text.trim(splitName)
		table.insert(namesList, string.format('[[ut:%s|%s]]', name, name))
	end

	table.insert(str, table.concat(namesList, ', '))
	if frame.args[2] == '' then
		-- Don't include category for NPC pages with separated infoboxes
		util.addCategory(str, 'Returning characters')
	end
	return table.concat(str)
end

--- Formats the infobox field for Lightner/Darkner classification and
--  categorizes the article. Only used on Deltarune Wiki.
--  @function           character.classification
--  @param              {table} frame Scribunto frame object
--  @returns            {string} List of all subject classifications
function character.classification(frame)
	local out = {}
	for cat in mw.text.gsplit(frame.args[1], ',', true) do
		local trimmedCat = mw.text.trim(cat)
		if trimmedCat == 'ライトナー' or trimmedCat == 'ダークナー' then
			table.insert(out, string.format('\n* [[%s]]', trimmedCat))
			util.addCategory(out, trimmedCat .. '')
		end
	end
	return table.concat(out)
end

return character