Modül:Character
Methods for managing character data storage and formatting.
character.act(frame)(function)- Formats a given enemy's ACT field in the infobox.
- Parameter:
frameScribunto frame object (table) - Returns: Formatted ACTs (string)
character.paramcat(frame)(function)- Used for appending the Enemies category if the
goldargument is supplied, and the Vendors category if thewaresargument is supplied (this is how we determine their respective categories should be applied). - Parameter:
frameScribunto frame object (table) - Returns: The same thing with the category added (string)
character.undertale(frame)(function)- Formats the parameter for linking back to Undertale Wiki. Used only on Deltarune Wiki.
- Parameter:
frameScribunto frame object (table) - Returns: Formatted returning character parameter (string)
character.classification(frame)(function)- Formats the infobox field for Lightner/Darkner classification and categorizes the article. Only used on Deltarune Wiki.
- Parameter:
frameScribunto frame object (table) - Returns: List of all subject classifications (string)
--- 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, 'Check, ')
else
table.insert(str, 'Check ')
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 == 'Lightner' or trimmedCat == 'Darkner' then
table.insert(out, string.format('\n* [[%s]]', trimmedCat))
util.addCategory(out, trimmedCat .. 's')
end
end
return table.concat(out)
end
return character