Ejemplo n.º 1
0
        private void ReloadPrototypeTypes()
        {
            Clear();
            foreach (var type in ReflectionManager.GetAllChildren <IPrototype>())
            {
                var attribute = (PrototypeAttribute)Attribute.GetCustomAttribute(type, typeof(PrototypeAttribute));
                if (attribute == null)
                {
                    throw new InvalidImplementationException(type, typeof(IPrototype), "No " + nameof(PrototypeAttribute) + " to give it a type string.");
                }

                if (prototypeTypes.ContainsKey(attribute.Type))
                {
                    throw new InvalidImplementationException(type, typeof(IPrototype),
                                                             $"Duplicate prototype type ID: {attribute.Type}. Current: {prototypeTypes[attribute.Type]}");
                }

                prototypeTypes[attribute.Type] = type;
                prototypes[type] = new List <IPrototype>();
                if (typeof(IIndexedPrototype).IsAssignableFrom(type))
                {
                    indexedPrototypes[type] = new Dictionary <string, IIndexedPrototype>();
                }
            }
        }
Ejemplo n.º 2
0
        public void ReflectionManager_TestGetAllChildren()
        {
            IReflectionManager reflectionManager = IoCManager.Resolve <IReflectionManager>();

            // I have no idea how to better do this.
            bool did1 = false;
            bool did2 = false;

            foreach (var type in reflectionManager.GetAllChildren <IReflectionManagerTest>())
            {
                if (!did1 && type == typeof(TestClass1))
                {
                    did1 = true;
                }
                else if (!did2 && type == typeof(TestClass2))
                {
                    did2 = true;
                }
                else if (type == typeof(TestClass3))
                {
                    // Not possible since it has [Reflect(false)]
                    Assert.Fail("ReflectionManager returned the [Reflect(false)] class.");
                }
                else if (type == typeof(TestClass4))
                {
                    Assert.Fail("ReflectionManager returned the abstract class");
                }
                else
                {
                    Assert.Fail("ReflectionManager returned too many types.");
                }
            }
            Assert.That(did1 && did2, Is.True, "IoCManager did not return both expected types. First: {0}, Second: {1}", did1, did2);
        }
Ejemplo n.º 3
0
 private void ReloadPrototypeTypes()
 {
     Clear();
     foreach (var type in ReflectionManager.GetAllChildren <IPrototype>())
     {
         RegisterType(type);
     }
 }
Ejemplo n.º 4
0
 public void Initialize()
 {
     _modeDictionary.Clear();
     foreach (var type in ReflectionManager.GetAllChildren <PlacementMode>())
     {
         _modeDictionary.Add(type.Name, type);
     }
 }
Ejemplo n.º 5
0
        public void DoAutoRegistrations()
        {
            var bodyNetwork = typeof(BodyNetwork);

            foreach (var child in _reflectionManager.GetAllChildren(bodyNetwork))
            {
                Register(child);
            }
        }
Ejemplo n.º 6
0
        public void Initialize()
        {
            var types    = reflectionManager.GetAllChildren <INetSerializableType>();
            var settings = new Settings()
            {
                CustomTypeSerializers = new ITypeSerializer[] { new SfmlTypeSerializer() }
            };

            Serializer = new Serializer(types, settings);
        }
Ejemplo n.º 7
0
        public void Initialize()
        {
            NetworkManager.RegisterNetMessage <MsgPlacement>(MsgPlacement.NAME, HandlePlacementMessage);

            _modeDictionary.Clear();
            foreach (var type in ReflectionManager.GetAllChildren <PlacementMode>())
            {
                _modeDictionary.Add(type.Name, type);
            }

            _mapMan.TileChanged += HandleTileChanged;
        }
Ejemplo n.º 8
0
        public void Initialize()
        {
            LightModes.AddRange(reflectionManager.GetAllChildren <LightMode>());

            if (_resources.TryContentFileRead(DefaultLightMaskTex, out var stream))
            {
                _defaultLightMask = new Texture(stream);
            }
            else
            {
                Logger.Error("Default light map texture could not be found!");
            }
        }
