bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Component Groups and data position boolean combinators.

Open mintlu8 opened this issue 2 years ago • 0 comments

Objective

Allow a generic group of components access to ergonomic filter queries.

Use case:

trait SomeBehavior {
    type GroupA: ComponentGroup;
    type GroupB: ComponentGroup;
}

fn behavior_system<B: SomeBehavior>(query: Query<
    (Entity, <B::GroupA as ComponentGroup>::ReadQuery), 
    <B::GroupB as ComponentGroup>::With
>) {
     ...
}

Solution

Added trait ComponentGroup implemented on components and tuple Bundles. The trait has GATs that converts the tuple into queries, With queries, Has queries, Added queries, Changed queries, etc.

Or and its new counterpart And can now be used on the data side as boolean combinators to support this change.


Changelog

  • Added aforementioned ComponentGroup.
  • Added the capability of And and Or to function on the data side.
  • Since Changed and Added recently got removed from the data side due to their confusing nature, defined Is<T> = And<(T,)> as a way to use these queries on the data side.
  • Added primitives Always and Never as default cases for some queries.

Migration Guide

I don't think there is a breaking change here.

mintlu8 avatar Jan 28 '24 20:01 mintlu8