A registry of all supported mod script types.
Inheritance: IScriptTypeRegistry
Example #1
0
        /// <summary>
        /// Searches for script type assemblies in the specified path, and loads
        /// any script types that are found into a registry.
        /// </summary>
        /// <remarks>
        /// A script type is loaded if the class implements <see cref="IScriptType"/> and is
        /// not abstract. Once loaded, the type is added to the registry.
        /// </remarks>
        /// <param name="p_strSearchPath">The path in which to search for script type assemblies.</param>
        /// <param name="p_gmdGameMode">The current game mode.</param>
        /// <returns>A registry containing all of the discovered script types.</returns>
        public static IScriptTypeRegistry DiscoverScriptTypes(string p_strSearchPath, IGameMode p_gmdGameMode)
        {
            Trace.TraceInformation("Discovering Script Types...");
            Trace.Indent();

            Trace.TraceInformation("Discovering Generic Script Types...");
            Trace.Indent();
            Trace.TraceInformation("Looking in: {0}", p_strSearchPath);
            IScriptTypeRegistry stgRegistry = new ScriptTypeRegistry();

            if (!Directory.Exists(p_strSearchPath))
            {
                Trace.TraceError("Script Type search path does not exist.");
                Trace.Unindent();
                Trace.Unindent();
                return(stgRegistry);
            }
            string[] strAssemblies = Directory.GetFiles(p_strSearchPath, "*.dll");
            RegisterScriptTypes(stgRegistry, strAssemblies);
            Trace.Unindent();

            Trace.TraceInformation("Discovering Game Mode Specific Script Types...");
            Trace.Indent();
            string strGameModeSearchPath = Path.GetDirectoryName(Assembly.GetAssembly(p_gmdGameMode.GetType()).Location);

            Trace.TraceInformation("Looking in: {0}", strGameModeSearchPath);
            if (!Directory.Exists(strGameModeSearchPath))
            {
                Trace.TraceError("Game Mode Specific Script Type search path does not exist.");
                Trace.Unindent();
                Trace.Unindent();
                return(stgRegistry);
            }
            List <string> lstAssemblies = new List <string>();

            foreach (IScriptType stpType in stgRegistry.Types)
            {
                lstAssemblies.AddRange(Directory.GetFiles(strGameModeSearchPath, String.Format("{0}.{1}.dll", p_gmdGameMode.ModeId, stpType.TypeId)));
            }
            RegisterScriptTypes(stgRegistry, lstAssemblies);
            Trace.Unindent();

            Trace.Unindent();
            return(stgRegistry);
        }
		/// <summary>
		/// Searches for script type assemblies in the specified path, and loads
		/// any script types that are found into a registry.
		/// </summary>
		/// <remarks>
		/// A script type is loaded if the class implements <see cref="IScriptType"/> and is
		/// not abstract. Once loaded, the type is added to the registry.
		/// </remarks>
		/// <param name="p_strSearchPath">The path in which to search for script type assemblies.</param>
		/// <param name="p_gmdGameMode">The current game mode.</param>
		/// <returns>A registry containing all of the discovered script types.</returns>
		public static IScriptTypeRegistry DiscoverScriptTypes(string p_strSearchPath, IGameMode p_gmdGameMode)
		{
			Trace.TraceInformation("Discovering Script Types...");
			Trace.Indent();

			Trace.TraceInformation("Discovering Generic Script Types...");
			Trace.Indent();
			Trace.TraceInformation("Looking in: {0}", p_strSearchPath);
			IScriptTypeRegistry stgRegistry = new ScriptTypeRegistry();
			if (!Directory.Exists(p_strSearchPath))
			{
				Trace.TraceError("Script Type search path does not exist.");
				Trace.Unindent();
				Trace.Unindent();
				return stgRegistry;
			}
			string[] strAssemblies = Directory.GetFiles(p_strSearchPath, "*.dll");
			RegisterScriptTypes(stgRegistry, strAssemblies);
			Trace.Unindent();

			Trace.TraceInformation("Discovering Game Mode Specific Script Types...");
			Trace.Indent();
			string strGameModeSearchPath = Path.GetDirectoryName(Assembly.GetAssembly(p_gmdGameMode.GetType()).Location);
			Trace.TraceInformation("Looking in: {0}", strGameModeSearchPath);
			if (!Directory.Exists(strGameModeSearchPath))
			{
				Trace.TraceError("Game Mode Specific Script Type search path does not exist.");
				Trace.Unindent();
				Trace.Unindent();
				return stgRegistry;
			}
			List<string> lstAssemblies = new List<string>();
			foreach (IScriptType stpType in stgRegistry.Types)
				lstAssemblies.AddRange(Directory.GetFiles(strGameModeSearchPath, String.Format("{0}.{1}.dll", p_gmdGameMode.ModeId, stpType.TypeId)));
			RegisterScriptTypes(stgRegistry, lstAssemblies);
			Trace.Unindent();

			Trace.Unindent();
			return stgRegistry;
		}