Module:TitleTable

From Sea of Thieves Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:TitleTable/doc

return {
	main = function( frame )
		local notavail = frame:expandTemplate{ title = "na" }
		local args = frame
		if frame == mw.getCurrentFrame() then
			args = frame:getParent().args
		end
		local html = mw.html.create( "table" )
				:attr( "class", "wikitable list" )
				:attr( "summary", "List of related titles with the emblem name requirements and rewards." )
					:tag( "tr" )
						:tag( "th" )
						:attr( "colspan", "3" )
						:wikitext( "[[Titles]]" )
							:tag( "tr" )
							:tag( "th" )
							:wikitext("Image")
							:tag("th")
							:wikitext("Title")
							:tag("th")
							:wikitext("Description & Requirements")
							:attr("style", "min-width:160px;")
						:done()
					:done()
		for _, v in pairs(args) do
			local b = mw.text.trim(v)
			
			-- Header
		local a = mw.ext.cargo.query( "Titles", "title_name,title_text,store_name,title_image,description,company,company_full,rank,reward,timelimited,highseas_only,ps_only,removed,discontinued", { where = 'store_name="' .. b .. '"', ["no html"] = true } )
			
			a = a[1] or { }

			local doRepnum = frame:expandTemplate{ title = "List repnum/split", args = { company = a.company, level = a.rank } }
			local tagtimelimited = frame:expandTemplate{ title="tag_timelimited", args= { } }
			local tagremoved = frame:expandTemplate{ title="tag_removed", args= { } }
			local tagdiscon = frame:expandTemplate{ title="tag_removed", args= { text = "Discontinued" } }
			local taghighseas = frame:expandTemplate{ title="tag_highseas", args= { text = "Earned in High Seas only" } }
			local tagplaystation = frame:expandTemplate{ title="tag_playstation", args= { } }
			
			if a.store_name then
				-- Image
				html = html
				:tag( "tr" )
					:tag( "th" )
					:attr( "class", "thumb" )
						:tag("div")
						:attr( "class", "thumb-frame pseudo-before" )
						:wikitext( "[[File:" .. (a.title_image or "empty") .. "|74px]]" )
						:done()
					:done() 
				-- End Image
					
				-- Title name
					:tag( "th" )
					:attr( "id", a.store_name )
						if mw.title.getCurrentTitle().text == 'Titles' then
							html = html
							:wikitext( a.title_name )
							:done()
						else
							html = html
							:wikitext( "[[Titles#" .. a.store_name .. "|" .. a.title_name .. "]]" )
							:done() 
						end
				-- End Title name
					
				-- Requirements
					html = html
					:tag( "td" )
					if a.description ~= NIL then
						html = html
						:wikitext( '"' .. a.description ..'"' )
					end
					if a.title_text ~= NIL then
						if a.description ~= NIL then
							html = html
							:tag( "br" ):done()
						end
						html = html
						:wikitext( a.title_text )
					end
					if a.rank ~= NIL then
						html = html
						:tag( "br" ):done()
						:wikitext( doRepnum )
						end
					if a.reward ~= NIL then
						html = html
						:tag( "br" ):done()
						:wikitext( "[[File:Lock icon.png|24px|class=invert75]] " .. a.reward )
					end
						if type(tonumber(a.timelimited)) == "number" then
							html = html
							:tag( "br" ):done()
							:wikitext( tagtimelimited )
						end
						if type(tonumber(a.highseas_only)) == "number" then
							html = html
							:tag( "br" ):done()
							:wikitext( taghighseas )
						end
						if type(tonumber(a.ps_only)) == "number" then
							html = html
							:tag( "br" ):done()
							:wikitext( tagplaystation )
						end
						if type(tonumber(a.removed)) == "number" then
							html = html
							:tag( "br" ):done()
							:wikitext( tagremoved )
						end
						if type(tonumber(a.discontinued)) == "number" then
							html = html
							:tag( "br" ):done()
							:wikitext( tagdiscon )
						end
				-- Ends Requirements
				
			end
		end
		html = html:allDone()
		return tostring(html)
	end, 
	}