Module:Cargo Map Page Generator

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

function p.generate( frame ) -- Faction Flags local flags = { US_Army = "USArmy Flag.PNG", British_Army = "GB flag.jpg", Irregular_Militia = "IM Flag.PNG", Insurgents = "Insurgents Flag.PNG", Russian_Ground_Forces = "RGF Flag.PNG", Canadian_Army = "Flag of Canada.png", Middle_Eastern_Alliance = "MEA_Flag.png", BLUFOR_or_REDFOR_or_INDEPENDENT = "BLUEFOR_-_REDFOR_-_INDEPENDENT_flag.png", BLUFOR_or_INDEPENDENT_or_REDFOR = "BLUEFOR_-_REDFOR_-_INDEPENDENT_flag.png", REDFOR_or_INDEPENDENT_or_BLUFOR = "BLUEFOR_-_REDFOR_-_INDEPENDENT_flag.png", REDFOR_or_BLUFOR_or_INDEPENDENT = "BLUEFOR_-_REDFOR_-_INDEPENDENT_flag.png", INDPENDENT_or_REDFOR_or_BLURFOR = "BLUEFOR_-_REDFOR_-_INDEPENDENT_flag.png", INDPENDENT_or_BLUFOR_or_REDFOR = "BLUEFOR_-_REDFOR_-_INDEPENDENT_flag.png", REDFOR_or_INDEPENDENT = "REDFOR_-_INDEPENDENT_flag.png", INDEPENDENT_or_REDFOR = "REDFOR_-_INDEPENDENT_flag.png", BLUFOR_or_INDEPENDENT = "BlUFOR - INDEPENDENT flag.png", INDEPENDNET_or_BLUFOR = "BlUFOR - INDEPENDENT flag.png", BLUFOR_or_REDFOR = "BlUFOR - REDFOR flag.png", REDFOR_or_REDFOR = "BlUFOR - REDFOR flag.png", REDFOR = "REDFOR flag.png", BLUFOR = "BLUEFOR flag.png", INDEPENDENT = "INDEPENDENT flag.png" }	-- Map Cargo Query Setup + Query local tables = 'map_layers' local fields = 'gamemode,layerversion,team1faction,team1tickets,team2faction,team2tickets,capturepoints' local args = { where = 'map_layers.mappage="'..frame.args[1]..'"', orderBy = 'map_layers.gamemode, map_layers.layerversion', }	local results = cargo.query( tables, fields, args ) frame:expandTemplate{ title = "Map Layers Version"} local finished = "" -- Veh Cargo Query Setup local tablesveh = "map_vehicle_assets" local fieldsveh = "teamfaction,vehicle,vehicledisplayname,count,delay,icon" -- Loop through for Map Query Results for i = 1, #results do -- Set Flags, trying to match them through an object, otherwise settting them as the wiki logo. local flag1 = flags[string.gsub(results[i].team1faction, " ", "_")] or "Logo_2.png" local flag2 = flags[string.gsub(results[i].team2faction, " ", "_")] or "Logo_2.png" -- Set the header and faction tops parts of table. finished = finished.."\n\n=="..results[i].gamemode.." "..results[i].layerversion.."==" finished = finished.."\n{|" if string.find(results[i].team1faction, "FOR") then finished = finished.."\n!"..results[i].team1faction.."" else finished = finished.."\n!"..results[i].team1faction.."" end -- Set flags and ticket counts finished = finished.."\n!"..results[i].team1tickets.." -  "..results[i].team2tickets if string.find(results[i].team2faction, "FOR") then finished = finished.."\n!"..results[i].team2faction.."" else finished = finished.."\n!"..results[i].team2faction.."" end finished = finished.. "\n|-" if string.find(results[i].team1faction, "FOR") then finished = finished.. '\n| style="vertical-align: top;" | Divisions \n' else finished = finished.. '\n| style="vertical-align: top;" | Vehicles \n' end -- Start team1 vehicle listing -- Veh cargo defenitions local wheredef = 'map_vehicle_assets.mappage="'..frame.args[1]..'" AND map_vehicle_assets.gamemode="'..results[i].gamemode..'" AND map_vehicle_assets.layerversion="'..results[i].layerversion..'" AND map_vehicle_assets.teamfaction="'		local argsvehteam1 = {		where = wheredef..results[i].team1faction..'"', orderBy = 'map_vehicle_assets.vehicledisplayname', }		local argsvehteam2 = { where = wheredef..results[i].team2faction..'"',		orderBy = 'map_vehicle_assets.vehicledisplayname',		}		local resultsvehteam1 = cargo.query( tablesveh, fieldsveh, argsvehteam1 )		-- Setting up nondelayed vehicle string and delayed vehicle string		local nondelayvehteam1 = ""		local delayvehteam1 = ""		for j = 1, #resultsvehteam1 do

