Exemplo n.º 1
0
 /// <summary>
 /// Replaces the component of the corresponding type from this entity and takes the old component out of the manager.
 /// If the component type does not exist or is non-exclusive, this method adds the given component to its list.
 /// </summary>
 /// <param name="component">The Component to replace with.</param>
 public void ReplaceComponent(Component_cl component)
 {
     Type type = component.GetType();
     if (mComponents.ContainsKey(type))
     {
         ComponentManager_cl.RemoveComponent(component);
         if (typeof(IExclusiveComponent).IsAssignableFrom(type))
         {
             mComponents[type][0] = component;
         }
         else
         {
             mComponents[type].Add(component);
         }
     }
     else
     {
         mComponents[type].Add(component);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the Component from this Entity.
        /// </summary>
        /// <param name="component">The Component.</param>
        public void RemoveComponent(Component_cl component)
        {
            Type type = component.GetType();
            if (mComponents.ContainsKey(type))
            {
                ComponentManager_cl.RemoveComponent(component);
                mComponents[type].Remove(component);

                // Remove an empty Component list of the type
                if (mComponents[type].Count == 0)
                {
                    mComponents.Remove(type);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a Component to this Entity.
        /// Overwrites any exclusive Component of the same type as the one being added.
        /// Adds to the list for non-exclusive Components.
        /// </summary>
        /// <param name="component">The Component to add.</param>
        public void AddComponent(Component_cl component)
        {
            Type type = component.GetType();
            if (mComponents.ContainsKey(type) == false)
            {
                mComponents.Add(type, new List<Component_cl>());
                mComponents[type].Add(component);
            }

            // Component of matching type already exists
            else if (typeof(IExclusiveComponent).IsAssignableFrom(type))
            {
                mComponents[type][0] = component;
            }
            else
            {
                mComponents[type].Add(component);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Add a component to the master dictionary of all components matched with their string class name.
 /// </summary>
 /// <param name="newComponent">the new component added to the world</param>
 private static void AddComponent(Component_cl newComponent)
 {
     if (mComponents.ContainsKey(newComponent.GetType()))
     {
         mComponents[newComponent.GetType()].Add(newComponent);
     }
     else
     {
         List<Component_cl> componentList = new List<Component_cl>();
         componentList.Add(newComponent);
         mComponents.Add(newComponent.GetType(), componentList);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Remove a component from the manager if it exists in the master dictionary.
 /// </summary>
 /// <param name="component">the component to remove from the master dictionary.</param>
 public static void RemoveComponent(Component_cl component)
 {
     /************************************************************************
      * TODO:
      * Verify that this does not need to store the component to be deleted
      * in another list to then remove on next PreUpdate.
      *
      * Jay Sternfield	-	2011/12/06
      ************************************************************************/
     Type componentType = component.GetType();
     //if (mComponents.ContainsKey(componentType))
     //{
     //    if (mComponents[componentType].Contains(deadComponent))
     //    {
             //if (componentType == typeof(RenderableComponent_cl))
             //{
                 //RenderableManager_cl.Instance.UnregisterComponent((RenderableComponent_cl)component);
                 /************************************************************************
                  * TODO:
                  * Remove the sprite.
                  *
                  * Jay Sternfield	-	2011/12/06
                  ************************************************************************/
             //}
             //else if (componentType == typeof(PhysicsComponent_cl))
             //{
             //    PhysicsManager_cl.Instance.RemovePhysicsBody(((PhysicsComponent_cl)(mComponents[typeof(PhysicsComponent_cl)][0])).PhysicsBody);
             //}
             if (mComponents.Keys.Contains(componentType))
             {
                 mComponents[componentType].Remove(component);
             }
         //}
     //}
 }
Exemplo n.º 6
0
 /// <summary>
 /// Add a component to the pre added component dictionary.
 /// </summary>
 /// <param name="newComponent">the new component added to the world</param>
 public static void PreAddComponent(Component_cl newComponent)
 {
     if (mPreAddedComponents.Contains(newComponent) == false)
     {
         mPreAddedComponents.Add(newComponent);
     }
 }