Module:Appearances

local p = {} local getArgs = require('Dev:Arguments').getArgs local h = require("Module:HF")

-- **************************************************************************************************************** -- *** LOCAL FUNCTIONS *** -- ****************************************************************************************************************

local function outdated_field(args) local value = args[1] local output = '' if ( not h.isempty(value) and not h.is_link(value) ) or not h.isempty(args[2]) or not h.isempty(args[3]) then output = h.Category('Outdated Fields/Tags') end return output end

local function build(arg, arg2, category) local link = "" local text = "" local output = ''

if not h.isempty(arg) then if not h.isempty(arg2) then link = arg text = arg2 else link = string.match(arg, "([^%[%|%]]+)") text = string.match(arg, "%|([^%]%|]+)") end

if string.find(link, "w:c:") == nil and string.find(link, "Glossary:") == nil and string.find(link, "#") == nil then if not h.isempty(link) then output = h.Link(link, text)..h.Category(link..category) else output = arg end else output = arg end end return output end

local function build2(arg, category) local link = "" local text = "" local output = ''

if not h.isempty(arg) then link = string.match(arg, "([^%[%|%]]+)") text = string.match(arg, "%|([^%]%|]+)")

if string.find(link, "w:c:") == nil and string.find(link, "Glossary:") == nil and string.find(link, "#") == nil then if not h.isempty(link) then output = h.Link(link, text)..h.Category(link..category) else output = arg end else output = arg end end return output end

local function suffixTag(value) local output = '' if not h.isempty(value) then output = ' '..tostring( mw.html.create('span'):addClass('green_text'):wikitext('('..value..')'):done ) end return output end

-- **************************************************************************************************************** -- *** APPEARANCES *** -- ****************************************************************************************************************

function p.appearances(frame) local args = getArgs(frame) return build(args[1], args[2], '/Appearances')..suffixTag(args[3]) end

-- used in "Template:Apn" function p.apn(frame) local standard = require("Module:StandardizedName") local function get_link(value, pagename, is_next) local info = {} local issue_number local output = ''

if not h.isempty(value) then if value ~= '-' then output = value end elseif string.find(pagename, ' Vol ') ~= nil or string.find(pagename, ' Season ') ~= nil then if string.find(pagename, ' Vol ') ~= nil then info = standard.lua_get_title_volume_issue(pagename, 'Vol') else info = standard.lua_get_title_volume_issue(pagename, 'Season') end issue_number = tonumber(info.issue) if issue_number ~= nil then if is_next then output = info.noissue..' '..(issue_number + 1) elseif issue_number > 1 then output = info.noissue..' '..(issue_number - 1) end end end if output ~= '' then if is_next then output = ' '..h.Link(output, '&#129170;') else output = h.Link(output, '&#129168;')..' ' end end return output end local pagename = mw.title.getCurrentTitle.text local args = getArgs(frame) local output = build2(args[1], '/Appearances')

return get_link(args[2], pagename, false)..output..get_link(args[3], pagename, true) end

