Ejemplo n.º 1
0
 private void ValidateComponent(GameObjectComponent component)
 {
     if (!component.OwnsThis(owner))
     {
         throw GameObjectComponentException.OwnerException(component);
     }
 }
Ejemplo n.º 2
0
        public void AddComponent(GameObjectComponent component)
        {
            if (component.IsUnique)
            {
                if (components.Find(c => c.GetType() == component.GetType()) != null)
                {
                    throw new ArgumentException("Cant add another unique component.");
                }
            }

            if (components.Contains(component))
            {
                return;
            }

            ValidateComponent(component);

            components.Add(component);

            ComponentAdded(this, new ComponentAddedEventArgs(component));

            components.OrderAllItemsListBy(c => c.UpdateOrder);

            sortedDrawableComponents = components
                                       .Items()
                                       .OrderBy(c => c.DrawOrder)
                                       .ToList();
        }
Ejemplo n.º 3
0
        public ComponentUpdateResults(GameObjectComponent creator, bool wasSuccessfulUpdate)
        {
            if (creator == null)
            {
                throw new ArgumentException("Creator cant be null.");
            }

            this.creator             = creator;
            this.wasSuccessfulUpdate = wasSuccessfulUpdate;
        }
Ejemplo n.º 4
0
        public bool RemoveComponent(GameObjectComponent component)
        {
            if (components.Contains(component))
            {
                sortedDrawableComponents.Remove(component);
                components.Remove(component);

                ComponentRemoved(this, new ComponentRemovedEventArgs(component));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public IEnumerable <ComponentUpdateResults> Update(GameTime gameTime)
        {
            List <ComponentUpdateResults> results = new List <ComponentUpdateResults>();

            for (int i = 0; i < components.Count; i++)
            {
                if (components[i].Destroyed)
                {
                    ComponentRemoved(this, new ComponentRemovedEventArgs(components[i]));
                    components.Remove(components[i]);

                    continue;
                }

                ComponentUpdateResults result = components[i].Update(gameTime, results);

                if (ComponentUpdateResults.IsEmpty(result))
                {
                    continue;
                }

                results.Add(result);
            }

            for (int i = 0; i < results.Count; i++)
            {
                GameObjectComponent component = components.Find(c => results[i].CreatedThis(c));

                if (results[i].BlockNextUpdate)
                {
                    component.SkipUpdate();
                }
            }

            return(results);
        }
Ejemplo n.º 6
0
 public bool CreatedThis(GameObjectComponent component)
 {
     return(ReferenceEquals(component, creator));
 }
Ejemplo n.º 7
0
 public bool ContainsComponent(GameObjectComponent component)
 {
     return(componentManager.Find <GameObjectComponent>(c => ReferenceEquals(c, component)) != null);
 }
Ejemplo n.º 8
0
 public bool RemoveComponent(GameObjectComponent component)
 {
     return(componentManager.RemoveComponent(component));
 }
Ejemplo n.º 9
0
 public void AddComponent(GameObjectComponent component)
 {
     componentManager.AddComponent(component);
 }
Ejemplo n.º 10
0
 public ComponentRemovedEventArgs(GameObjectComponent removedComponent)
     : base(removedComponent)
 {
 }
Ejemplo n.º 11
0
 public ComponentAddedEventArgs(GameObjectComponent addedComponent)
     : base(addedComponent)
 {
 }
Ejemplo n.º 12
0
 public GameObjectComponentEventArgs(GameObjectComponent component)
     : base()
 {
     this.component = component;
 }