Module:Dialogue

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Dialogue/doc. [edit]
Module:Dialogue's function invoke_main is invoked by Template:Dialogue.
Function list
L 3 — p.invoke_main
L 8 — p.main

local p = {}

function p.invoke_main(frame)
	local args = frame:getParent().args
	return p.main(args)
end

function p.main(args)
	local dtype = string.lower( args[1] or '' )
	local pagetitle = mw.title.getCurrentTitle()
	local pagename = pagetitle.text
	local basepagename = pagetitle.baseText
	local ns120 = pagetitle.namespace == 120  -- Transcript namespace
	local linkarg = args.link
	local link = '[[' .. ( linkarg or pagename ) .. ']]'
	local linkb = args.linkb
	local linkband = linkb and ( '[[' .. linkb .. ']] and ' ) or ''
	local title = args.title or pagename
	local displaynumber = dtype == 'museumdisplay' and string.gsub(pagename,'[^%d]', '') or ''
	
	local sentences = {
		['achievement'] = 'dialogue related to ' .. linkband .. 'the achievement ' .. link,
		['case'] = 'dialogue related to the court case ' .. link,
		['casedocument'] = 'the transcript of the ' .. link .. ' related to the case [[' .. (linkb or '') .. ']]',
		['dgjournal'] = 'the transcript of ' .. linkband .. link,
		['irl'] = 'a transcript related to ' .. linkband .. link,
		['item'] = 'the transcript of ' .. linkband .. link,
		['museumdisplay'] = 'the transcript of [[Varrock Museum displays#Display ' .. displaynumber .. '|Varrock Museum display No. ' .. displaynumber .. ']]',
		['mystery'] = 'dialogue related to the [[Archaeology]] [[mystery]] ' .. link,
		['questjournal'] = 'dialogue related to ' .. linkband .. '[[' .. (linkarg or basepagename) .. ']]',
		['research'] = 'the transcript of the [[Archaeology]] [[research]] named ' .. link,
		['scenery'] = 'dialogue related to ' .. linkband .. 'the scenery object ' .. link,
		['th'] = 'the transcript of the [[Treasure Hunter]] promotion ' .. link,
		['tutorial'] = 'dialogue related to ' .. linkband .. 'the tutorial ' .. link,
		['voyage'] = 'dialogue related to ' .. linkband .. 'the voyage ' .. link
	}
	local defaultText = 'dialogue related to ' .. linkband .. link
	local source = 'The content below is copied verbatim from \'\'RuneScape\'\' and thus copyrighted by [[Jagex]].'
	if dtype == 'irl' then
		source = 'The content below has been transcribed from a real-life act by [[Jagex]].'
	end
	
	local startTable = '{| class="messagebox standard-talk plainlinks" style="border-left:none; text-align:center;"\n|-\n| '
	local line = 'This page contains ' .. ( sentences[dtype] or defaultText ) .. '.'
	local endTable = '<br clear="all" /><div style="font-size:0.85em; line-height:1.4em;">' .. source .. '</div>\n|-\n|}'
	
	local header = startTable .. line .. endTable
	
	local cats = {
		['achievement'] = {'Achievement transcript'},
		['case'] = {'Court case transcript'},
		['casedocument'] = {'Court case transcript', 'Item transcript', 'Nonspoken Transcripts'},
		['dgjournal'] = {'Dungeoneering journal transcript', 'Item transcript', 'Nonspoken Transcripts'},
		['event'] = {'Event transcript'},
		['familiar'] = {'Familiar dialogue'},
		['irl'] = {'Real-life transcripts'},
		['item'] = {'Item transcript', 'Nonspoken Transcripts'},
		['miniquest'] = {'Miniquest transcript'},
		['museumdisplay'] = {'Scenery transcript', 'Varrock Museum display transcripts', 'Nonspoken Transcripts'},
		['music'] = {'Music transcript', 'Nonspoken Transcripts'},
		['mystery'] = {'Mystery transcript'},
		['npc'] = {'NPC dialogue'},
		['pet'] = {'Pet dialogue'},
		['quest'] = {'Quest transcript'},
		['questjournal'] = {'Quest journal transcript', 'Nonspoken Transcripts'},
		['relic'] = {'Archaeology transcript'},
		['research'] = {'Research transcript', 'Nonspoken Transcripts'},
		['saga'] = {'Fremennik Saga transcript'},
		['scenery'] = {'Scenery transcript'},
		['th'] = {'Treasure Hunter transcript'},
		['tutorial'] = {'Tutorial transcript'},
		['voyage'] = {'Voyage transcript'}
	}
	
	local setcat = ''
	local displayTitle = ''
	if ns120 then
		local cat = cats[dtype] or {'Miscellaneous transcript'}
		setcat = '[[Category:' .. table.concat(cat, ']][[Category:') .. ']]'
		
		local titleTypeIds = {
			['familiar'] = 1,
			['npc'] = 1,
			['pet'] = 1,
			['item'] = 2,
			['miniquest'] = 2,
			['misc'] = 2,
			['quest'] = 2,
			['saga'] = 2,
			['questjournal'] = 3
		}
		local titleTypes = {
			'Dialogue for ' .. title,
			'Transcript of ' .. title,
			'Transcript of ' .. basepagename .. ' journal entry'
		}
		local newTitle = titleTypes[ titleTypeIds[dtype] or 2 ]
		displayTitle = mw.getCurrentFrame():callParserFunction{ name = 'DISPLAYTITLE', args = { newTitle } }
		-- set Transcript authors SMW
		if string.match(args.author or '', '%S') then
			local authors = {}
			for auth in string.gmatch(args.author, "[^;]+") do
				if string.lower(auth) == 'player' then
					table.insert(authors, 'Player character')
				else
					table.insert(authors, auth)
				end
			end
			mw.smw.set( { ['Transcript authors'] = authors } )
		end
	end
	
	return header .. setcat .. displayTitle
end

return p