Module:Appear

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 = "" for i, v in ipairs(frame:getParent.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 = "" local first = arg:sub(1, 1) if tonumber(first) then seasoncode = first episodecode = arg:sub(1, 3) sidenotecode = arg:sub(4) elseif first == 'a' then seasoncode = arg:sub(4) episodecode = arg elseif first == 'i' then episodecode = 'intro' elseif first == 's' then seasoncode = 'short' episodecode = arg:sub(1, 7) sidenotecode = arg:sub(8) else local lowerIndex = arg:find( '%l' ) seasoncode = 'game' if lowerIndex then episodecode = arg:sub(1, lowerIndex - 1) sidenotecode = arg:sub(lowerIndex) else episodecode = arg end 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 ' (' .. t[sidenote] .. ')' else return '' end end

return p