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 ); }
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); }
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(); } }
private ICollector <TEntity> GetCollector <T>(TriggerOnEvent <TEntity> trigger) where T : IComponent, new() { return(this.CreateCollector(trigger)); }
public void AddReact <TEntity>(TriggerOnEvent <TEntity> trigger, Func <TEntity, bool> filter, Action <List <TEntity> > execute) where TEntity : class, IEntity { AddReact(new [] { trigger }, filter, execute); }
public void AddReactEachLate <TEntity>(TriggerOnEvent <TEntity> trigger, Filter filter, Action <TEntity> execute) where TEntity : class, IEntity { AddReactLate(trigger, filter, entities => entities.ForEach(execute)); }
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)); }
protected void Trigger(TriggerOnEvent <TEntity> trigger) { triggers.Add(trigger); }