-- If the vehicle has a delay it should be put in its own string with the delay. if resultsvehteam1[j].delay <= '-1' then nondelayvehteam1 = nondelayvehteam1.. "\n\n "..resultsvehteam1[j].vehicledisplayname.."" else if resultsvehteam1[j].delay ~= '0' then delayvehteam1 = delayvehteam1.. "\n\n"..resultsvehteam1[j].count.."x "..resultsvehteam1[j].vehicledisplayname.." ["..resultsvehteam1[j].delay.." mins]" else nondelayvehteam1 = nondelayvehteam1.. "\n\n"..resultsvehteam1[j].count.."x "..resultsvehteam1[j].vehicledisplayname.."" end end end -- Add nondelayed vehicles first finished = finished..nondelayvehteam1 -- If there are delayed vehicles then we need to add a note and then the delayed vehicles string if delayvehteam1 ~= "" then finished = finished.."\n\nDelayed Spawn"..delayvehteam1 end -- If we know the number of capturepoints then we should list it 		if results[i].capturepoints ~= '0' then finished = finished.. '\n| Capture Points: '..results[i].capturepoints else finished = finished.. '\n| ' end -- Check to see if image for this layer exsits **This is considered intesive and is limited to 99 per wiki page** local image = mw.title.new(frame.args[1].." "..results[i].gamemode.." "..string.gsub(results[i].layerversion, "v", "V")..".jpg", "File") -- If there is an image add it, otherwise throw in the squad wiki logo if image.id ~= 0 then finished = finished.."\n" else finished = finished.."\n Work in Progress - Map picture coming soon " end -- Setup for team 2 vehicles finished = finished.."\n " if string.find(results[i].team2faction, "FOR") then finished = finished.. '\n| style="vertical-align: top;" | Divisions \n' else finished = finished.. '\n| style="vertical-align: top;" | Vehicles \n' end local resultsvehteam2 = cargo.query( tablesveh, fieldsveh, argsvehteam2 ) local nondelayvehteam2 = "" local delayvehteam2 = "" for j = 1, #resultsvehteam2 do

if resultsvehteam2[j].delay <= '-1' then nondelayvehteam2 = nondelayvehteam2.. "\n\n "..resultsvehteam2[j].vehicledisplayname.."" else if resultsvehteam2[j].delay ~= '0' then delayvehteam2 = delayvehteam2.. "\n\n"..resultsvehteam2[j].count.."x "..resultsvehteam2[j].vehicledisplayname.." ["..resultsvehteam2[j].delay.." mins]" else nondelayvehteam2 = nondelayvehteam2.. "\n\n"..resultsvehteam2[j].count.."x "..resultsvehteam2[j].vehicledisplayname.."" end end end finished = finished..nondelayvehteam2 if delayvehteam2 ~= "" then finished = finished.."\n\nDelayed Spawn"..delayvehteam2 end -- End string finished = finished.."\n|}" -- Logging mw.log(finished) end return (finished) end

