sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.03k stars 1.11k forks source link

Overload CreateCollector to accept a Matchers directly, which behaves like AllOf #1036

Closed alexandrunechita-popcore closed 1 year ago

alexandrunechita-popcore commented 1 year ago

Now: context.CreateCollector( GameMatcher.AllOf( GameMatcher.Comp1, GameMatcher.Comp2 ) );

And it would be convenient to do: context.CreateCollector( GameMatcher.Comp1, GameMatcher.Comp2 );

I think 5 or 6 parameters maximum would suffice.

sschmid commented 1 year ago

H! You can already:

protected override ICollector<AppEntity> GetTrigger(IContext<AppEntity> context) => context.CreateCollector(
    GameMatcher.Comp1.Added(),
    GameMatcher.Comp2.Added()
);
sschmid commented 1 year ago

Btw, context.CreateCollector(GameMatcher.AllOf(GameMatcher.Comp1, GameMatcher.Comp2)); probably doesn't do what you expect.

(so far so good)

this is probably not what you intend.

The solution mentioned above will trigger the reactive system when comp1 or comp2 are added or replaced.

alexandrunechita-popcore commented 1 year ago

Btw, context.CreateCollector(GameMatcher.AllOf(GameMatcher.Comp1, GameMatcher.Comp2)); probably doesn't do what you expect.

  • add comp1 -> matcher doesn't match yet, entity not added to group
  • add comp2 -> matcher matches, entity is added to group

    • collector will collect added entity

(so far so good)

  • replace either comp1 or comp2

    • nothing will happen, because entity is already in group

this is probably not what you intend.

The solution mentioned above will trigger the reactive system when comp1 or comp2 are added or replaced.

I see. I expect GameMatcher.Comp1 to behave like GameMatcher.Comp1.CHANGED where any addition, removal or replacement qualifies are including the entity in List in the Execute trigger