mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 11:50:53 +00:00
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();
|
||||
|
||||
|
@ -83,10 +83,9 @@ pub(crate) struct File{
|
||||
|
||||
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
||||
pub(crate) struct BlueprintPreloadAssets {
|
||||
pub(crate) assets: Vec<(String, File)>
|
||||
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;
|
@ -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!(
|
||||
@ -97,14 +99,10 @@ pub(crate) fn inject_materials(
|
||||
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,7 +113,8 @@ Overview of the Blueprint Spawning process
|
||||
*/
|
||||
|
||||
pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
||||
blueprint_instances_to_spawn: Query<(
|
||||
blueprint_instances_to_spawn: Query<
|
||||
(
|
||||
Entity,
|
||||
&BlueprintInfo,
|
||||
Option<&Name>,
|
||||
@ -125,17 +122,36 @@ pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
||||
Option<&HideUntilReady>,
|
||||
Option<&Visibility>,
|
||||
Option<&AddToGameWorld>,
|
||||
|
||||
), (Without<BlueprintMetaLoading>, Without<BlueprintSpawning>, Without<BlueprintInstanceReady>)>,
|
||||
),
|
||||
(
|
||||
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,7 +173,7 @@ 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
|
||||
@ -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,7 +261,6 @@ 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!(
|
||||
@ -303,8 +320,7 @@ pub(super) fn blueprints_prepare_spawn(
|
||||
}
|
||||
|
||||
// only insert if not already present in mapping
|
||||
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids
|
||||
[&path_id]
|
||||
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));
|
||||
@ -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>();
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,20 +12,30 @@ pub(crate) fn spawn_from_blueprintworld(
|
||||
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((
|
||||
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();
|
||||
))
|
||||
.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...
|
||||
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();
|
||||
GameWorldTag,
|
||||
))
|
||||
.id();
|
||||
|
||||
// commands.entity(entity).add_child(static_world);
|
||||
// commands.entity(entity).add_child(dynamic_world);
|
||||
|
@ -2,7 +2,6 @@ use bevy::prelude::*;
|
||||
|
||||
use crate::{BlueprintInfo, DynamicEntitiesRoot, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
||||
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct LoadingRequest {
|
||||
pub path: String,
|
||||
@ -17,7 +16,6 @@ pub struct LoadingRequested {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
- Loading
|
||||
- load request recieved
|
||||
@ -33,7 +31,7 @@ General:
|
||||
*/
|
||||
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,
|
||||
gameworlds: Query<Entity, With<GameWorldTag>>,
|
||||
|
||||
) {
|
||||
for e in gameworlds.iter() {
|
||||
info!("--loading: despawn old world/level");
|
||||
@ -62,9 +59,6 @@ pub(crate) fn prepare_loading(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
pub(crate) fn load_game(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
@ -95,16 +89,18 @@ pub(crate) fn load_game(
|
||||
},
|
||||
bevy::prelude::Name::from("World_dynamic"),
|
||||
DynamicEntitiesRoot,
|
||||
GameWorldTag
|
||||
GameWorldTag,
|
||||
))
|
||||
.id();
|
||||
|
||||
let _static_data = commands.spawn((
|
||||
let _static_data = commands
|
||||
.spawn((
|
||||
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
|
||||
SpawnBlueprint,
|
||||
HideUntilReady,
|
||||
GameWorldTag,
|
||||
)).id();
|
||||
))
|
||||
.id();
|
||||
|
||||
//commands.entity(world_root).add_child(static_data);
|
||||
//commands.entity(world_root).add_child(dynamic_data);
|
||||
|
@ -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,7 +38,6 @@ pub struct StaticEntitiesBlueprintInfo {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct BlueprintWorld {
|
||||
pub path: String,
|
||||
@ -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
|
||||
|
||||
// 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
|
||||
@ -93,7 +83,6 @@ impl Plugin for SaveLoadPlugin {
|
||||
.run_if(should_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,7 +129,8 @@ 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();
|
||||
@ -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,8 +70,7 @@ fn spawn_blueprint_instance(
|
||||
// random name
|
||||
let name_index: u64 = rng.gen();
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
commands.spawn((
|
||||
BlueprintInfo::from_path("blueprints/test.glb"),
|
||||
SpawnBlueprint,
|
||||
Dynamic,
|
||||
@ -86,19 +82,14 @@ fn spawn_blueprint_instance(
|
||||
}
|
||||
}
|
||||
|
||||
fn move_movers(
|
||||
mut movers: Query<(&mut Transform), With<Dynamic>>
|
||||
) {
|
||||
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
Block a user