function p.generateDivisions ( frame ) mw.log('Enter') local formatting = 'style="text-align:center; padding: 20px 10vw 20px;"' local formattingleft = 'style="text-align:left; padding: 20px 10vw 20px;"' -- Division local tables = 'divisions' local fields = 'faction,type,name,longname,badge,info' local args = { where ='divisions.faction="'..frame.args[1]..'"', orderBy = 'divisions.type, divisions.name' }	local results = cargo.query( tables, fields, args ) local finished = "== Divisions ==\n\n" -- Veh Cargo Query Setup local tablesveh = 'division_vehicle_assets' local fieldsveh = 'divisionname,vehicle,vehicledisplayname,count,delay,icon' mw.log('Start Loop') mw.logObject(#results) mw.logObject(frame.args) for i = 1, #results do		mw.log('Loop | '..i)		mw.logObject(results[i]) if(i % 2 == 1 and results[1 + i] == undefined) then finished = finished..'{|style="margin-left: 0; margin-right: auto; border: none;"' local imagecheck = mw.title.new(results[i].badge, 'File') local image = '' if imagecheck.id ~= 0 then image = results[i].badge else image = 'SquadWiki logo.png' end finished = finished..'\n!'..formatting..' | \n==='..results[i].type..'=== \n| \n|-' finished = finished..'\n|'..formatting..' | ' finished = finished.."\n\n"..results[i].name.."" finished = finished..'\n\n'..results[i].longname finished = finished.."\n|\n|-" finished = finished.."\n|"..formattingleft..' | Vehicles ' finished = finished.."\n" local wheredef = 'division_vehicle_assets.faction="'..frame.args[1]..'" AND division_vehicle_assets.divisionname="'			local argsdivision1 = {				where = wheredef..results[i].name..'"', orderBy = 'division_vehicle_assets.vehicledisplayname' }			local resultsdivision1 = cargo.query(tablesveh, fieldsveh, argsdivision1) local nondelayvehdivision1 = "" local delayvehdivision1 = "" for j = 1, #resultsdivision1 do				if resultsdivision1[j].delay <= '0' then mw.logObject(resultsdivision1[j]) nondelayvehdivision1 = nondelayvehdivision1..'\n\n'..resultsdivision1[j].count..'x '..resultsdivision1[j].vehicledisplayname..'' else mw.logObject(resultsdivision1[j]) delayvehdivision1 = delayvehdivision1..'\n\n'..resultsdivision1[j].count..'x '..resultsdivision1[j].vehicledisplayname..' ['..resultsdivision1[j].delay..' mins]' end end finished = finished..nondelayvehdivision1 if delayvehdivision1 ~= '' then finished = finished..'\n\n Delayed Spawn '..delayvehdivision1 end finished = finished..'\n|\n|}' else if(i % 2 == 1) then mw.log('Doin stuff') finished = finished..'{|style="margin-left: 0; margin-right: auto; border: none;"' -- Display Type Here finished = finished..'\n!'..formatting..' | \n==='..results[i].type..'===' finished = finished..'\n!'..formatting..' | \n==='..results[1 + i].type..'===' finished = finished..'\n|-' local imagecheck = mw.title.new(results[i].badge, 'File') local image = '' if imagecheck.id ~= 0 then image = results[i].badge else image = 'SquadWiki logo.png' end local imagecheck2 = mw.title.new(results[1 + i].badge, 'File') local image2 = '' if imagecheck2.id ~= 0 then image2 = results[i + 1].badge else image2 = 'SquadWiki logo.png' end finished = finished..'\n|'..formatting..' | ' finished = finished.."\n\n"..results[i].name.."" finished = finished..'\n\n'..results[i].longname finished = finished..'\n|'..formatting..' | ' finished = finished.."\n\n"..results[1 + i].name.."" finished = finished..'\n\n'..results[1 + i].longname finished = finished.."\n|-" finished = finished.."\n|"..formattingleft..' | Vehicles ' finished = finished.."\n" local wheredef = 'division_vehicle_assets.faction="'..frame.args[1]..'" AND division_vehicle_assets.divisionname="'				local argsdivision1 = {					where = wheredef..results[i].name..'"', orderBy = 'division_vehicle_assets.vehicledisplayname' }				local argsdivision2 = { where = wheredef..results[1 + i].name..'"',					orderBy = 'division_vehicle_assets.vehicledisplayname'				}				-- Team 1				local resultsdivision1 = cargo.query(tablesveh, fieldsveh, argsdivision1)				local nondelayvehdivision1 = ""				local delayvehdivision1 = ""				for j = 1, #resultsdivision1 do					if resultsdivision1[j].delay <= '0' then						mw.logObject(resultsdivision1[j])						nondelayvehdivision1 = nondelayvehdivision1..'\n\n'..resultsdivision1[j].count..'x '..resultsdivision1[j].vehicledisplayname..					else						mw.logObject(resultsdivision1[j])						delayvehdivision1 = delayvehdivision1..'\n\n'..resultsdivision1[j].count..'x '..resultsdivision1[j].vehicledisplayname..' ['..resultsdivision1[j].delay..' mins]'					end				end				finished = finished..nondelayvehdivision1				if delayvehdivision1 ~=  then finished = finished..'\n\n Delayed Spawn '..delayvehdivision1 end -- Team 2 local resultsdivision2 = cargo.query(tablesveh, fieldsveh, argsdivision2) local nondelayvehdivision2 = "" local delayvehdivision2 = "" finished = finished.."\n|"..formattingleft..' | Vehicles ' finished = finished.."\n" for j = 1, #resultsdivision2 do					if resultsdivision2[j].delay <= '0' then nondelayvehdivision2 = nondelayvehdivision2..'\n\n'..resultsdivision2[j].count..'x '..resultsdivision2[j].vehicledisplayname..'' else delayvehdivision2 = delayvehdivision2..'\n\n'..resultsdivision2[j].count..'x '..resultsdivision2[j].vehicledisplayname..' ['..resultsdivision2[j].delay..' mins]' end end finished = finished..nondelayvehdivision2 if delayvehdivision2 ~= '' then finished = finished..'\n\n Delayed Spawn '..delayvehdivision2 end -- End string finished = finished.."\n|}\n\n" --Logging mw.log(finished) mw.log(i) end -- else if		end -- loop end return (finished) end

return p