Skip to content

Commit

Permalink
feat(Blenvy:Bevy): cleaning up
Browse files Browse the repository at this point in the history
 * removed clutter
 * moved hot reload to seperate module
 * added back "assets loaded" event, removed useless events
 * registered HideUntilReady component for users
 * minor tweaks & cleanups
  • Loading branch information
kaosat-dev committed Jul 8, 2024
1 parent bef709a commit 3099f98
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 117 deletions.
4 changes: 2 additions & 2 deletions crates/blenvy/old/spawn_post_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::prelude::*;
use bevy::scene::SceneInstance;
// use bevy::utils::hashbrown::HashSet;

use crate::{BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintInfo, BlueprintReadyForPostProcess, BlueprintInstanceReady, BlueprintSpawning, SpawnTrackRoot, SubBlueprintsSpawnTracker};
use crate::{BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintInfo, BlueprintReadyForPostProcess, BlueprintInstanceReady, BlueprintSpawning, SubBlueprintSpawnRoot, SubBlueprintsSpawnTracker};
use crate::{SpawnHere, Spawned};
use crate::{
BlueprintEvent, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren
Expand All @@ -32,7 +32,7 @@ pub(crate) fn spawned_blueprint_post_process( // rename to '
&BlueprintInfo,

// sub blueprint instances tracker
Option<&SpawnTrackRoot>
Option<&SubBlueprintSpawnRoot>
),
(With<SpawnHere>, With<SceneInstance>, Added<BlueprintReadyForPostProcess>),
>,
Expand Down
48 changes: 48 additions & 0 deletions crates/blenvy/src/blueprints/hot_reload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

use bevy::prelude::*;
use bevy::asset::{AssetEvent, LoadedUntypedAsset};
use bevy::scene::SceneInstance;
use crate::{BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintInfo, SpawnHere};

pub(crate) fn react_to_asset_changes(
mut gltf_events: EventReader<AssetEvent<Gltf>>,
mut untyped_events: EventReader<AssetEvent<LoadedUntypedAsset>>,
mut blueprint_assets: Query<(Entity, Option<&Name>, &BlueprintInfo, &mut BlueprintAssetsLoadState, Option<&Children>)>,
asset_server: Res<AssetServer>,
mut commands: Commands,

) {

for event in gltf_events.read() {
// LoadedUntypedAsset
match event {
AssetEvent::Modified { id } => {
// React to the image being modified
// println!("Modified gltf {:?}", asset_server.get_path(*id));
for (entity, entity_name, blueprint_info, mut assets_to_load, children) in blueprint_assets.iter_mut() {
for tracker in assets_to_load.asset_infos.iter_mut() {
if asset_server.get_path(*id).is_some() {
if tracker.path == asset_server.get_path(*id).unwrap().to_string() {
println!("HOLY MOLY IT DETECTS !!, now respawn {:?}", entity_name);
if children.is_some() {
for child in children.unwrap().iter(){
commands.entity(*child).despawn_recursive();
}
}
commands.entity(entity)
.remove::<BlueprintAssetsLoaded>()
.remove::<SceneInstance>()
.remove::<BlueprintAssetsLoadState>()
.insert(SpawnHere);

break;
}
}
}
}

}
_ => {}
}
}
}
9 changes: 6 additions & 3 deletions crates/blenvy/src/blueprints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub use materials::*;
pub mod copy_components;
pub use copy_components::*;

pub mod hot_reload;
pub use hot_reload::*;

use core::fmt;
use std::path::PathBuf;

Expand Down Expand Up @@ -98,6 +101,7 @@ impl Plugin for BlueprintsPlugin {
app
.register_watching_for_changes()

.add_event::<BlueprintEvent>()

.register_type::<BlueprintInfo>()
.register_type::<MaterialInfo>()
Expand All @@ -116,10 +120,9 @@ impl Plugin for BlueprintsPlugin {
.register_type::<Vec<String>>()
.register_type::<BlueprintAssets>()

.add_event::<BlueprintEvent>()


.register_type::<HashMap<String, Vec<String>>>()
.register_type::<HideUntilReady>()

.configure_sets(
Update,
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
Expand Down
Loading

0 comments on commit 3099f98

Please sign in to comment.