Ejemplo n.º 9
0
#pragma warning restore 649

        public void Initialize()
        {
            var nodeTypes = _reflectionManager.GetAllChildren <Node>();

            foreach (var nodeType in nodeTypes)
            {
                var att = nodeType.GetCustomAttribute <NodeAttribute>();
                if (att != null)
                {
                    _groupTypes.Add(att.Name, nodeType);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Locates and registeres all local commands.
        /// </summary>
        private void InitializeCommands()
        {
            foreach (var t in _reflectionManager.GetAllChildren <IConsoleCommand>())
            {
                var instance = (IConsoleCommand)Activator.CreateInstance(t) !;
                if (_commands.ContainsKey(instance.Command))
                {
                    throw new InvalidOperationException($"Command already registered: {instance.Command}");
                }

                _commands[instance.Command] = instance;
            }
        }
        public void PostInject()
        {
            foreach (Type type in reflectionManager.GetAllChildren <IClientCommand>())
            {
                var instance = Activator.CreateInstance(type, null) as IClientCommand;
                if (AvailableCommands.ContainsKey(instance.Command))
                {
                    throw new Exception("Command name already registered: " + instance.Command);
                }

                AvailableCommands[instance.Command] = instance;
            }
        }
Ejemplo n.º 12
0
        public void PostInject()
        {
            foreach (Type type in reflectionManager.GetAllChildren <IClientCommand>())
            {
                var instance = Activator.CreateInstance(type, null) as IClientCommand;
                if (AvailableCommands.TryGetValue(instance.Command, out IClientCommand duplicate))
                {
                    throw new InvalidImplementationException(instance.GetType(), typeof(IClientCommand), $"Command name already registered: {instance.Command}, previous: {duplicate.GetType()}");
                }

                AvailableCommands[instance.Command] = instance;
            }
        }
Ejemplo n.º 13
0
 // Load all command types.
 private void LoadCommands()
 {
     foreach (Type t in reflectionManager.GetAllChildren <IChatCommand>())
     {
         IChatCommand instance = (IChatCommand)Activator.CreateInstance(t, null);
         if (_commands.ContainsKey(instance.Command))
         {
             Logger.Error("Command has duplicate name: {0}", instance.Command);
             continue;
         }
         _commands[instance.Command] = instance;
     }
 }
 public void Initialize()
 {
     foreach (Type type in ReflectionManager.GetAllChildren <IEntitySystem>())
     {
         //Force initialization of all systems
         var instance = (IEntitySystem)Activator.CreateInstance(type);
         AddSystem(instance);
         instance.RegisterMessageTypes();
         instance.SubscribeEvents();
     }
     foreach (IEntitySystem system in Systems.Values)
     {
         system.Initialize();
     }
 }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public void Initialize()
        {
            foreach (var type in _reflectionManager.GetAllChildren <IEntitySystem>())
            {
                Logger.DebugS("go.sys", "Initializing entity system {0}", type);
                //Force initialization of all systems
                var instance = _typeFactory.CreateInstance <IEntitySystem>(type);
                AddSystem(instance);
            }

            foreach (var system in _systems.Values)
            {
                system.Initialize();
            }
        }
Ejemplo n.º 16
0
        public void Initialize()
        {
            var nodeGroupTypes = _reflectionManager.GetAllChildren <INodeGroup>();

            foreach (var nodeGroupType in nodeGroupTypes)
            {
                var att = nodeGroupType.GetCustomAttribute <NodeGroupAttribute>();
                if (att != null)
                {
                    foreach (var groupID in att.NodeGroupIDs)
                    {
                        _groupTypes.Add(groupID, nodeGroupType);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public void Initialize()
        {
            foreach (var type in reflectionManager.GetAllChildren <IClientCommand>())
            {
                var instance = Activator.CreateInstance(type, null) as IClientCommand;
                if (AvailableCommands.TryGetValue(instance.Command, out var duplicate))
                {
                    throw new InvalidImplementationException(instance.GetType(), typeof(IClientCommand), $"Command name already registered: {instance.Command}, previous: {duplicate.GetType()}");
                }

                AvailableCommands[instance.Command] = instance;
            }

            _net.RegisterNetMessage <MsgConCmd>(MsgConCmd.NAME, ProcessCommand);
            _net.RegisterNetMessage <MsgConCmdAck>(MsgConCmdAck.NAME);
            _net.RegisterNetMessage <MsgConCmdReg>(MsgConCmdReg.NAME, message => HandleRegistrationRequest(message.MsgChannel));
        }
Ejemplo n.º 18
0
        public void Initialize()
        {
            foreach (Type type in ReflectionManager.GetAllChildren <IEntitySystem>())
            {
                Logger.DebugS("go.sys", "Initializing entity system {0}", type);
                //Force initialization of all systems
                var instance = _typeFactory.CreateInstance <IEntitySystem>(type);
                AddSystem(instance);
                instance.RegisterMessageTypes();
                instance.SubscribeEvents();
            }

            foreach (IEntitySystem system in Systems.Values)
            {
                system.Initialize();
            }
        }
Ejemplo n.º 19
0
        private void ReloadComponents()
        {
            foreach (var type in ReflectionManager.GetAllChildren <IComponent>())
            {
                IComponent instance = (IComponent)Activator.CreateInstance(type);
                if (instance.Name == null || instance.Name == "")
                {
                    throw new InvalidImplementationException(type, typeof(IComponent), "Does not have a " + nameof(IComponent.Name));
                }

                if (componentNames.TryGetValue(instance.Name, out Type duplicate))
                {
                    throw new InvalidImplementationException(type, typeof(IComponent), $"Duplicate Name for component: {instance.Name}, previous: {duplicate}");
                }

                componentNames[instance.Name] = type;
            }
        }
Ejemplo n.º 20
0
        /// <inheritdoc />
        public void Initialize()
        {
            HashSet <Type> excludedTypes = new HashSet <Type>();

            foreach (var type in _reflectionManager.GetAllChildren <IEntitySystem>().Concat(_extraLoadedTypes))
            {
                Logger.DebugS("go.sys", "Initializing entity system {0}", type);
                // Force IoC inject of all systems
                var instance = _typeFactory.CreateInstance <IEntitySystem>(type);

                _systems.Add(type, instance);

                // also register systems under their supertypes, so they can be retrieved by their supertype.
                // We don't do this if there are multiple subtype systems of that supertype though, otherwise
                // it wouldn't be clear which instance to return when asking for the supertype
                foreach (var baseType in GetBaseTypes(type))
                {
                    // already known that there are multiple subtype systems of this type,
                    // so don't register under the supertype because it would be unclear
                    // which instance to return if we retrieved it by the supertype
                    if (excludedTypes.Contains(baseType))
                    {
                        continue;
                    }
                    if (_supertypeSystems.ContainsKey(baseType))
                    {
                        _supertypeSystems.Remove(baseType);
                        excludedTypes.Add(baseType);
                    }
                    else
                    {
                        _supertypeSystems.Add(baseType, instance);
                    }
                }
            }

            foreach (var system in _systems.Values)
            {
                system.Initialize();
            }

            _initialized = true;
        }
Ejemplo n.º 21
0
        public void Initialize()
        {
            NetworkManager.RegisterNetMessage <MsgPlacement>(MsgPlacement.NAME, HandlePlacementMessage);

            _modeDictionary.Clear();
            foreach (var type in ReflectionManager.GetAllChildren <PlacementMode>())
            {
                _modeDictionary.Add(type.Name, type);
            }

            _mapMan.TileChanged += HandleTileChanged;
            drawNode             = new Godot.Node2D()
            {
                Name = "Placement Manager Sprite",
            };
            sceneTree.WorldRoot.AddChild(drawNode);
            drawNodeDrawSubscriber = new GodotGlue.GodotSignalSubscriber0();
            drawNodeDrawSubscriber.Connect(drawNode, "draw");
            drawNodeDrawSubscriber.Signal += Render;
        }
Ejemplo n.º 22
0
 public void Initialize()
 {
     LightModes.AddRange(reflectionManager.GetAllChildren <LightMode>());
 }