// Worthless Bums 2014.


package CommonPackage
{
	function onStart ()
	{//echo("onStart()");//echo("commonConfig.xml file path =" SPC expandPath("commonConfig.xml"));
		//Parent::onStart();	// Wtf did this use to do?!?
		_defaultGameconfigurationData();
		_loadGameConfigurationData(getCommonConfigFilePath());
		
		// Should this be in _loadGameConfigurationData()?
		$pref::Video::windowedRes = $Game::Resolution;
		
		initializeCommon();
	}
	function onExit ()
	{//echo("onExit()");
	echo("      o SHUTTING DOWN STEAM MARINES.");
		_saveGameConfigurationData(getCommonConfigFilePath());
		_shutdownCommon();
		Parent::onExit();
	}
	function getCommonConfigFilePath ()
	{
		return getUserDataDirectory() @ "/Worthless Bums/Steam Marines/commonConfig.xml";
	}
	function displayHelp ()
	{//echo("displayHelp()");
		// Let the parent do its stuff.
		Parent::displayHelp();
		error("Common Mod options:\n" @
			  "  -fullscreen            Starts game in full screen mode\n" @
			  "  -windowed              Starts game in windowed mode\n" @
			  "  -autoVideo             Auto detect video, but prefers OpenGL\n" @
			  "  -openGL                Force OpenGL acceleration\n" @
			  "  -directX               Force DirectX acceleration\n" @
			  "  -voodoo2               Force Voodoo2 acceleration\n" @
			  "  -prefs <configFile>    Exec the config file\n");
	}
	function parseArgs ()
	{//echo("parseArgs()");
		// Let the parent grab the arguments it wants first.
		Parent::parseArgs();
		
		// Loop through the arguments.
		for (%i = 1; %i < $Game::argc; %i++)
		{
			%arg = $Game::argv[%i];
			%nextArg = $Game::argv[%i+1];
			%hasNextArg = $Game::argc - %i > 1;
		
			switch$ (%arg)
			{
				case "-fullscreen":
					$pref::Video::fullScreen = 1;
					$argUsed[%i]++;
				
				case "-windowed":
					$pref::Video::fullScreen = 0;
					$argUsed[%i]++;
				
				case "-openGL":
					$pref::Video::displayDevice = "OpenGL";
					$argUsed[%i]++;
				
				case "-directX":
					$pref::Video::displayDevice = "D3D";
					$argUsed[%i]++;
				
				case "-voodoo2":
					$pref::Video::displayDevice = "Voodoo2";
					$argUsed[%i]++;
				
				case "-autoVideo":
					$pref::Video::displayDevice = "";
					$argUsed[%i]++;
				
				case "-prefs":
					$argUsed[%i]++;
					if (%hasNextArg)
					{
						exec(%nextArg, true, true);
						$argUsed[%i+1]++;
						%i++;
					}
					else
					{
					   error("Error: Missing Command Line argument. Usage: -prefs <path/script.cs>");
					}
			}
		}
	}
};
activatePackage(CommonPackage);