chore(): cargo fmt
This commit is contained in:
parent
8c8e502f3a
commit
72dbad0152
|
@ -178,7 +178,8 @@ pub fn trigger_instance_animation_markers_events(
|
|||
__animation_graphs: Res<Assets<AnimationGraph>>,
|
||||
mut _animation_marker_events: EventWriter<AnimationMarkerReached>,
|
||||
) {
|
||||
for (__entity, __markers, player_link, animations, __animation_infos) in animation_infos.iter() {
|
||||
for (__entity, __markers, player_link, animations, __animation_infos) in animation_infos.iter()
|
||||
{
|
||||
//let (animation_player, animation_transitions) = animation_players.get(player_link.0).unwrap();
|
||||
//let foo = animation_transitions.get_main_animation().unwrap();
|
||||
|
||||
|
|
|
@ -77,16 +77,15 @@ impl Default for BlueprintAssetsLoadState {
|
|||
|
||||
// for preloading asset files
|
||||
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
||||
pub(crate) struct File{
|
||||
pub(crate) struct File {
|
||||
pub(crate) path: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
||||
pub(crate) struct BlueprintPreloadAssets{
|
||||
pub(crate) assets: Vec<(String, File)>
|
||||
pub(crate) struct BlueprintPreloadAssets {
|
||||
pub(crate) assets: Vec<(String, File)>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct BlueprintMetaHandle(pub Handle<BlueprintPreloadAssets>);
|
||||
|
||||
|
@ -94,6 +93,5 @@ pub(crate) struct BlueprintMetaHandle(pub Handle<BlueprintPreloadAssets>);
|
|||
#[derive(Component)]
|
||||
pub(crate) struct BlueprintMetaLoaded;
|
||||
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct BlueprintMetaLoading;
|
||||
pub(crate) struct BlueprintMetaLoading;
|
||||
|
|
|
@ -58,9 +58,11 @@ pub(crate) fn inject_materials(
|
|||
} else {
|
||||
let model_handle: Handle<Gltf> = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now
|
||||
let Some(mat_gltf) = assets_gltf.get(model_handle.id()) else {
|
||||
warn!("materials file {} should have been preloaded skipping",material_info.path);
|
||||
warn!(
|
||||
"materials file {} should have been preloaded skipping",
|
||||
material_info.path
|
||||
);
|
||||
continue;
|
||||
|
||||
};
|
||||
/*let mat_gltf = assets_gltf.get(model_handle.id()).unwrap_or_else(|| {
|
||||
panic!(
|
||||
|
@ -93,18 +95,14 @@ pub(crate) fn inject_materials(
|
|||
material_info.name,
|
||||
material_info.path.clone()
|
||||
);
|
||||
|
||||
|
||||
commands.entity(*child).insert(material.clone());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
commands.entity(entity).insert(MaterialProcessed);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,8 +110,7 @@ impl Plugin for BlueprintsPlugin {
|
|||
.register_type::<Vec<String>>()
|
||||
.register_type::<BlueprintAssets>()
|
||||
.register_type::<HashMap<String, Vec<String>>>()
|
||||
.add_plugins(RonAssetPlugin::<BlueprintPreloadAssets>::new(&["meta.ron"]),)
|
||||
|
||||
.add_plugins(RonAssetPlugin::<BlueprintPreloadAssets>::new(&["meta.ron"]))
|
||||
.configure_sets(
|
||||
Update,
|
||||
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
use std::path::Path;
|
||||
|
||||
use bevy::{
|
||||
gltf::Gltf,
|
||||
prelude::*,
|
||||
scene::SceneInstance,
|
||||
utils::hashbrown::HashMap,
|
||||
};
|
||||
use bevy::{gltf::Gltf, prelude::*, scene::SceneInstance, utils::hashbrown::HashMap};
|
||||
|
||||
use crate::{
|
||||
AnimationInfos, AssetLoadTracker, AssetToBlueprintInstancesMapper, BlueprintAnimationInfosLink, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintAssetsLoadState, BlueprintAssetsLoaded, BlueprintAssetsNotLoaded, BlueprintMetaLoaded, BlueprintMetaLoading, BlueprintPreloadAssets, InstanceAnimationInfosLink, InstanceAnimationPlayerLink, InstanceAnimations, WatchingForChanges
|
||||
AnimationInfos, AssetLoadTracker, AssetToBlueprintInstancesMapper, BlueprintAnimationInfosLink,
|
||||
BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintAssetsLoadState,
|
||||
BlueprintAssetsLoaded, BlueprintAssetsNotLoaded, BlueprintMetaLoaded, BlueprintMetaLoading,
|
||||
BlueprintPreloadAssets, InstanceAnimationInfosLink, InstanceAnimationPlayerLink,
|
||||
InstanceAnimations, WatchingForChanges,
|
||||
};
|
||||
|
||||
|
||||
/// this is a flag component for our levels/game world
|
||||
#[derive(Component)]
|
||||
pub struct GameWorldTag;
|
||||
|
@ -67,8 +65,6 @@ pub struct HideUntilReady;
|
|||
/// Companion to the `HideUntilReady` component: this stores the visibility of the entity before the blueprint was inserted into it
|
||||
pub(crate) struct OriginalVisibility(Visibility);
|
||||
|
||||
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug)]
|
||||
#[reflect(Component)]
|
||||
/// marker component, gets added to all children of a currently spawning blueprint instance, can be usefull to avoid manipulating still in progress entities
|
||||
|
@ -117,25 +113,45 @@ Overview of the Blueprint Spawning process
|
|||
*/
|
||||
|
||||
pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
||||
blueprint_instances_to_spawn: Query<(
|
||||
Entity,
|
||||
&BlueprintInfo,
|
||||
Option<&Name>,
|
||||
Option<&Parent>,
|
||||
Option<&HideUntilReady>,
|
||||
Option<&Visibility>,
|
||||
Option<&AddToGameWorld>,
|
||||
|
||||
), (Without<BlueprintMetaLoading>, Without<BlueprintSpawning>, Without<BlueprintInstanceReady>)>,
|
||||
blueprint_instances_to_spawn: Query<
|
||||
(
|
||||
Entity,
|
||||
&BlueprintInfo,
|
||||
Option<&Name>,
|
||||
Option<&Parent>,
|
||||
Option<&HideUntilReady>,
|
||||
Option<&Visibility>,
|
||||
Option<&AddToGameWorld>,
|
||||
),
|
||||
(
|
||||
Without<BlueprintMetaLoading>,
|
||||
Without<BlueprintSpawning>,
|
||||
Without<BlueprintInstanceReady>,
|
||||
),
|
||||
>,
|
||||
mut game_world: Query<Entity, With<GameWorldTag>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
for (entity, blueprint_info, entity_name, original_parent, hide_until_ready, original_visibility, add_to_world) in blueprint_instances_to_spawn.iter() {
|
||||
for (
|
||||
entity,
|
||||
blueprint_info,
|
||||
entity_name,
|
||||
original_parent,
|
||||
hide_until_ready,
|
||||
original_visibility,
|
||||
add_to_world,
|
||||
) in blueprint_instances_to_spawn.iter()
|
||||
{
|
||||
// get path to assets / metadata file
|
||||
info!("Step 1: spawn request detected: loading metadata file for {:?}", blueprint_info);
|
||||
info!(
|
||||
"Step 1: spawn request detected: loading metadata file for {:?}",
|
||||
blueprint_info
|
||||
);
|
||||
let blueprint_path = blueprint_info.path.clone();
|
||||
let metadata_path = blueprint_path.replace(".glb", ".meta.ron").replace(".gltf", ".meta.ron"); // FIXME: horrible
|
||||
let metadata_path = blueprint_path
|
||||
.replace(".glb", ".meta.ron")
|
||||
.replace(".gltf", ".meta.ron"); // FIXME: horrible
|
||||
let mut asset_infos: Vec<AssetLoadTracker> = vec![];
|
||||
//let foo_handle:Handle<BlueprintPreloadAssets> = asset_server.load(metadata_path);
|
||||
let untyped_handle = asset_server.load_untyped(metadata_path.clone());
|
||||
|
@ -157,11 +173,11 @@ pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
|||
..Default::default()
|
||||
},
|
||||
BlueprintMetaLoading,
|
||||
BlueprintSpawning
|
||||
BlueprintSpawning,
|
||||
));
|
||||
|
||||
// if the entity has no name, add one based on the blueprint's
|
||||
if entity_name.is_none(){
|
||||
if entity_name.is_none() {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(bevy::prelude::Name::from(blueprint_info.name.clone()));
|
||||
|
@ -170,14 +186,14 @@ pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
|||
if original_parent.is_none() {
|
||||
// only allow hiding until ready when the entity does not have a parent (?)
|
||||
if hide_until_ready.is_some() {
|
||||
|
||||
// if there is already a set visibility, save it for later
|
||||
if let Some(original_visibility) = original_visibility {
|
||||
commands.entity(entity).insert(OriginalVisibility(*original_visibility));
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(OriginalVisibility(*original_visibility));
|
||||
}
|
||||
// & now hide the instance until it is ready
|
||||
commands.entity(entity)
|
||||
.insert(Visibility::Hidden);
|
||||
commands.entity(entity).insert(Visibility::Hidden);
|
||||
}
|
||||
|
||||
// only allow automatically adding a newly spawned blueprint instance to the "world", if the entity does not have a parent
|
||||
|
@ -200,9 +216,7 @@ pub(crate) fn blueprints_check_assets_metadata_files_loading(
|
|||
asset_server: Res<AssetServer>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
|
||||
for (entity, _blueprint_info, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
||||
|
||||
let mut all_loaded = true;
|
||||
let mut loaded_amount = 0;
|
||||
let total = assets_to_load.asset_infos.len();
|
||||
|
@ -221,10 +235,12 @@ pub(crate) fn blueprints_check_assets_metadata_files_loading(
|
|||
all_loaded = false;
|
||||
}
|
||||
if all_loaded {
|
||||
commands.entity(entity).insert(BlueprintMetaHandle(asset_server.load(tracker.path.clone()))).remove::<BlueprintAssetsLoadState>();
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintMetaHandle(asset_server.load(tracker.path.clone())))
|
||||
.remove::<BlueprintAssetsLoadState>();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
let progress: f32 = loaded_amount as f32 / total as f32;
|
||||
assets_to_load.progress = progress;
|
||||
|
@ -232,9 +248,11 @@ pub(crate) fn blueprints_check_assets_metadata_files_loading(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub(super) fn blueprints_prepare_spawn(
|
||||
blueprint_instances_to_spawn: Query<(Entity, &BlueprintInfo, &BlueprintMetaHandle), Added<BlueprintMetaHandle>>,
|
||||
blueprint_instances_to_spawn: Query<
|
||||
(Entity, &BlueprintInfo, &BlueprintMetaHandle),
|
||||
Added<BlueprintMetaHandle>,
|
||||
>,
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
// for hot reload
|
||||
|
@ -243,12 +261,11 @@ pub(super) fn blueprints_prepare_spawn(
|
|||
// for debug
|
||||
// all_names: Query<&Name>
|
||||
blueprint_metas: Res<Assets<BlueprintPreloadAssets>>,
|
||||
|
||||
) {
|
||||
for (entity, blueprint_info, blueprint_meta_handle) in blueprint_instances_to_spawn.iter() {
|
||||
info!(
|
||||
"Step 2: metadata loaded: loading assets for {:?}",
|
||||
blueprint_info,
|
||||
blueprint_info,
|
||||
);
|
||||
// we add the asset of the blueprint itself
|
||||
// TODO: add detection of already loaded data
|
||||
|
@ -270,56 +287,55 @@ pub(super) fn blueprints_prepare_spawn(
|
|||
// and we also add all its assets
|
||||
/* prefetch attempt */
|
||||
if let Some(blenvy_metadata) = blueprint_metas.get(&blueprint_meta_handle.0) {
|
||||
for asset in blenvy_metadata.assets.iter() {
|
||||
let asset_path = asset.1.path.clone();
|
||||
let asset_name = asset.0.clone();
|
||||
for asset in blenvy_metadata.assets.iter() {
|
||||
let asset_path = asset.1.path.clone();
|
||||
let asset_name = asset.0.clone();
|
||||
|
||||
let untyped_handle = asset_server.load_untyped(&asset_path);
|
||||
let asset_id = untyped_handle.id();
|
||||
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
|
||||
if !loaded {
|
||||
asset_infos.push(AssetLoadTracker {
|
||||
name: asset_name.clone(),
|
||||
path: asset_path.clone(),
|
||||
id: asset_id,
|
||||
loaded: false,
|
||||
handle: untyped_handle.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
// FIXME: dang, too early, asset server has not yet started loading yet
|
||||
// let path_id = asset_server.get_path_id(&asset.path).expect("we should have alread checked for this asset");
|
||||
let path_id = asset_path.clone();
|
||||
|
||||
// Only do this if hot reload is enabled
|
||||
if watching_for_changes.0 {
|
||||
if !assets_to_blueprint_instances
|
||||
.untyped_id_to_blueprint_entity_ids
|
||||
.contains_key(&path_id)
|
||||
{
|
||||
assets_to_blueprint_instances
|
||||
.untyped_id_to_blueprint_entity_ids
|
||||
.insert(path_id.clone(), vec![]);
|
||||
let untyped_handle = asset_server.load_untyped(&asset_path);
|
||||
let asset_id = untyped_handle.id();
|
||||
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
|
||||
if !loaded {
|
||||
asset_infos.push(AssetLoadTracker {
|
||||
name: asset_name.clone(),
|
||||
path: asset_path.clone(),
|
||||
id: asset_id,
|
||||
loaded: false,
|
||||
handle: untyped_handle.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
// only insert if not already present in mapping
|
||||
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids
|
||||
[&path_id]
|
||||
.contains(&entity)
|
||||
{
|
||||
// println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity));
|
||||
assets_to_blueprint_instances
|
||||
// FIXME: dang, too early, asset server has not yet started loading yet
|
||||
// let path_id = asset_server.get_path_id(&asset.path).expect("we should have alread checked for this asset");
|
||||
let path_id = asset_path.clone();
|
||||
|
||||
// Only do this if hot reload is enabled
|
||||
if watching_for_changes.0 {
|
||||
if !assets_to_blueprint_instances
|
||||
.untyped_id_to_blueprint_entity_ids
|
||||
.get_mut(&path_id)
|
||||
.unwrap()
|
||||
.push(entity);
|
||||
.contains_key(&path_id)
|
||||
{
|
||||
assets_to_blueprint_instances
|
||||
.untyped_id_to_blueprint_entity_ids
|
||||
.insert(path_id.clone(), vec![]);
|
||||
}
|
||||
|
||||
// only insert if not already present in mapping
|
||||
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids[&path_id]
|
||||
.contains(&entity)
|
||||
{
|
||||
// println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity));
|
||||
assets_to_blueprint_instances
|
||||
.untyped_id_to_blueprint_entity_ids
|
||||
.get_mut(&path_id)
|
||||
.unwrap()
|
||||
.push(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!("no asset metadata found for {}, please make sure to generate them using the Blender add-on, or preload your assets manually", blueprint_info.path);
|
||||
}
|
||||
}else {
|
||||
warn!("no asset metadata found for {}, please make sure to generate them using the Blender add-on, or preload your assets manually", blueprint_info.path);
|
||||
}
|
||||
|
||||
|
||||
// Only do this if hot reload is enabled
|
||||
// TODO: should this be added to the list of "all assets" on the blender side instead
|
||||
if watching_for_changes.0 {
|
||||
|
@ -361,7 +377,8 @@ pub(super) fn blueprints_prepare_spawn(
|
|||
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
||||
}
|
||||
|
||||
commands.entity(entity)
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintMetaLoaded)
|
||||
.remove::<BlueprintMetaLoading>()
|
||||
.remove::<BlueprintMetaHandle>();
|
||||
|
@ -423,12 +440,7 @@ pub(crate) fn blueprints_check_assets_loading(
|
|||
|
||||
pub(crate) fn blueprints_assets_loaded(
|
||||
spawn_placeholders: Query<
|
||||
(
|
||||
Entity,
|
||||
&BlueprintInfo,
|
||||
Option<&Transform>,
|
||||
Option<&Name>,
|
||||
),
|
||||
(Entity, &BlueprintInfo, Option<&Transform>, Option<&Name>),
|
||||
(
|
||||
Added<BlueprintAssetsLoaded>,
|
||||
Without<BlueprintAssetsNotLoaded>,
|
||||
|
@ -442,13 +454,7 @@ pub(crate) fn blueprints_assets_loaded(
|
|||
|
||||
mut commands: Commands,
|
||||
) {
|
||||
for (
|
||||
entity,
|
||||
blueprint_info,
|
||||
transform,
|
||||
name,
|
||||
) in spawn_placeholders.iter()
|
||||
{
|
||||
for (entity, blueprint_info, transform, name) in spawn_placeholders.iter() {
|
||||
/*info!(
|
||||
"BLUEPRINT: all assets loaded, attempting to spawn blueprint SCENE {:?} for entity {:?}, id: {:}, parent:{:?}",
|
||||
blueprint_info.name, name, entity, original_parent
|
||||
|
@ -522,8 +528,6 @@ pub(crate) fn blueprints_assets_loaded(
|
|||
graph,
|
||||
},
|
||||
));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -875,8 +879,9 @@ pub(crate) fn blueprints_finalize_instances(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
commands.entity(entity).remove::<BlueprintInstanceDisabled>();
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<BlueprintInstanceDisabled>();
|
||||
for child in all_children.iter_descendants(entity) {
|
||||
commands.entity(child).remove::<BlueprintInstanceDisabled>();
|
||||
}
|
||||
|
@ -884,7 +889,7 @@ pub(crate) fn blueprints_finalize_instances(
|
|||
if hide_until_ready.is_some() {
|
||||
if let Some(original_visibility) = original_visibility {
|
||||
commands.entity(entity).insert(original_visibility.0);
|
||||
}else {
|
||||
} else {
|
||||
commands.entity(entity).insert(Visibility::Inherited);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,13 +70,13 @@ fn components_string_to_components(
|
|||
.expect("deserialzer should have been generated from string");
|
||||
let reflect_deserializer = ReflectDeserializer::new(type_registry);
|
||||
/*let component = reflect_deserializer
|
||||
.deserialize(&mut deserializer)
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"failed to deserialize component {} with value: {:?}",
|
||||
name, value
|
||||
)
|
||||
});*/
|
||||
.deserialize(&mut deserializer)
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"failed to deserialize component {} with value: {:?}",
|
||||
name, value
|
||||
)
|
||||
});*/
|
||||
let Ok(component) = reflect_deserializer.deserialize(&mut deserializer) else {
|
||||
warn!(
|
||||
"failed to deserialize component {} with value: {:?}",
|
||||
|
|
|
@ -45,7 +45,7 @@ pub struct BlenvyPlugin {
|
|||
// for save & load
|
||||
pub save_component_filter: SceneFilter,
|
||||
pub save_resource_filter: SceneFilter,
|
||||
pub save_path: PathBuf
|
||||
pub save_path: PathBuf,
|
||||
}
|
||||
|
||||
impl Default for BlenvyPlugin {
|
||||
|
@ -58,7 +58,7 @@ impl Default for BlenvyPlugin {
|
|||
|
||||
save_component_filter: SceneFilter::default(),
|
||||
save_resource_filter: SceneFilter::default(),
|
||||
save_path: PathBuf::from("blenvy_saves") // TODO: use https://docs.rs/dirs/latest/dirs/ to default to the correct user directory
|
||||
save_path: PathBuf::from("blenvy_saves"), // TODO: use https://docs.rs/dirs/latest/dirs/ to default to the correct user directory
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl Plugin for BlenvyPlugin {
|
|||
ExportRegistryPlugin::default(),
|
||||
BlueprintsPlugin::default(),
|
||||
#[cfg(not(target_arch = "wasm32"))] // save & load is only for non wasm platforms
|
||||
SaveLoadPlugin::default()
|
||||
SaveLoadPlugin::default(),
|
||||
))
|
||||
.insert_resource(BlenvyConfig {
|
||||
export_registry: self.export_registry,
|
||||
|
@ -85,7 +85,7 @@ impl Plugin for BlenvyPlugin {
|
|||
|
||||
save_component_filter: self.save_component_filter.clone(),
|
||||
save_resource_filter: self.save_resource_filter.clone(),
|
||||
save_path: self.save_path.clone()
|
||||
save_path: self.save_path.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ fn export_registry(blenvy_config: Res<BlenvyConfig>) -> bool {
|
|||
|
||||
impl Plugin for ExportRegistryPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.register_asset_root().add_systems(Startup, export_types.run_if(export_registry));
|
||||
app.register_asset_root()
|
||||
.add_systems(Startup, export_types.run_if(export_registry));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,34 +5,44 @@ use crate::{BlueprintInfo, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
|||
use super::BlueprintWorld;
|
||||
|
||||
pub(crate) fn spawn_from_blueprintworld(
|
||||
added_blueprint_worlds: Query<(Entity, &BlueprintWorld), Added<BlueprintWorld> >,
|
||||
added_blueprint_worlds: Query<(Entity, &BlueprintWorld), Added<BlueprintWorld>>,
|
||||
mut commands: Commands,
|
||||
){
|
||||
for (__entity, blueprint_world) in added_blueprint_worlds.iter(){
|
||||
) {
|
||||
for (__entity, blueprint_world) in added_blueprint_worlds.iter() {
|
||||
println!("added blueprintWorld {:?}", blueprint_world);
|
||||
|
||||
// here we spawn the static part our game world/level, which is also a blueprint !
|
||||
let __static_world = commands.spawn((
|
||||
BlueprintInfo::from_path(blueprint_world.path.as_str()), // all we need is a Blueprint info...
|
||||
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||
HideUntilReady, // only reveal the level once it is ready
|
||||
GameWorldTag,
|
||||
)).id();
|
||||
let __static_world = commands
|
||||
.spawn((
|
||||
BlueprintInfo::from_path(blueprint_world.path.as_str()), // all we need is a Blueprint info...
|
||||
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||
HideUntilReady, // only reveal the level once it is ready
|
||||
GameWorldTag,
|
||||
))
|
||||
.id();
|
||||
|
||||
// here we spawn the dynamic entities part of our game world/level, which is also a blueprint !
|
||||
let __dynamic_world = commands.spawn((
|
||||
BlueprintInfo::from_path(blueprint_world.path.replace(".glb", "_dynamic.glb").replace(".gltf", "_dynamic.gltf").as_str()), // all we need is a Blueprint info...
|
||||
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||
HideUntilReady, // only reveal the level once it is ready
|
||||
GameWorldTag
|
||||
)).id();
|
||||
let __dynamic_world = commands
|
||||
.spawn((
|
||||
BlueprintInfo::from_path(
|
||||
blueprint_world
|
||||
.path
|
||||
.replace(".glb", "_dynamic.glb")
|
||||
.replace(".gltf", "_dynamic.gltf")
|
||||
.as_str(),
|
||||
), // all we need is a Blueprint info...
|
||||
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||
HideUntilReady, // only reveal the level once it is ready
|
||||
GameWorldTag,
|
||||
))
|
||||
.id();
|
||||
|
||||
// commands.entity(entity).add_child(static_world);
|
||||
// commands.entity(entity).add_child(dynamic_world);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
pub(crate) fn inject_dynamic_into_children(
|
||||
added_dynamic: Query<Entity, Added<Dynamic> >,
|
||||
all_children: Query<&Children>,
|
||||
|
@ -43,4 +53,4 @@ pub(crate) fn inject_dynamic_into_children(
|
|||
commands.entity(child).insert(Dynamic);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}*/
|
||||
|
|
|
@ -2,7 +2,6 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::{BlueprintInfo, DynamicEntitiesRoot, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
||||
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct LoadingRequest {
|
||||
pub path: String,
|
||||
|
@ -17,23 +16,22 @@ pub struct LoadingRequested {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
- Loading
|
||||
- load request recieved
|
||||
- pause things ?
|
||||
- unload everything
|
||||
- load static data using blueprintInfo
|
||||
- load dynamic data from save file
|
||||
- load dynamic data from save file
|
||||
|
||||
|
||||
General:
|
||||
General:
|
||||
* wrap loading a bevy scene as a blueprint ?
|
||||
* meh, has no assets & co, different logic ?
|
||||
*/
|
||||
pub fn process_load_requests(
|
||||
mut load_requests: EventReader<LoadingRequest>,
|
||||
mut commands: Commands
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let mut save_path: String = "".into();
|
||||
for load_request in load_requests.read() {
|
||||
|
@ -47,14 +45,13 @@ pub fn process_load_requests(
|
|||
}
|
||||
|
||||
pub fn should_load(loading_requests: Option<Res<LoadingRequested>>) -> bool {
|
||||
return resource_exists::<LoadingRequested>(loading_requests)
|
||||
return resource_exists::<LoadingRequested>(loading_requests);
|
||||
}
|
||||
|
||||
// TODO: replace with generic despawner ?
|
||||
pub(crate) fn prepare_loading(
|
||||
mut commands: Commands,
|
||||
mut commands: Commands,
|
||||
gameworlds: Query<Entity, With<GameWorldTag>>,
|
||||
|
||||
) {
|
||||
for e in gameworlds.iter() {
|
||||
info!("--loading: despawn old world/level");
|
||||
|
@ -62,28 +59,25 @@ pub(crate) fn prepare_loading(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
pub(crate) fn load_game(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
load_request: Res<LoadingRequested>,
|
||||
) {
|
||||
info!("--loading: load dynamic data");
|
||||
|
||||
|
||||
//let save_path = Path::new(load_request.path.clone().as_str());
|
||||
|
||||
info!("LOADING FROM {:?}", load_request.path.clone());
|
||||
|
||||
/*let world_root = commands
|
||||
.spawn((
|
||||
bevy::prelude::Name::from("world"),
|
||||
GameWorldTag,
|
||||
TransformBundle::default(),
|
||||
InheritedVisibility::default(),
|
||||
))
|
||||
.id();*/
|
||||
.spawn((
|
||||
bevy::prelude::Name::from("world"),
|
||||
GameWorldTag,
|
||||
TransformBundle::default(),
|
||||
InheritedVisibility::default(),
|
||||
))
|
||||
.id();*/
|
||||
|
||||
// and we fill it with dynamic data
|
||||
// let input = std::fs::read(&path)?;
|
||||
|
@ -95,16 +89,18 @@ pub(crate) fn load_game(
|
|||
},
|
||||
bevy::prelude::Name::from("World_dynamic"),
|
||||
DynamicEntitiesRoot,
|
||||
GameWorldTag
|
||||
GameWorldTag,
|
||||
))
|
||||
.id();
|
||||
|
||||
let _static_data = commands.spawn((
|
||||
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
|
||||
SpawnBlueprint,
|
||||
HideUntilReady,
|
||||
GameWorldTag,
|
||||
)).id();
|
||||
let _static_data = commands
|
||||
.spawn((
|
||||
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
|
||||
SpawnBlueprint,
|
||||
HideUntilReady,
|
||||
GameWorldTag,
|
||||
))
|
||||
.id();
|
||||
|
||||
//commands.entity(world_root).add_child(static_data);
|
||||
//commands.entity(world_root).add_child(dynamic_data);
|
||||
|
@ -113,4 +109,4 @@ pub(crate) fn load_game(
|
|||
|
||||
info!("--loading: loaded dynamic data");
|
||||
commands.remove_resource::<LoadingRequested>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ pub(crate) struct RootEntity;
|
|||
/// internal helper component to store parents before resetting them
|
||||
pub(crate) struct OriginalParent(pub(crate) Entity);
|
||||
|
||||
|
||||
/// Marker component to Flag the root entity of all static entities (immutables)
|
||||
#[derive(Component, Reflect, Debug, Default)]
|
||||
#[reflect(Component)]
|
||||
|
@ -32,7 +31,6 @@ pub struct StaticEntitiesRoot;
|
|||
#[reflect(Component)]
|
||||
pub struct DynamicEntitiesRoot;
|
||||
|
||||
|
||||
#[derive(Resource, Clone, Debug, Default, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
pub struct StaticEntitiesBlueprintInfo {
|
||||
|
@ -40,9 +38,8 @@ pub struct StaticEntitiesBlueprintInfo {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct BlueprintWorld{
|
||||
pub struct BlueprintWorld {
|
||||
pub path: String,
|
||||
}
|
||||
impl BlueprintWorld {
|
||||
|
@ -55,8 +52,6 @@ impl BlueprintWorld {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
/// Plugin for saving & loading
|
||||
pub struct SaveLoadPlugin {}
|
||||
|
@ -65,13 +60,10 @@ impl Plugin for SaveLoadPlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.register_type::<Dynamic>()
|
||||
.register_type::<StaticEntitiesRoot>()
|
||||
|
||||
.add_event::<SavingRequest>()
|
||||
.add_event::<SaveFinished>()
|
||||
|
||||
// common
|
||||
.add_systems(Update, (spawn_from_blueprintworld, )) // inject_dynamic_into_children
|
||||
|
||||
.add_systems(Update, (spawn_from_blueprintworld,)) // inject_dynamic_into_children
|
||||
// saving
|
||||
.add_systems(Update, process_save_requests)
|
||||
.add_systems(
|
||||
|
@ -79,9 +71,7 @@ impl Plugin for SaveLoadPlugin {
|
|||
(prepare_save_game, apply_deferred, save_game, cleanup_save)
|
||||
.chain()
|
||||
.run_if(should_save),
|
||||
|
||||
)
|
||||
|
||||
.add_event::<LoadingRequest>()
|
||||
.add_event::<LoadingFinished>()
|
||||
//loading
|
||||
|
@ -91,9 +81,8 @@ impl Plugin for SaveLoadPlugin {
|
|||
(prepare_loading, apply_deferred, load_game)
|
||||
.chain()
|
||||
.run_if(should_load),
|
||||
//.run_if(not(resource_exists::<LoadFirstStageDone>))
|
||||
// .in_set(LoadingSet::Load),
|
||||
)
|
||||
;
|
||||
//.run_if(not(resource_exists::<LoadFirstStageDone>))
|
||||
// .in_set(LoadingSet::Load),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use std::fs::File;
|
|||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
use bevy::{prelude::*, tasks::IoTaskPool};
|
||||
use bevy::prelude::World;
|
||||
use bevy::{prelude::*, tasks::IoTaskPool};
|
||||
|
||||
use crate::{BlenvyConfig, BlueprintInfo, Dynamic, FromBlueprint, RootEntity, SpawnBlueprint};
|
||||
|
||||
|
@ -16,17 +16,15 @@ pub struct SavingRequest {
|
|||
#[derive(Event)]
|
||||
pub struct SaveFinished; // TODO: merge the the events above
|
||||
|
||||
|
||||
/// resource that keeps track of the current save request
|
||||
#[derive(Resource, Default)]
|
||||
pub struct SavingRequested {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
|
||||
pub fn process_save_requests(
|
||||
mut saving_requests: EventReader<SavingRequest>,
|
||||
mut commands: Commands
|
||||
mut commands: Commands,
|
||||
) {
|
||||
let mut save_path: String = "".into();
|
||||
for saving_request in saving_requests.read() {
|
||||
|
@ -39,12 +37,10 @@ pub fn process_save_requests(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn should_save(saving_requests: Option<Res<SavingRequested>>) -> bool {
|
||||
return resource_exists::<SavingRequested>(saving_requests)
|
||||
return resource_exists::<SavingRequested>(saving_requests);
|
||||
}
|
||||
|
||||
|
||||
// any child of dynamic/ saveable entities that is not saveable itself should be removed from the list of children
|
||||
pub(crate) fn prepare_save_game(
|
||||
saveables: Query<Entity, (With<Dynamic>, With<BlueprintInfo>)>,
|
||||
|
@ -54,7 +50,8 @@ pub(crate) fn prepare_save_game(
|
|||
|
||||
mut commands: Commands,
|
||||
) {
|
||||
for entity in saveables.iter() { // FIXME : not sure about this one
|
||||
for entity in saveables.iter() {
|
||||
// FIXME : not sure about this one
|
||||
commands.entity(entity).insert(SpawnBlueprint);
|
||||
}
|
||||
|
||||
|
@ -83,8 +80,6 @@ pub(crate) fn prepare_save_game(
|
|||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub(crate) fn save_game(world: &mut World) {
|
||||
info!("saving");
|
||||
|
||||
|
@ -125,7 +120,6 @@ pub(crate) fn save_game(world: &mut World) {
|
|||
.allow::<BlueprintInfo>()
|
||||
.allow::<SpawnBlueprint>()
|
||||
.allow::<Dynamic>()
|
||||
|
||||
/*.deny::<CameraRenderGraph>()
|
||||
.deny::<CameraMainTextureUsages>()
|
||||
.deny::<Handle<Mesh>>()
|
||||
|
@ -135,11 +129,12 @@ pub(crate) fn save_game(world: &mut World) {
|
|||
// for root entities, it is the same EXCEPT we make sure parents are not included
|
||||
let filter_root = filter.clone().deny::<Parent>();
|
||||
|
||||
let filter_resources = config.clone()
|
||||
let filter_resources = config
|
||||
.clone()
|
||||
.save_resource_filter
|
||||
.deny::<Time<Real>>()
|
||||
.clone();
|
||||
//.allow::<StaticEntitiesStorage>();
|
||||
//.allow::<StaticEntitiesStorage>();
|
||||
|
||||
// for default stuff
|
||||
let scene_builder = DynamicSceneBuilder::from_world(world)
|
||||
|
@ -190,7 +185,6 @@ pub(crate) fn save_game(world: &mut World) {
|
|||
})
|
||||
.detach();
|
||||
|
||||
|
||||
let static_world_path = "levels/world.glb";
|
||||
let fake_foo = format!("(dynamic: {bla}, static: {static_world_path})");
|
||||
let real_save_path = format!("{bla}.save.ron");
|
||||
|
@ -217,5 +211,4 @@ pub(crate) fn cleanup_save(
|
|||
saving_finished.send(SaveFinished);
|
||||
|
||||
commands.remove_resource::<SavingRequested>();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@ use std::time::Duration;
|
|||
|
||||
use bevy::prelude::*;
|
||||
use blenvy::{
|
||||
BlenvyPlugin, BlueprintAnimationPlayerLink,
|
||||
BlueprintAnimations, BlueprintInfo, GameWorldTag, HideUntilReady,
|
||||
SpawnBlueprint,
|
||||
BlenvyPlugin, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintInfo, GameWorldTag,
|
||||
HideUntilReady, SpawnBlueprint,
|
||||
};
|
||||
|
||||
mod component_examples;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
use blenvy::{
|
||||
AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag, HideUntilReady, SpawnBlueprint
|
||||
AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag,
|
||||
HideUntilReady, SpawnBlueprint,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
|
@ -32,12 +33,8 @@ fn setup_game(mut commands: Commands) {
|
|||
}
|
||||
|
||||
// you can also spawn blueprint instances at runtime
|
||||
pub fn spawn_blueprint_instance(
|
||||
keycode: Res<ButtonInput<KeyCode>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
pub fn spawn_blueprint_instance(keycode: Res<ButtonInput<KeyCode>>, mut commands: Commands) {
|
||||
if keycode.just_pressed(KeyCode::KeyS) {
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let range = 5.5;
|
||||
let x: f32 = rng.gen_range(-range..range);
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
use std::any::TypeId;
|
||||
|
||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
||||
use blenvy::{AddToGameWorld, BlenvyPlugin, BlueprintInfo, BlueprintWorld, Dynamic, GameWorldTag, HideUntilReady, LoadingRequest, SavingRequest, SpawnBlueprint};
|
||||
use blenvy::{
|
||||
AddToGameWorld, BlenvyPlugin, BlueprintInfo, BlueprintWorld, Dynamic, GameWorldTag,
|
||||
HideUntilReady, LoadingRequest, SavingRequest, SpawnBlueprint,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
// mod game;
|
||||
// use game::*;
|
||||
|
||||
mod component_examples;
|
||||
use component_examples::*;
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
use component_examples::*;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
|
@ -39,19 +42,16 @@ fn main() {
|
|||
// GamePlugin, // specific to our game
|
||||
ComponentsExamplesPlugin, // Showcases different type of components /structs
|
||||
))
|
||||
|
||||
.add_systems(Startup, setup_game)
|
||||
.add_systems(Update, (spawn_blueprint_instance, move_movers, save_game, load_game))
|
||||
|
||||
.add_systems(
|
||||
Update,
|
||||
(spawn_blueprint_instance, move_movers, save_game, load_game),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
// this is how you setup & spawn a level from a blueprint
|
||||
fn setup_game(
|
||||
mut commands: Commands,
|
||||
) {
|
||||
|
||||
|
||||
fn setup_game(mut commands: Commands) {
|
||||
// would be nice: contains both static & dynamic stuff
|
||||
commands.spawn((
|
||||
BlueprintWorld::from_path("levels/World.glb"), // will take care of loading both static & dynamic data
|
||||
|
@ -59,10 +59,7 @@ fn setup_game(
|
|||
}
|
||||
|
||||
// you can also spawn blueprint instances at runtime
|
||||
fn spawn_blueprint_instance(
|
||||
keycode: Res<ButtonInput<KeyCode>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
fn spawn_blueprint_instance(keycode: Res<ButtonInput<KeyCode>>, mut commands: Commands) {
|
||||
if keycode.just_pressed(KeyCode::KeyT) {
|
||||
// random position
|
||||
let mut rng = rand::thread_rng();
|
||||
|
@ -73,32 +70,26 @@ fn spawn_blueprint_instance(
|
|||
// random name
|
||||
let name_index: u64 = rng.gen();
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
BlueprintInfo::from_path("blueprints/test.glb"),
|
||||
SpawnBlueprint,
|
||||
Dynamic,
|
||||
bevy::prelude::Name::from(format!("test{}", name_index)),
|
||||
HideUntilReady,
|
||||
AddToGameWorld,
|
||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
||||
));
|
||||
commands.spawn((
|
||||
BlueprintInfo::from_path("blueprints/test.glb"),
|
||||
SpawnBlueprint,
|
||||
Dynamic,
|
||||
bevy::prelude::Name::from(format!("test{}", name_index)),
|
||||
HideUntilReady,
|
||||
AddToGameWorld,
|
||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn move_movers(
|
||||
mut movers: Query<(&mut Transform), With<Dynamic>>
|
||||
) {
|
||||
for mut transform in movers.iter_mut(){
|
||||
fn move_movers(mut movers: Query<(&mut Transform), With<Dynamic>>) {
|
||||
for mut transform in movers.iter_mut() {
|
||||
// println!("moving dynamic entity");
|
||||
transform.translation.x += 0.005;
|
||||
}
|
||||
}
|
||||
|
||||
fn save_game(
|
||||
keycode: Res<ButtonInput<KeyCode>>,
|
||||
mut save_requests: EventWriter<SavingRequest>,
|
||||
) {
|
||||
fn save_game(keycode: Res<ButtonInput<KeyCode>>, mut save_requests: EventWriter<SavingRequest>) {
|
||||
if keycode.just_pressed(KeyCode::KeyS) {
|
||||
save_requests.send(SavingRequest {
|
||||
path: "scenes/save.scn.ron".into(),
|
||||
|
@ -106,11 +97,7 @@ fn save_game(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fn load_game(
|
||||
keycode: Res<ButtonInput<KeyCode>>,
|
||||
mut load_requests: EventWriter<LoadingRequest>,
|
||||
) {
|
||||
fn load_game(keycode: Res<ButtonInput<KeyCode>>, mut load_requests: EventWriter<LoadingRequest>) {
|
||||
if keycode.just_pressed(KeyCode::KeyL) {
|
||||
load_requests.send(LoadingRequest {
|
||||
path: "scenes/save.scn.ron".into(),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{GameState, InAppRunning};
|
||||
use bevy::prelude::*;
|
||||
use blenvy::{
|
||||
AddToGameWorld, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag,
|
||||
HideUntilReady, SpawnBlueprint,
|
||||
AddToGameWorld, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag, HideUntilReady,
|
||||
SpawnBlueprint,
|
||||
};
|
||||
|
||||
//use bevy_rapier3d::prelude::Velocity;
|
||||
|
|
Loading…
Reference in New Issue