Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine("initializing CityEngine");

            // Get all mods
            var directory = new DirectoryInfo(Directory.GetCurrentDirectory());

            if (directory.Exists)
            {
                var mods  = new Dictionary <string, Type>();
                var files = directory.GetFiles("mod-*.dll");

                foreach (var file in files)
                {
                    try
                    {
                        Assembly assembly = Assembly.LoadFrom(file.FullName);
                        Type[]   types    = assembly.GetTypes();

                        foreach (Type type in types)
                        {
                            var attributes = type.GetCustomAttributes(typeof(GameModAttribute), true);
                            if (attributes.Length > 0)
                            {
                                var a = attributes[0] as GameModAttribute;
                                mods.Add(a.name, type);

                                Debug.WriteLine("found mod {0} [{1}]", a.name, a.version);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }

                if (mods.Count > 0)
                {
                    // Just get the first found mod for now
                    var selectedMod = mods.First();
                    Debug.WriteLine("loading mod: " + selectedMod.Key);

                    this.Mod = (GameModBase)selectedMod.Value.GetConstructor(Type.EmptyTypes).Invoke(null);
                }
            }

            base.Initialize();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine("initializing CityEngine");

            // Get all mods
            var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
            if (directory.Exists)
            {
                var mods = new Dictionary<string, Type>();
                var files = directory.GetFiles("mod-*.dll");

                foreach (var file in files)
                {
                    try
                    {
                        Assembly assembly = Assembly.LoadFrom(file.FullName);
                        Type[] types = assembly.GetTypes();

                        foreach (Type type in types)
                        {
                            var attributes = type.GetCustomAttributes(typeof(GameModAttribute), true);
                            if (attributes.Length > 0)
                            {
                                var a = attributes[0] as GameModAttribute;
                                mods.Add(a.name, type);

                                Debug.WriteLine("found mod {0} [{1}]", a.name, a.version);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }

                if (mods.Count > 0)
                {
                    // Just get the first found mod for now
                    var selectedMod = mods.First();
                    Debug.WriteLine("loading mod: " + selectedMod.Key);

                    this.Mod = (GameModBase)selectedMod.Value.GetConstructor(Type.EmptyTypes).Invoke(null);
                }
            }

            base.Initialize();
        }