Module:CommendationTable

From Sea of Thieves Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:CommendationTable/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 commendations with the emblem name requirements and rewards." )
					:tag( "tr" )
						:tag( "th" )
						:attr( "colspan", "4" )
						:wikitext( "[[Commendations]]" )
							:tag( "tr" )
							:tag( "th" )
							:wikitext("Image")
							:tag("th")
							:wikitext("Commendation")
							:tag("th")
							:wikitext("Requirements")
							:attr("style", "min-width:160px;")
							:tag("th")
							:wikitext("Rewards")
						:done()
					:done()
		for _, v in pairs(args) do
			local b = mw.text.trim(v)
			
			-- Header
			local a = mw.ext.cargo.query( "Commendations", "comm_name,store_name,comm_text,reward,reward1,reward2,reward3,reward4,reward5,reward6,reward7,reward8,reward9,reward10,d,d_timelimited,title,grade1,grade2,grade3,grade4,grade5,grade6,grade7,grade8,grade9,grade10,image,timelimited,highseas_only,removed,discontinued", { where = 'store_name="' .. b .. '"', ["no html"] = true } )
			
			a = a[1] or { }
			
			local dubprice = frame:expandTemplate{ title="d", args= { a.d } }
			local dubpricetimelimited = frame:expandTemplate{ title="tag_timelimited", args= { other = "+" .. dubprice } }
			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= { } }
			
			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.image or "empty") .. "|74px]]" )
						:done()
					:done() -- End Image
					
				-- Commendation name
					:tag( "th" )
					:attr( "id", a.store_name )
						if mw.title.getCurrentTitle().text == 'Commendations' then
							html = html
							:wikitext( a.comm_name )
							:done()
						else
							html = html
							:wikitext( "[[Commendations#" .. a.store_name .. "|" .. a.comm_name .. "]]" )
							:done() 
						end -- End Commendation name
					
				-- Requirements
					html = html
					:tag( "td" )
					:wikitext( a.comm_text )
					
						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.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
						if a.grade1 ~= NIL then
							html = html
							:tag( "div" )
							:attr( "class", "mw-collapsible mw-collapsed" )
							:attr( "data-expandtext", " View Grades " )
							:attr( "data-collapsetext", " Hide Grades " )
							:wikitext( " " )
							:tag( "div" )
							:attr( "class", "mw-collapsible-content" )
								:tag("ul")
									:tag("li")
									:wikitext( "'''Grade I:''' " .. ( a.grade1 or "data required" ) ) 
								if a.grade2 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade II:''' " .. a.grade2 )
								end
								if a.grade3 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade III:''' " .. a.grade3 )
								end
								if a.grade4 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade IV:''' " .. a.grade4 )
								end
								if a.grade5 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade V:''' " .. a.grade5 )
								end
								if a.grade6 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade VI:''' " .. a.grade6 )
								end
								if a.grade7 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade VII:''' " .. a.grade7 )
								end
								if a.grade8 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade IIX:''' " .. a.grade8 )
								end
								if a.grade9 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade IX:''' " .. a.grade9 )
								end
								if a.grade10 ~= NIL then
									html = html
									:tag ("li")
									:wikitext("'''Grade X:''' " .. a.grade10 )
								end

						else
							html = html:done()
						end -- Ends Requirements
						
				--Rewards
				html = html
					:tag( "td" )
					
						if type(tonumber(a.d_timelimited)) == "number" then
							html = html
							:wikitext( dubpricetimelimited )
							:tag( "br" )
							:done()
						elseif a.d ~= NIL then
							html = html
							:wikitext( "+" .. dubprice )
							:tag( "br" )
							:done()
						end 
						
						
						if a.title == "yes" then
							html = html
							:wikitext( "[[File:Title icon.png|24px|class=invert75]] Rewards the [[Titles#" .. a.comm_name .. "|" .. a.comm_name .. "]] Title." )
							:tag( "br" )
							:done()
						elseif a.title ~= NIL then 
							html = html
							:wikitext( "[[File:Title icon.png|24px|class=invert75]] Rewards the [[Titles#" .. a.title .. "|" .. a.title .. "]] Title." )
							:tag( "br" )
							:done()
						end
						if a.reward ~= NIL then
							html = html
							:wikitext( "[[File:Lock icon.png|24px|class=invert75]] " .. a.reward )
							:done()
						end
						if a.reward1 ~= NIL then
							html = html
							:wikitext( "[[File:Lock icon.png|24px|class=invert75]] " .. a.reward1 .. " at Grade I" )
						end
						if a.reward2 ~= NIL and a.reward1 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward2 .. " at Grade II" )
						end
						if a.reward2 ~= NIL and a.reward1 == NIL then
							html = html
							:wikitext(  "[[File:Lock icon.png|24px|class=invert75]] " .. a.reward2 .. " at Grade II" )
						end
						if a.reward3 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward3 .. " at Grade III" )
						end
						if a.reward4 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward4 .. " at Grade IV" )
						end		
						if a.reward5 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward5 .. " at Grade V" )
						end
						if a.reward6 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward6 .. " at Grade VI" )
						end
						if a.reward7 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward7 .. " at Grade VII" )
						end
						if a.reward8 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward8 .. " at Grade IIX" )
						end
						if a.reward9 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward9 .. " at Grade IX" )
						end
						if a.reward10 ~= NIL then
							html = html
							:wikitext( ", " .. a.reward10 .. " at Grade X" )
						end
						if a.reward1 ~= NIL then
							html = html
							:wikitext( "." )
						end
						if a.d == NIL and a.title == NIL and a.reward == NIL and a.reward1 == NIL and a.reward2 == NIL and a.reward3 == NIL and a.reward4 == NIL and a.reward5 == NIL and a.reward6 == NIL and a.reward7 == NIL and a.reward8 == NIL and a.reward9 == NIL and a.reward10 == NIL then
							html = html
							:wikitext( notavail )
							:done()
						end
						-- End Rewards
					
			end
		end
		html = html:allDone()
		return tostring(html)
	end, 
	}