Site News
Warning: This wiki contains spoilers. Read at your own risk!

Social media: If you would like, please join our Discord server, and/or follow us on X (Twitter) or Tumblr!

Module:ChapChars: Difference between revisions

From Fire Emblem Wiki, your source on Fire Emblem information. By fans, for fans.
(Adjusted rowbreak: defaults to 3, and can be set manualy)
m (Updated variable that accounts for Saga: in links; updated comments)
Line 19: Line 19:
end
end
local trs = game:sub(1, 3) == "trs" -- if the set game starts with "trs"
local saga = game:sub(1, 3) == "trs" or game:sub(1, 2) == "vs" -- if the set game starts with "trs" or "vs"
if num > 5 or trs then -- games 1–5 and Warriors are false; games 6–16 and TRS are true
if num > 5 or game:sub(1, 3) == "trs" then -- games that use small portraits; 1–5 and Warriors are false, 6–16 and TRS are true
size = "Small "
size = "Small "
end
end
Line 29: Line 29:
local hdr = "[[File:" .. size .. "portrait " -- Start of an image link
local hdr = "[[File:" .. size .. "portrait " -- Start of an image link
local link = " " .. game .. ".png|link=" -- Middle portion of an image link
local link = " " .. game .. ".png|link=" -- Middle portion of an image link
if trs then
if saga then
link = link .. "Saga:"
link = link .. "Saga:"
end
end
local ftr = "|x80px]]" -- End of link
local ftr = "|x80px]]" -- End of link
local output = hdr -- starts output with header value
local output = hdr -- starts output with header value
local i = 0
-- loops through the input and turns it into a list of images and one of links
-- loops through the input and turns it into a list of images and one of links
Line 43: Line 44:
links[tonumber(k:sub(7,-8))] = v
links[tonumber(k:sub(7,-8))] = v
elseif tostring(k):sub(1,6) == "return" then -- checks if first six characters are "return"
elseif tostring(k):sub(1,6) == "return" then -- checks if first six characters are "return"
images[tonumber(k:sub(7))] = mw.ustring.lower(v)
i = tonumber(k:sub(7))
if links[tonumber(k:sub(7))] == nil then
images[i] = mw.ustring.lower(v)
links[tonumber(k:sub(7))] = v
if links[i] == nil then -- checks if the corresponding link already exists
links[i] = v
end
end
end
end
Line 90: Line 92:
rowbreak = 2
rowbreak = 2
end
end
--[[rowbreak determines were new rows are made: breaks after the 4th unit
--[[rowbreak determines were new rows are made: breaks after the third unit,
for seven or eight units, after the 5th for nine or ten, and after every
except when there are four units where it breaks after the second.]]
6th for anything above ten; no breaks for fewer than six new units.]]
local output = ""
local output = ""

Revision as of 02:23, 2 February 2022

Contains three functions for use with {{ChapChars}}: newunits manages the new unit tables, and oldunits manages the required, available, and undeployable character sections; additionally, returning is a deprecated function that is no longer used.


local p = {}

function p.returning(frame)
	-- Naming the input
	local in_args = frame:getParent().args
	
	-- Determines whether or not to use "small"
	local size = ""; num = 0
	local game = tostring(in_args["game#"])
	if game:find("%c", -1) ~= nil then -- if game ends with a control character
		game = game:sub(1, -2)
	end
	
	if tonumber(game) ~= nil then -- if the game is set as a number
		num = tonumber(game)
	end
	if num > 0 or game == "wa" then -- if num was set, or game is set to "wa"
		game = "fe" .. game
	end
	
	local saga = game:sub(1, 3) == "trs" or game:sub(1, 2) == "vs" -- if the set game starts with "trs" or "vs"
	
	if num > 5 or game:sub(1, 3) == "trs" then -- games that use small portraits; 1–5 and Warriors are false, 6–16 and TRS are true
		size = "Small "
	end
	
	-- Begins construction of output
	local args = {}; images = {}; links = {}
	local hdr = "[[File:" .. size .. "portrait " -- Start of an image link
	local link = " " .. game .. ".png|link=" -- Middle portion of an image link
	if saga then
		link = link .. "Saga:"
	end
	local ftr = "|x80px]]" -- End of link
	local output = hdr -- starts output with header value
	local i = 0
	
	-- loops through the input and turns it into a list of images and one of links
	for k, v in pairs(in_args) do
		if v:find("%c", -1) ~= nil then -- if an input ends with a control character
			v = v:sub(1, -2) -- removes last character
		end
		if tostring(k):sub(-7) == "article" then -- checks if last seven characters are "article"
			links[tonumber(k:sub(7,-8))] = v
		elseif tostring(k):sub(1,6) == "return" then -- checks if first six characters are "return"
			i = tonumber(k:sub(7))
			images[i] = mw.ustring.lower(v)
			if links[i] == nil then -- checks if the corresponding link already exists
				links[i] = v
			end
		end
	end
	
	if images[1] == nil then -- true if images[1] is empty, which should only happen if return1 is not set
		return "None" -- ends the program
	end
	
	-- Turns the previous two lists into one list of partial links
	for k in pairs(images) do
		args[k] = images[k] .. link .. links[k] -- creates the middle portion of the link
	end
	
	-- takes list created above and turns it into useable wikitext
	output = output .. table.concat(args, ftr .. hdr)
	
	-- returns completed image set
	return output .. ftr
end

function p.newunits(frame)
	-- Naming input to be more convinient
	local in_args = frame:getParent().args
	
	local units = {} -- variabe that will contain every "newunit#" field
	
	-- Checks input for newunit fields
	for k, v in pairs(in_args) do
		if tostring(k):find("newunit%d+") ~= nil then
			units[tonumber(k:sub(8))] = v
		end
	end
	
	if #units == 0 then -- if there are no new units
		return "|\nNone"
	end
	
	local rowbreak = 3
	
	if in_args[rowbreak] ~= nil then -- if rowbreak is set in the page
		rowbreak = in_args[rowbreak]
	elseif #units == 4 then -- if there are four new units
		rowbreak = 2
	end
	--[[rowbreak determines were new rows are made: breaks after the third unit,
		except when there are four units where it breaks after the second.]]
	
	local output = ""
	
	for k, v in ipairs(units) do -- assembles output
		output = output .. "|\n" .. v .. "\n"
		if k % rowbreak == 0 then -- adds new rows
			output = output .. "|-\n"
		end
	end
	
	return output
end

return p