Example #1
0
        public void OnEntityAddedToGroup(IEntity entity)
        {
            if (!IsEntityApplicable(entity))
            {
                return;
            }

            CachedEntities.Add(entity);
            _onEntityAdded.OnNext(entity);
        }
        public IEntity CreateEntity(IBlueprint blueprint = null)
        {
            var entity = EntityFactory.Create(null);

            EntityLookup.Add(entity);
            _onEntityAdded.OnNext(new CollectionEntityEvent(entity));
            SubscribeToEntity(entity);

            blueprint?.Apply(entity);

            return(entity);
        }
Example #3
0
        public IEntity CreateEntity(IBlueprint blueprint = null, int?id = null)
        {
            if (id.HasValue && EntityLookup.Contains(id.Value))
            {
                throw new InvalidOperationException("id already exists");
            }

            var entity = EntityFactory.Create(id);

            EntityLookup.Add(entity);
            _onEntityAdded.OnNext(new CollectionEntityEvent(entity));
            SubscribeToEntity(entity);

            blueprint?.Apply(entity);

            return(entity);
        }
Example #4
0
        public void AddEntity(IEntity entity)
        {
            EntityLookup.Add(entity.Id, entity);

            entityAdded.OnNext(new CollectionEntityEvent(entity, this));

            SubscribeToEntity(entity);
        }
Example #5
0
        public void OnEntityComponentRemoved(ComponentsChangedEvent args)
        {
            if (CachedEntities.Contains(args.Entity.Id))
            {
                if (args.Entity.HasAllComponents(Token.LookupGroup.RequiredComponents))
                {
                    return;
                }

                CachedEntities.Remove(args.Entity.Id);
                _onEntityRemoved.OnNext(args.Entity);
                return;
            }

            if (!Token.LookupGroup.Matches(args.Entity))
            {
                return;
            }

            CachedEntities.Add(args.Entity);
            _onEntityAdded.OnNext(args.Entity);
        }
Example #6
0
        public ObservableGroup(ObservableGroupToken token, IEnumerable <IEntity> initialEntities, IEnumerable <INotifyingEntityCollection> notifyingCollections)
        {
            Token = token;
            NotifyingCollections = notifyingCollections;

            _onEntityAdded    = new Subject <IEntity>();
            _onEntityRemoved  = new Subject <IEntity>();
            _onEntityRemoving = new Subject <IEntity>();

            Subscriptions = new List <IDisposable>();
            var applicableEntities = initialEntities.Where(x => Token.LookupGroup.Matches(x));

            CachedEntities = new EntityLookup();

            foreach (var applicableEntity in applicableEntities)
            {
                CachedEntities.Add(applicableEntity);
            }

            NotifyingCollections.ForEachRun(MonitorEntityChanges);
        }