protected override void RemoveItem(int index)
        {
            T e = this[index] as T;

            if (e != null)
            {
                e.SetDeleted();
                RemovedEntities.Add(e);
            }

            base.RemoveItem(index);
        }
Exemple #2
0
        /// <summary>
        /// Helper for tests to create snapshots with entities within more collections than just
        /// AddedEntities.
        /// </summary>
        internal IEntity CreateEntity(EntityAddTarget target, string prettyName = "")
        {
            ContentEntity added = new ContentEntity(EntityIdGenerator.Next(), prettyName);

            if (target == EntityAddTarget.Added)
            {
                AddedEntities.Add(added);
            }
            else if (target == EntityAddTarget.Active)
            {
                ActiveEntities.Add(added);
            }
            else
            {
                RemovedEntities.Add(added);
            }

            return(added);
        }
Exemple #3
0
        public GameSnapshotEntityRemoveResult RemoveEntity(IEntity entity)
        {
            if (GlobalEntity == entity)
            {
                return(GameSnapshotEntityRemoveResult.Failed);
            }

            for (int i = 0; i < AddedEntities.Count; ++i)
            {
                if (entity.UniqueId == AddedEntities[i].UniqueId)
                {
                    AddedEntities.RemoveAt(i);
                    return(GameSnapshotEntityRemoveResult.Destroyed);
                }
            }

            for (int i = 0; i < ActiveEntities.Count; ++i)
            {
                if (entity.UniqueId == ActiveEntities[i].UniqueId)
                {
                    IEntity removed = ActiveEntities[i];
                    ActiveEntities.RemoveAt(i);
                    RemovedEntities.Add(removed);
                    return(GameSnapshotEntityRemoveResult.IntoRemoved);
                }
            }

            foreach (IEntity removed in RemovedEntities)
            {
                if (entity.UniqueId == removed.UniqueId)
                {
                    return(GameSnapshotEntityRemoveResult.Failed);
                }
            }

            throw new InvalidOperationException("Unable to find entity with UniqueId = " + entity.UniqueId);
        }
Exemple #4
0
 public override T Remove(T entity)
 {
     RemovedEntities.Add(entity);
     _contentCollection.Remove(entity);
     return(entity);
 }