-- used in "Template:1st" function p.first_appearance(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First appearance')..outdated_field(args) end

-- used in "Template:1stas" function p.first_as(frame) local args = getArgs(frame) local arg1 = args[1] local arg2 = args[2] local output = '' if not h.isempty(arg1) then if not h.isempty(arg2) then output = build2(arg1, '/Appearances')..suffixTag('First appearance as '..arg2) elseif h.is_link(arg1) then output = build2(arg1, '/Appearances')..suffixTag('First appearance as '..arg1) else output = suffixTag('First appearance as '..arg1) end end return output end

-- used in "Template:1stChron" function p.first_chronologically(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First appearance chronologically')..outdated_field(args) end

-- used in "Template:1stFull" function p.first_full(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First full appearance')..outdated_field(args) end

-- used in "Template:1stHist" function p.first_historically(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First appearance historically')..outdated_field(args) end

-- used in "Template:1st Real Name" function p.first_real_name(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Name first revealed')..outdated_field(args) end

-- used in "Template:1st Unnamed" function p.first_unnamed(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First appearance; unnamed')..outdated_field(args) end

-- used in "Template:ApDeath" function p.apparent_death(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Apparent death')..outdated_field(args) end

-- used in "Template:Cameo" function p.cameo(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Cameo')..outdated_field(args) end

-- used in "Template:ChronoFB" function p.chronological_flashback(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag( h.Link('#Chronology Notes', 'Appears in flashback') )..outdated_field(args) end

-- used in "Template:Chronology" function p.chronology(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag( h.Link('#Chronology Notes', 'See chronology') )..outdated_field(args) end

-- used in "Template:Death" function p.death(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Death')..outdated_field(args) end

-- used in "Template:Deceased" function p.deceased(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Deceased')..outdated_field(args) end

-- used in "Template:Defunct" function p.defunct(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Defunct')..outdated_field(args) end

-- used in "Template:Destroyed" function p.destroyed(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Destroyed')..outdated_field(args) end

-- used in "Template:Destruction" function p.destruction(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Destruction')..outdated_field(args) end

-- used in "Template:Disbands" function p.disbands(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Disbands')..outdated_field(args) end

-- used in "Template:Final" function p.final(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Final appearance')..outdated_field(args) end

-- used in "Template:Final Dies" function p.final_dies(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Final appearance; dies')..outdated_field(args) end

-- used in "Template:Flashback" function p.flashback(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Main story and flashback')..outdated_field(args) end

-- used in "Template:Flashback and Flashforward" function p.flashback_flashforward(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Main story, flashback and flashforward')..outdated_field(args) end

-- used in "Template:Flashforward" function p.flashforward(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Main story and flashforward')..outdated_field(args) end

-- used in "Template:FlashOnly" function p.flashback_only(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Only in flashback')..outdated_field(args) end

-- used in "Template:FlashforwardOnly" function p.flashforward_only(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Only in flashforward')..outdated_field(args) end

-- used in "Template:Ghost" function p.ghost_soul_spirit(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Ghost, soul or spirit')..outdated_field(args) end

-- used in "Template:Hologram" function p.hologram(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('As hologram')..outdated_field(args) end

-- used in "Template:Joins" function p.joins(frame) local args = getArgs(frame) local arg2 = args[2]

if not h.isempty(arg2) then return build2(args[1], '/Appearances')..suffixTag('Joins '..arg2) else return build2(args[1], '/Appearances')..suffixTag('Joins group') end end

-- used in "Template:Last" function p.last(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Last appearance')..outdated_field(args) end

-- used in "Template:Leaves" function p.leaves(frame) local args = getArgs(frame) local arg2 = args[2]

if not h.isempty(arg2) then return build2(args[1], '/Appearances')..suffixTag('Leaves '..arg2) else return build2(args[1], '/Appearances')..suffixTag('Leaves group') end end

-- used in "Template:Only" function p.only(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First and only known appearance')..outdated_field(args) end

-- used in "Template:Only Destruction" function p.only_destruction(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First and only known appearance; destruction')..outdated_field(args) end

-- used in "Template:Only Dies" function p.only_dies(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('First and only known appearance; dies')..outdated_field(args) end

-- used in "Template:OnScreen" function p.on_screen(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Appears on screen')..outdated_field(args) end

-- used in "Template:Origin" function p.origin(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Origin revealed')..outdated_field(args) end

-- used in "Template:PossessedBy" function p.possessed_by(frame) local args = getArgs(frame) local value1 = args[1] local value2 = args[2] local output_categories = {} if not h.isempty(value1) then if h.is_link(value1) then table.insert(output_categories, h.break_link(value1)..'/Appearances') end else value1 = '' end if not h.isempty(value2) then if h.is_link(value2) then table.insert(output_categories, h.break_link(value2)..'/Appearances') end value2 = suffixTag('Possessed by '..value2) else value2 = '' end

return value1..value2..h.add_categories(output_categories) end

-- used in "Template:Possesses" function p.possesses(frame) local args = getArgs(frame) local value1 = args[1] local value2 = args[2] local output_categories = {} if not h.isempty(value1) then if h.is_link(value1) then table.insert(output_categories, h.break_link(value1)..'/Appearances') end else value1 = '' end if not h.isempty(value2) then if h.is_link(value2) then table.insert(output_categories, h.break_link(value2)..'/Appearances') end value2 = suffixTag('Possesses '..value2) else value2 = '' end

return value1..value2..h.add_categories(output_categories) end

-- used in "Template:Recap" function p.recap(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Main story and recap')..outdated_field(args) end

-- used in "Template:Rejoins" function p.rejoins(frame) local args = getArgs(frame) local arg2 = args[2]

if not h.isempty(arg2) then return build2(args[1], '/Appearances')..suffixTag('Rejoins '..arg2) else return build2(args[1], '/Appearances')..suffixTag('Rejoins group') end end

-- used in "Template:Repaired" function p.repaired(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Repaired')..outdated_field(args) end

-- used in "Template:Resurrection" function p.resurrection(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Resurrection')..outdated_field(args) end

-- used in "Template:Revealed Alive" function p.revealed_alive(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Revealed to be alive') end

-- used in "Template:Shadow" function p.shadow(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Shadow only')..outdated_field(args) end

-- used in "Template:Topical Reference" function p.topical_reference(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag( h.Link('Glossary:Topical Reference', 'Topical Reference') )..outdated_field(args) end

-- used in "Template:Unnamed" function p.unnamed(frame) local args = getArgs(frame) return build2(args[1], '/Appearances')..suffixTag('Unnamed')..outdated_field(args) end

-- ****************************************************************************************************************

function p.minor(frame) local args = getArgs(frame) return build(args[1], args[2], '/Minor Appearances')..suffixTag(args[3]) end

-- used in "Template:BTS" function p.behind_the_scenes(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Behind the scenes')..outdated_field(args) end

-- used in "Template:Carving" function p.carving(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Carving')..outdated_field(args) end

-- used in "Template:Corpse" function p.corpse(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Corpse, skeleton or other remains')..outdated_field(args) end

-- used in "Template:Drawing" function p.drawing(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Drawing')..outdated_field(args) end

-- used in "Template:Dream" function p.dream(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Dream')..outdated_field(args) end

-- used in "Template:Illusion" function p.illusion_or_hologram(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Illusion or holographic simulation')..outdated_field(args) end

-- used in "Template:Imagination" function p.imagination(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Imagination') end

-- used in "Template:OnScreenOnly" function p.on_screen_only(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Only on screen as a static image or video record')..outdated_field(args) end

-- used in "Template:Photo" function p.photo(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Photo')..outdated_field(args) end

-- used in "Template:Poster" function p.poster(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Poster')..outdated_field(args) end

-- used in "Template:RecapOnly" function p.recap_only(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Only in recap')..outdated_field(args) end

-- used in "Template:Wreckage" function p.wreckage(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Wreckage, ruins, debris, fragments')..outdated_field(args) end

-- used in "Template:Statue" function p.statue(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Statue')..outdated_field(args) end

-- used in "Template:Toy" function p.toy(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Toy')..outdated_field(args) end

-- used in "Template:Vision" function p.vision(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Vision')..outdated_field(args) end

-- used in "Template:Voice" function p.voice(frame) local args = getArgs(frame) return build2(args[1], '/Minor Appearances')..suffixTag('Voice')..outdated_field(args) end

-- ****************************************************************************************************************

-- used in "Template:Mentioned" function p.mentioned(frame) local args = getArgs(frame) return build2(args[1], '/Mentions')..suffixTag('Mentioned')..outdated_field(args) end

-- used in "Template:Map" function p.map(frame) local args = getArgs(frame) return build2(args[1], '/Mentions')..suffixTag('Map')..outdated_field(args) end

-- used in "Template:Named" function p.named(frame) local args = getArgs(frame) return build2(args[1], '/Mentions')..suffixTag('Name only')..outdated_field(args) end

-- used in "Template:Referenced" function p.referenced(frame) local args = getArgs(frame) return build2(args[1], '/Mentions')..suffixTag('Referenced')..outdated_field(args) end

-- used in "Template:Tombstone" function p.tombstone(frame) local args = getArgs(frame) return build2(args[1], '/Mentions')..suffixTag('Tombstone') end

-- ****************************************************************************************************************

-- used in "Template:Invoked" function p.invoked(frame) local args = getArgs(frame) return build2(args[1], '/Invocations')..suffixTag('Invoked')..outdated_field(args) end

-- ****************************************************************************************************************

-- used in "Template:Impersonates" function p.impersonates(frame) local args = getArgs(frame) return suffixTag('Impersonates '..args[1]) end

-- used in "Template:Killed" function p.killed(frame) local args = getArgs(frame) local output = 'Killed' if not h.isempty(args[1]) then output = 'Killed by '..args[1] end return suffixTag(output) end

-- used in "Template:RevealedAs" function p.revealed_as(frame) local args = getArgs(frame) return suffixTag('Revealed as '..args[1]) end

return p