Skip to content

A small derive macro for turning structs into bundles

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

hytopiagg/bevy_bundled

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bevy_bundled

A small derive macro for turning structs into bundles of components and resources without creating types for each field

What this does

This crate creates a Bundled derive macro, which creates a mirror of your struct in which each field is a component, and the mirror is a bundle. Additionally this crate introduces a ResourceBundle abstraction, in which individual struct fields can be accessed seperately as Resources.

Minimal example

Bundled

#[derive(Default, Bundled)]
struct Player {
    health: f32,
    position: Vec3,
}

fn setup_system(mut commands: Commands) {
    commands.spawn(Player::default().bundled());
}

fn health_system(health: Query<&Player::Health>) {
    // ...
}

ResourceBundle

#[derive(Default, ResourceBundle)]
struct Player {
    health: f32,
    position: Vec3,
}

fn setup_system(mut commands: Commands) {
    commands.init_resource_bundle::<Player>();
}

fn health_system(health: Res<Player::Health>) {
    // ...
}

To do

  • Accessibility
    • Documentation
    • Better Errors
    • Better Examples
      • ResourceBundle Example
      • Idiomatic example for Bundled
  • Unnamed/Tuple Structs
  • Marker Components
    • Possible #[marked] attribute which creates a simple Marker type and field
      • Should automatically be added when .into is called from base struct
    • Marked is the default, with a #[marked] attribute to make it explicit, and an #[unmarked] to disable marking
  • Bundled Resources
    • Mixed Resources and NonSend
  • Possibly generate SystemParams for ResourceBundles and Bundleds to access whole struct easily
  • Unwrapped Fields
    • Nested Bundles
  • Refactoring
    • Use quote_spanned to ensure hygene

About

A small derive macro for turning structs into bundles

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages