refactor(Blenvy:Bevy):

* removed "Library" component & co
* "InBlueprint" components are now always inserted: removed "NoInblueprint" component
This commit is contained in:
kaosat.dev 2024-07-16 11:06:55 +02:00
parent c1e2bb6ecf
commit b25fc56ea6
2 changed files with 9 additions and 38 deletions

View File

@ -169,21 +169,6 @@ There is also a ```BluePrintBundle``` for convenience , which just has
## Additional information ## Additional information
- When a blueprint is spawned, all its children entities (and nested children etc) also have an ```InBlueprint``` component that gets insert - When a blueprint is spawned, all its children entities (and nested children etc) also have an ```InBlueprint``` component that gets insert
- In cases where that is undesirable, you can add a ```NoInBlueprint``` component on the entity you spawn the blueprint with, and the components above will not be add
- if you want to overwrite the **path** where this crate looks for blueprints (gltf files) , you can add a ```Library``` component , and that will be used instead of the default path
ie :
```rust no_run
commands
.spawn((
Name::from("test"),
BluePrintBundle {
blueprint: BlueprintInfo("TestBlueprint".to_string()),
..Default::default()
},
Library("models".into()) // now the path to the blueprint above will be /assets/models/TestBlueprint.glb
))
```
- this crate also provides a special optional ```GameWorldTag``` component: this is useful when you want to keep all your spawned entities inside a root entity - this crate also provides a special optional ```GameWorldTag``` component: this is useful when you want to keep all your spawned entities inside a root entity
You can use it in your queries to add your entities as children of this "world" You can use it in your queries to add your entities as children of this "world"

View File

@ -37,23 +37,11 @@ impl BlueprintInfo {
#[reflect(Component)] #[reflect(Component)]
pub struct SpawnBlueprint; pub struct SpawnBlueprint;
#[derive(Component, Reflect, Default, Debug)] #[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)] #[reflect(Component)]
/// flag component marking any spwaned child of blueprints ..unless the original entity was marked with the `NoInBlueprint` marker component /// flag component marking any spwaned child of blueprints
pub struct InBlueprint; pub struct InBlueprint;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
/// flag component preventing any spawned child of blueprints to be marked with the `InBlueprint` component
pub struct NoInBlueprint;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
// this allows overriding the default library path for a given entity/blueprint
pub struct Library(pub PathBuf);
#[derive(Component, Reflect, Default, Debug)] #[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)] #[reflect(Component)]
/// flag component to force adding newly spawned entity as child of game world /// flag component to force adding newly spawned entity as child of game world
@ -72,7 +60,7 @@ pub struct HideUntilReady;
#[derive(Component)] #[derive(Component)]
/// marker component, gets added to all children of a currently spawning blueprint instance, can be usefull to avoid manipulating still in progress entities /// marker component, gets added to all children of a currently spawning blueprint instance, can be usefull to avoid manipulating still in progress entities
pub struct BlueprintDisabled; pub struct BlueprintInstanceDisabled;
#[derive(Event, Debug)] #[derive(Event, Debug)]
pub enum BlueprintEvent { pub enum BlueprintEvent {
@ -228,7 +216,7 @@ pub(crate) fn blueprints_prepare_spawn(
.entity(entity) .entity(entity)
.insert(bevy::prelude::Name::from(blueprint_info.name.clone())); .insert(bevy::prelude::Name::from(blueprint_info.name.clone()));
// add the blueprint spawning marker // add the blueprint spawning marker
commands.entity(entity).insert((BlueprintSpawning)); commands.entity(entity).insert(BlueprintSpawning);
} }
} }
@ -510,7 +498,7 @@ pub(crate) fn blueprints_scenes_spawned(
} }
} }
// Mark all components as "Disabled" (until Bevy gets this as first class feature) // Mark all components as "Disabled" (until Bevy gets this as first class feature)
commands.entity(child).insert(BlueprintDisabled); commands.entity(child).insert(BlueprintInstanceDisabled);
} }
} }
@ -548,7 +536,6 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
&OriginalChildren, &OriginalChildren,
Option<&Name>, Option<&Name>,
&BlueprintAnimations, &BlueprintAnimations,
Option<&NoInBlueprint>,
), ),
Added<BlueprintChildrenReady>, Added<BlueprintChildrenReady>,
>, >,
@ -563,7 +550,7 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
all_names: Query<&Name>, all_names: Query<&Name>,
) { ) {
for (original, children, original_children, name, animations, no_inblueprint) in for (original, children, original_children, name, animations) in
blueprint_scenes.iter() blueprint_scenes.iter()
{ {
info!("YOOO ready !! removing empty nodes {:?}", name); info!("YOOO ready !! removing empty nodes {:?}", name);
@ -585,11 +572,10 @@ pub(crate) fn blueprints_cleanup_spawned_scene(
// we flag all children of the blueprint instance with 'InBlueprint' // we flag all children of the blueprint instance with 'InBlueprint'
// can be usefull to filter out anything that came from blueprints vs normal children // can be usefull to filter out anything that came from blueprints vs normal children
if no_inblueprint.is_none() {
for child in all_children.iter_descendants(blueprint_root_entity) { for child in all_children.iter_descendants(blueprint_root_entity) {
commands.entity(child).insert(InBlueprint); // we do this here in order to avoid doing it to normal children commands.entity(child).insert(InBlueprint); // we do this here in order to avoid doing it to normal children
} }
}
// copy components into from blueprint instance's blueprint_root_entity to original entity // copy components into from blueprint instance's blueprint_root_entity to original entity
commands.add(CopyComponents { commands.add(CopyComponents {
@ -758,7 +744,7 @@ pub(crate) fn blueprints_finalize_instances(
} }
for child in all_children.iter_descendants(entity) { for child in all_children.iter_descendants(entity) {
commands.entity(child).remove::<BlueprintDisabled>(); commands.entity(child).remove::<BlueprintInstanceDisabled>();
} }
if hide_until_ready.is_some() { if hide_until_ready.is_some() {