Esempio n. 1
0
 public void AddReactLate <TEntity>(TriggerOnEvent <TEntity> trigger, Filter filter, Action <List <TEntity> > execute) where TEntity : class, IEntity
 {
     if (filter == Filter.Removed && trigger.groupEvent != GroupEvent.Removed)
     {
         throw new Exception("Filter.Removed needs .Removed() trigger");
     }
     if (filter == Filter.Auto && trigger.groupEvent != GroupEvent.Added)
     {
         throw new Exception("Filter.Auto needs .Added() trigger");
     }
     AddReactLate(
         trigger,
         e => {
         if (filter == Filter.Auto)
         {
             return(trigger.matcher.Matches(e));
         }
         if (filter == Filter.Removed)
         {
             return(!trigger.matcher.Matches(e));
         }
         if (filter == Filter.None)
         {
             return(true);
         }
         throw new Exception("Should never reach here");
     },
         execute
         );
 }
Esempio n. 2
0
    public void AddReact <TEntity>(TriggerOnEvent <TEntity> trigger, Filter filter, Action <List <TEntity> > execute) where TEntity : class, IEntity
    {
        Func <TEntity, bool> predicate;

        switch (filter)
        {
        case Filter.Auto:
            if (trigger.groupEvent != GroupEvent.Added)
            {
                throw new Exception("Filter.Auto needs .Added() trigger");
            }
            predicate = e => trigger.matcher.Matches(e);
            break;

        case Filter.Removed:
            if (trigger.groupEvent != GroupEvent.Removed)
            {
                throw new Exception("Filter.Removed needs .Removed() trigger");
            }
            predicate = e => !trigger.matcher.Matches(e);
            break;

        case Filter.None:
            predicate = e => true;
            break;

        default:
            throw new ArgumentOutOfRangeException("filter", filter, null);
        }

        AddReact(trigger, predicate, execute);
    }
Esempio n. 3
0
        public void TriggerUpdate()
        {
            registeredForUpdate = false;

            if (NewOrRemovedObjects.Count > 0)
            {
                if (TriggerOn)
                {
                    TriggerOnEvent?.Invoke(this);
                }
                NewObjectsEvent?.Invoke(this);
                NewOrRemovedObjects.Clear();
            }

            foreach (var p in ActiveObjects)
            {
                if (p.Value == 0)
                {
                    NewOrRemovedObjects.Add(p.Key);
                }
            }
            if (NewOrRemovedObjects.Count > 0)
            {
                foreach (var p in NewOrRemovedObjects)
                {
                    ActiveObjects.Remove(p);
                }
                ObjectsRemovedEvent?.Invoke(this);
                if (TriggerOff)
                {
                    TriggerOffEvent?.Invoke(this);
                }
                NewOrRemovedObjects.Clear();
            }
        }
Esempio n. 4
0
 private ICollector <TEntity> GetCollector <T>(TriggerOnEvent <TEntity> trigger) where T : IComponent, new()
 {
     return(this.CreateCollector(trigger));
 }
Esempio n. 5
0
 public void AddReact <TEntity>(TriggerOnEvent <TEntity> trigger, Func <TEntity, bool> filter, Action <List <TEntity> > execute) where TEntity : class, IEntity
 {
     AddReact(new [] { trigger }, filter, execute);
 }
Esempio n. 6
0
 public void AddReactEachLate <TEntity>(TriggerOnEvent <TEntity> trigger, Filter filter, Action <TEntity> execute) where TEntity : class, IEntity
 {
     AddReactLate(trigger, filter, entities => entities.ForEach(execute));
 }
Esempio n. 7
0
 public void AddReactEach <TEntity>(TriggerOnEvent <TEntity> trigger, Func <TEntity, bool> filter, Action <TEntity> execute) where TEntity : class, IEntity
 {
     AddReact(trigger, filter, entities => entities.ForEach(execute));
 }
Esempio n. 8
0
 protected void Trigger(TriggerOnEvent <TEntity> trigger)
 {
     triggers.Add(trigger);
 }