Documentation for this module may be created at Module:Appear/doc
local p = {}
-- Create a table t to hold the data from Module:Appear/data
local t = mw.loadData('Module:Appear/data')
-- Create a table to see which seasons have been written and which haven't
local seasons = {}
local writeAll, writeSeason, writeEpisode, writeSidenote
-- Sends the arguments given to the template to the write function
-- and returns everything put together into a string
function p.main(frame)
local text = ""
local args = frame:getParent().args
for i, v in ipairs(args) do
if v ~= '' then
if i ~= 1 then
text = text .. '\n'
end
text = text .. writeAll(v)
end
end
return text
end
-- Splits the argument into pieces and sends the right pieces to
-- writeSeason, writeEpisode, and writeSidenote
-- They are then put together and returned
writeAll = function (arg)
local seasoncode = ""
local episodecode = ""
local sidenotecode = ""
-- "gtest" is for first 2 characters of arg to see if input is a game, intro, or all.
local gtest = arg:sub(1, 2)
-- Tested in this order: game, all, intro, single episodes
if gtest == 'DP' or gtest == 'NU' or gtest == 'NB' or gtest == 'NI' then
local lowerIndex = arg:find( '%l' )
seasoncode = 'game'
if lowerIndex then
episodecode = arg:sub(1, lowerIndex - 1)
sidenotecode = arg:sub(lowerIndex)
else
episodecode = arg
end
elseif gtest == 'al' then
seasoncode = arg:sub(4)
episodecode = arg
elseif gtest == 'in' then
episodecode = 'intro'
else
--Episodecode and Sidenotecode
--testing to see if lowercase is actually a sidenotecode since
--lowercase 'a,' 'i,' 'o,' 't' exist in episode abbreviations
local cftest = arg:find('f', -3) -- to test for sidenotecodes 'f' and 'fnl'
local cnltest = arg:find('nl', -3) -- to test for sidenotecode 'nl'
local cutest = arg:find('u', -3) -- to test for sidenotecode 'u'
local cmtest = arg:find('m', -3) -- to test for sidenotecode 'm'
local cptest = arg:find('p', -3) -- to test for sidenotecode 'p'
local cltest = arg:find('l', -3) -- to test for sidenotecode 'l'
--line below checks if sidenotecode was found
if cftest or cnltest or cutest or cmtest or cptest or cltest then
--testing for which sidenotecode
--WARNING: do NOT change order!
if cftest then
episodecode = arg:sub(1, cftest - 1)
sidenotecode = arg:sub(cftest)
elseif cnltest then
episodecode = arg:sub(1, cnltest - 1)
sidenotecode = arg:sub(cnltest)
elseif cutest then
episodecode = arg:sub(1, cutest - 1)
sidenotecode = arg:sub(cutest)
elseif cmtest then
episodecode = arg:sub(1, cmtest - 1)
sidenotecode = arg:sub(cmtest)
elseif cptest then
episodecode = arg:sub(1, cptest - 1)
sidenotecode = arg:sub(cptest)
elseif cltest then
episodecode = arg:sub(1, cltest - 1)
sidenotecode = arg:sub(cltest)
end
else
episodecode = arg --if there is no sidenotecode
end
--Seasoncode
local epseason = t[episodecode]
local snumber = epseason:sub(1, 1) --writing as extra step to show process
seasoncode = snumber
end
local season = writeSeason(seasoncode)
local episode = writeEpisode(episodecode)
local sidenote = writeSidenote(sidenotecode)
return season .. episode .. sidenote
end
writeSeason = function (season)
if not seasons[season] and t[season] then
seasons[season] = true
return '===' .. t[season] .. '===\n'
else
return ''
end
end
writeEpisode = function (episode)
return '*' .. t[episode]
end
writeSidenote = function (sidenote)
if t[sidenote] then
return ' <sup>(' .. t[sidenote] .. ')</sup>'
else
return ''
end
end
return p