MrGVSV / bevy_proto

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

Add `schematic_attr` for forwarding attributes #59

Closed MrGVSV closed 1 year ago

MrGVSV commented 1 year ago

Objective

Resolves #53

Solution

Adds the schematic_attr and asset_schematic_attr attributes to the Schematic and AssetSchematic derives, respectively. This allows attributes to be forwarded to the generated input type.

For example, take the following schematic:

#[derive(Component, Schematic, Reflect)]
#[schematic_attr(
  derive(Default),
  reflect(Default),
)]
struct MyStruct {
  #[schematic(from = u8)]
  data: u32,
  #[schematic_attr(reflect(ignore))]
  hash: u64,
}

Will now generate an input type like:

#[derive(Reflect)]
#[derive(Default)]
#[reflect(Default)]
struct MyStructInput {
  data: u8,
  #[reflect(ignore)] 
  hash: u64,
}

This also means that reflection attributes are no longer automatically passed to the input type. That behavior was removed as it would sometimes result in invalid behavior and was also not very flexible.