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 Twitter (X) or Tumblr!

Module:ChapChars: Difference between revisions

From Fire Emblem Wiki, your source on Fire Emblem information. By fans, for fans.
mNo edit summary
m (I think this is more efficient)
Line 37: Line 37:
local i = 0
local i = 0
for k, v in pairs(in_args) do
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 type(k) == "string" then -- checks for link corrections
if type(k) == "string" then -- checks for link corrections
links[tonumber(k:sub(2)) + 1] = v
links[tonumber(k:sub(2)) + 1] = v
elseif type(k) == "number" then -- anything that isn't a link should be a portrait
elseif type(k) == "number" then -- anything that isn't a link should be a portrait
images[k] = mw.ustring.lower(v)
images[k] = mw.ustring.lower(v)
links[k] = mw.ustring.lower(v)
end
end
end
end
Line 46: Line 50:
-- Turns the previous two lists into one list of partial links
-- Turns the previous two lists into one list of partial links
for k in pairs(images) do
for k in pairs(images) do
if images[k]:find("%c", -1) ~= nil then -- if the image ends with a control character
images[k] = images[k]:sub(1, -2) -- removes last character
end
if type(links[k]) == "nil" then -- if the link corresponding to the image is empty
links[k] = images[k]
end
args[k] = images[k] .. link .. links[k] -- creates the middle portion of the link
args[k] = images[k] .. link .. links[k] -- creates the middle portion of the link
end
end

Revision as of 20:28, 12 February 2021

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 = ""
	local game = in_args[1]
	if game:find("%c", -1) ~= nil then -- if game ends with a control character
		game = game:sub(1, -2)
	end
	local trs = game:sub(1, 3) == "trs"
	local num = game:sub(-2) -- sets "num" to third and later characters in first input
	
	if tonumber(num) ~= nil then -- if the third and later characters are numbers (e.g. "fe01" is true, "fewa" is false)
		num = tonumber(num)
	else
		num = 0
	end
	
	if num > 5 or trs then -- games 1–5 and Warriors are false; games 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 trs then
		link = link .. "TearRingSaga:"
	end
	local ftr = "|x80px]]" -- End of link
	local output = hdr -- starts output with header value
	
	-- loops through the input and turns it into a list of images and one of links
	local i = 0
	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 type(k) == "string" then -- checks for link corrections
			links[tonumber(k:sub(2)) + 1] = v
		elseif type(k) == "number" then -- anything that isn't a link should be a portrait
			images[k] = mw.ustring.lower(v)
			links[k] = mw.ustring.lower(v)
		end
	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
	
	table.remove(args, 1) -- The first bit of args[] is a link for the platform, this removes that
	
	-- 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

return p