Squad Wiki
Advertisement

Documentation for this module may be created at Module:Cargo Display Functions/doc

local p = {}
local cargo = mw.ext.cargo

function p.getLayers( frame )
	local different = {
		Kamdesh = "Kamdesh Highlands",
		Kohat = "Kohat Toi",
		Sumari = "Sumari Bala",
	}
	
	
	-- Map Cargo Query Setup + Query
	local tables = 'map_vehicle_assets'
	local fields = "mappage, gamemode, layerversion"
	
	local args = {
		where = 'map_vehicle_assets.vehicle="'..frame.args[1]..'"',
		orderBy = "map_vehicle_assets.mappage",
		limit = 300
	}
	
	local results = cargo.query(tables, fields, args)
	if(results[1] == nil) then return "N/A" end
	local text = "[["..results[1].mappage.."]], "
	local currentmap = results[1].mappage
	for i = 1, #results do 
		if(different[results[i].mappage] ~= undefined) then results[i].mappage = different[results[i].mappage] end
		if(currentmap ~= results[i].mappage) then 
			text = text.."[["..results[i].mappage.."]], "
			currentmap = results[i].mappage
			end
		end
	return string.sub(text, 1, string.len(text) - 2)
end

function p.getTheaters(frame)
	local different = {
		Kamdesh_Highlands = "Kamdesh",
		Kohat_Toi = "Kohat",
		Sumari_Bala = "Sumari",
		Manic__5 = "Manic",
		Tallil_Outskirts = "Tallil"
	}
	
	local tables = "maps"
	local fields = "mapname, theater"
	
	local args = {
		where = 'maps.theater <> ""',
		orderBy = "maps.theater",
		limit = 300
	}
	
	local results = cargo.query(tables, fields, args)
	if(results[1] == nil) then return "N/A" end
	mw.logObject(results)
	local maps = {}
	local text = ''
	
	local tables2 = "map_layers"
	local fields2 = "mappage"
	
	local args2 = {
		where = 'map_layers.team1faction = "'..frame.args[1]..'" OR map_layers.team2faction = "'..frame.args[1]..'"',
		orderBy = "map_layers.mappage",
		limit = 300
	}
	local results2 = cargo.query(tables2, fields2, args2)
	
	-- Sort Maps
	local currentTheater = results[1].theater
	maps[currentTheater] = {}
	for i = 1, #results do
		
		if(currentTheater ~= results[i].theater or i == #results) then
			if(i == #results) then table.insert(maps[currentTheater], results[i].mapname) end
			table.sort(maps[currentTheater])
			local theaterFound = false
			local temptext = ""
			for j = 1, #maps[currentTheater] do
				local found = false
				for k = 1, #results2 do
					local currentmap = ""
					if(different[string.gsub(maps[currentTheater][j]," ", "_")] ~= nil) 
					then currentmap = different[string.gsub(maps[currentTheater][j]," ", "_")] 
					else if(different[string.gsub(maps[currentTheater][j],"-", "__")] ~= nil) 
						then currentmap = different[string.gsub(maps[currentTheater][j],"-", "__")]  
						else currentmap = maps[currentTheater][j]
							end
						end
					if string.find(maps[currentTheater][j], "&#39;") then maps[currentTheater][j] = string.gsub(maps[currentTheater][j], "&#39;", "'")end
					mw.logObject(results2[k].mappage)
					mw.logObject(maps[currentTheater][j])
					mw.log(currentmap)
					mw.logObject(different[string.gsub(maps[currentTheater][j]," ", "_")])
					if(results2[k].mappage == currentmap) then 
						found = true 
						theaterFound = true
						end
				end
				mw.log("END")
				if(found) then temptext = temptext.."[["..maps[currentTheater][j].."]], " end
			end
			if(theaterFound) then 
				text = text.." "..currentTheater.. ": <br/>"..temptext
				text = string.sub(text, 1, string.len(text) - 2).." <br/>"
				end
			currentTheater = results[i].theater
			maps[currentTheater] = {}
		end
		table.insert(maps[currentTheater], results[i].mapname)
	end
	return text
end

return p
Advertisement