Enum variant relations
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Use enum variants to define relations between entities.
### Example: graphical editor
Set of 2D objects in parent-child hierarchy with components: Color, Shape, Transform.
Color could be a single color OR inherited from another (probably ancestor) entity.
We may also need many more possibly inherited attributes like stroke width, fill, etc.
## What solution would you like?
Make it possible to define them like this:
```rust
#[derive(Component, Debug)]
#[relationship_target(relationship = Color::Inherited)]
pub struct ColorInheritedBy(EntityHashSet);
#[derive(Component, Debug)]
pub enum Color {
Value(bevy::color::Color),
#[relationship(relationship_target = ColorInheritedBy)]
Inherited(Entity),
}
```
Relationship is added when Color::Inherited is added to an Entity.
The macros could have a different name of course if implementation is not feasible to share with the regular relationship definitions.
## What alternative(s) have you considered?
Could just store color value in a component and relation in another one.
## Additional context
I wonder what you think about this kind of design. Enums are nice.
Contributor guide
Research direction
Start by reviewing Bevy's existing regular relationship definitions and the relationship and relationship_target macro entry points mentioned in the proposal. Compare the enum-based Color example with the alternative of separate components, then determine the intended API and acceptance criteria before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100