MrGVSV / bevy_proto

Create config files for entities in Bevy
Other
239 stars 25 forks source link

Added Multi-Templating #3

Closed MrGVSV closed 2 years ago

MrGVSV commented 2 years ago

Goal

Allows for prototypes to define multiple templates, as suggested here: https://github.com/MrGVSV/bevy_proto/pull/2#discussion_r758901050.

Example

We can define templates the same as before:

template: A

However, we can now specify a collection of templates:

templates:
  - A
  - B
  - C

templates and template are interchangeable

We can also define templates as a comma-separated string (for ease of use):

templates: A, B, C  # AKA: "A, B, C"

Multiple Inheritance

One concern with allowing for multiple templates is dealing with the issues of multiple inheritance and possible conflicts that arise from it.

The templating system solves conflicts by simply overriding the components in other templates.

It does so in reverse order.

So if we want a component in B to override a conflicting component in A, we must define it like:

templates: B, A

The reason we do it in reverse order is to better display specificity. More generic templates are listed last since they are (often) less specific. This keeps the most pertinent templates closer to the prototype being defined:

name: "Granny Smith"
templates:
  - Apple # Very Specific
  - Fruit
  - Food
  - Thing # Very Generic

Tasks