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>>,
|
__animation_graphs: Res<Assets<AnimationGraph>>,
|
||||||
mut _animation_marker_events: EventWriter<AnimationMarkerReached>,
|
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 (animation_player, animation_transitions) = animation_players.get(player_link.0).unwrap();
|
||||||
//let foo = animation_transitions.get_main_animation().unwrap();
|
//let foo = animation_transitions.get_main_animation().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -77,16 +77,15 @@ impl Default for BlueprintAssetsLoadState {
|
||||||
|
|
||||||
// for preloading asset files
|
// for preloading asset files
|
||||||
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
||||||
pub(crate) struct File{
|
pub(crate) struct File {
|
||||||
pub(crate) path: String,
|
pub(crate) path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath, Debug)]
|
||||||
pub(crate) struct BlueprintPreloadAssets{
|
pub(crate) struct BlueprintPreloadAssets {
|
||||||
pub(crate) assets: Vec<(String, File)>
|
pub(crate) assets: Vec<(String, File)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct BlueprintMetaHandle(pub Handle<BlueprintPreloadAssets>);
|
pub(crate) struct BlueprintMetaHandle(pub Handle<BlueprintPreloadAssets>);
|
||||||
|
|
||||||
|
@ -94,6 +93,5 @@ pub(crate) struct BlueprintMetaHandle(pub Handle<BlueprintPreloadAssets>);
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct BlueprintMetaLoaded;
|
pub(crate) struct BlueprintMetaLoaded;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct BlueprintMetaLoading;
|
pub(crate) struct BlueprintMetaLoading;
|
|
@ -58,9 +58,11 @@ pub(crate) fn inject_materials(
|
||||||
} else {
|
} else {
|
||||||
let model_handle: Handle<Gltf> = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now
|
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 {
|
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;
|
continue;
|
||||||
|
|
||||||
};
|
};
|
||||||
/*let mat_gltf = assets_gltf.get(model_handle.id()).unwrap_or_else(|| {
|
/*let mat_gltf = assets_gltf.get(model_handle.id()).unwrap_or_else(|| {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -97,14 +99,10 @@ pub(crate) fn inject_materials(
|
||||||
commands.entity(*child).insert(material.clone());
|
commands.entity(*child).insert(material.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
commands.entity(entity).insert(MaterialProcessed);
|
commands.entity(entity).insert(MaterialProcessed);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,8 +110,7 @@ impl Plugin for BlueprintsPlugin {
|
||||||
.register_type::<Vec<String>>()
|
.register_type::<Vec<String>>()
|
||||||
.register_type::<BlueprintAssets>()
|
.register_type::<BlueprintAssets>()
|
||||||
.register_type::<HashMap<String, Vec<String>>>()
|
.register_type::<HashMap<String, Vec<String>>>()
|
||||||
.add_plugins(RonAssetPlugin::<BlueprintPreloadAssets>::new(&["meta.ron"]),)
|
.add_plugins(RonAssetPlugin::<BlueprintPreloadAssets>::new(&["meta.ron"]))
|
||||||
|
|
||||||
.configure_sets(
|
.configure_sets(
|
||||||
Update,
|
Update,
|
||||||
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
(GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{gltf::Gltf, prelude::*, scene::SceneInstance, utils::hashbrown::HashMap};
|
||||||
gltf::Gltf,
|
|
||||||
prelude::*,
|
|
||||||
scene::SceneInstance,
|
|
||||||
utils::hashbrown::HashMap,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
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
|
/// this is a flag component for our levels/game world
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct GameWorldTag;
|
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
|
/// Companion to the `HideUntilReady` component: this stores the visibility of the entity before the blueprint was inserted into it
|
||||||
pub(crate) struct OriginalVisibility(Visibility);
|
pub(crate) struct OriginalVisibility(Visibility);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Component, Reflect, Default, Debug)]
|
#[derive(Component, Reflect, Default, Debug)]
|
||||||
#[reflect(Component)]
|
#[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
|
/// 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(
|
pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
||||||
blueprint_instances_to_spawn: Query<(
|
blueprint_instances_to_spawn: Query<
|
||||||
|
(
|
||||||
Entity,
|
Entity,
|
||||||
&BlueprintInfo,
|
&BlueprintInfo,
|
||||||
Option<&Name>,
|
Option<&Name>,
|
||||||
|
@ -125,17 +122,36 @@ pub(super) fn blueprints_prepare_metadata_file_for_spawn(
|
||||||
Option<&HideUntilReady>,
|
Option<&HideUntilReady>,
|
||||||
Option<&Visibility>,
|
Option<&Visibility>,
|
||||||
Option<&AddToGameWorld>,
|
Option<&AddToGameWorld>,
|
||||||
|
),
|
||||||
), (Without<BlueprintMetaLoading>, Without<BlueprintSpawning>, Without<BlueprintInstanceReady>)>,
|
(
|
||||||
|
Without<BlueprintMetaLoading>,
|
||||||
|
Without<BlueprintSpawning>,
|
||||||
|
Without<BlueprintInstanceReady>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
mut game_world: Query<Entity, With<GameWorldTag>>,
|
mut game_world: Query<Entity, With<GameWorldTag>>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
mut commands: Commands,
|
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
|
// 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 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 mut asset_infos: Vec<AssetLoadTracker> = vec![];
|
||||||
//let foo_handle:Handle<BlueprintPreloadAssets> = asset_server.load(metadata_path);
|
//let foo_handle:Handle<BlueprintPreloadAssets> = asset_server.load(metadata_path);
|
||||||
let untyped_handle = asset_server.load_untyped(metadata_path.clone());
|
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()
|
..Default::default()
|
||||||
},
|
},
|
||||||
BlueprintMetaLoading,
|
BlueprintMetaLoading,
|
||||||
BlueprintSpawning
|
BlueprintSpawning,
|
||||||
));
|
));
|
||||||
|
|
||||||
// if the entity has no name, add one based on the blueprint's
|
// if the entity has no name, add one based on the blueprint's
|
||||||
if entity_name.is_none(){
|
if entity_name.is_none() {
|
||||||
commands
|
commands
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
.insert(bevy::prelude::Name::from(blueprint_info.name.clone()));
|
.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() {
|
if original_parent.is_none() {
|
||||||
// only allow hiding until ready when the entity does not have a parent (?)
|
// only allow hiding until ready when the entity does not have a parent (?)
|
||||||
if hide_until_ready.is_some() {
|
if hide_until_ready.is_some() {
|
||||||
|
|
||||||
// if there is already a set visibility, save it for later
|
// if there is already a set visibility, save it for later
|
||||||
if let Some(original_visibility) = original_visibility {
|
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
|
// & now hide the instance until it is ready
|
||||||
commands.entity(entity)
|
commands.entity(entity).insert(Visibility::Hidden);
|
||||||
.insert(Visibility::Hidden);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// only allow automatically adding a newly spawned blueprint instance to the "world", if the entity does not have a parent
|
// 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>,
|
asset_server: Res<AssetServer>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
for (entity, _blueprint_info, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
for (entity, _blueprint_info, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
||||||
|
|
||||||
let mut all_loaded = true;
|
let mut all_loaded = true;
|
||||||
let mut loaded_amount = 0;
|
let mut loaded_amount = 0;
|
||||||
let total = assets_to_load.asset_infos.len();
|
let total = assets_to_load.asset_infos.len();
|
||||||
|
@ -221,10 +235,12 @@ pub(crate) fn blueprints_check_assets_metadata_files_loading(
|
||||||
all_loaded = false;
|
all_loaded = false;
|
||||||
}
|
}
|
||||||
if all_loaded {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
let progress: f32 = loaded_amount as f32 / total as f32;
|
let progress: f32 = loaded_amount as f32 / total as f32;
|
||||||
assets_to_load.progress = progress;
|
assets_to_load.progress = progress;
|
||||||
|
@ -232,9 +248,11 @@ pub(crate) fn blueprints_check_assets_metadata_files_loading(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub(super) fn blueprints_prepare_spawn(
|
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,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
// for hot reload
|
// for hot reload
|
||||||
|
@ -243,7 +261,6 @@ pub(super) fn blueprints_prepare_spawn(
|
||||||
// for debug
|
// for debug
|
||||||
// all_names: Query<&Name>
|
// all_names: Query<&Name>
|
||||||
blueprint_metas: Res<Assets<BlueprintPreloadAssets>>,
|
blueprint_metas: Res<Assets<BlueprintPreloadAssets>>,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
for (entity, blueprint_info, blueprint_meta_handle) in blueprint_instances_to_spawn.iter() {
|
for (entity, blueprint_info, blueprint_meta_handle) in blueprint_instances_to_spawn.iter() {
|
||||||
info!(
|
info!(
|
||||||
|
@ -303,8 +320,7 @@ pub(super) fn blueprints_prepare_spawn(
|
||||||
}
|
}
|
||||||
|
|
||||||
// only insert if not already present in mapping
|
// only insert if not already present in mapping
|
||||||
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids
|
if !assets_to_blueprint_instances.untyped_id_to_blueprint_entity_ids[&path_id]
|
||||||
[&path_id]
|
|
||||||
.contains(&entity)
|
.contains(&entity)
|
||||||
{
|
{
|
||||||
// println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity));
|
// println!("adding mapping between {} and entity {:?}", path_id, all_names.get(entity));
|
||||||
|
@ -316,7 +332,7 @@ pub(super) fn blueprints_prepare_spawn(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
} 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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +377,8 @@ pub(super) fn blueprints_prepare_spawn(
|
||||||
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
commands.entity(entity)
|
commands
|
||||||
|
.entity(entity)
|
||||||
.insert(BlueprintMetaLoaded)
|
.insert(BlueprintMetaLoaded)
|
||||||
.remove::<BlueprintMetaLoading>()
|
.remove::<BlueprintMetaLoading>()
|
||||||
.remove::<BlueprintMetaHandle>();
|
.remove::<BlueprintMetaHandle>();
|
||||||
|
@ -423,12 +440,7 @@ pub(crate) fn blueprints_check_assets_loading(
|
||||||
|
|
||||||
pub(crate) fn blueprints_assets_loaded(
|
pub(crate) fn blueprints_assets_loaded(
|
||||||
spawn_placeholders: Query<
|
spawn_placeholders: Query<
|
||||||
(
|
(Entity, &BlueprintInfo, Option<&Transform>, Option<&Name>),
|
||||||
Entity,
|
|
||||||
&BlueprintInfo,
|
|
||||||
Option<&Transform>,
|
|
||||||
Option<&Name>,
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
Added<BlueprintAssetsLoaded>,
|
Added<BlueprintAssetsLoaded>,
|
||||||
Without<BlueprintAssetsNotLoaded>,
|
Without<BlueprintAssetsNotLoaded>,
|
||||||
|
@ -442,13 +454,7 @@ pub(crate) fn blueprints_assets_loaded(
|
||||||
|
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
for (
|
for (entity, blueprint_info, transform, name) in spawn_placeholders.iter() {
|
||||||
entity,
|
|
||||||
blueprint_info,
|
|
||||||
transform,
|
|
||||||
name,
|
|
||||||
) in spawn_placeholders.iter()
|
|
||||||
{
|
|
||||||
/*info!(
|
/*info!(
|
||||||
"BLUEPRINT: all assets loaded, attempting to spawn blueprint SCENE {:?} for entity {:?}, id: {:}, parent:{:?}",
|
"BLUEPRINT: all assets loaded, attempting to spawn blueprint SCENE {:?} for entity {:?}, id: {:}, parent:{:?}",
|
||||||
blueprint_info.name, name, entity, original_parent
|
blueprint_info.name, name, entity, original_parent
|
||||||
|
@ -522,8 +528,6 @@ pub(crate) fn blueprints_assets_loaded(
|
||||||
graph,
|
graph,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -875,8 +879,9 @@ pub(crate) fn blueprints_finalize_instances(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands
|
||||||
commands.entity(entity).remove::<BlueprintInstanceDisabled>();
|
.entity(entity)
|
||||||
|
.remove::<BlueprintInstanceDisabled>();
|
||||||
for child in all_children.iter_descendants(entity) {
|
for child in all_children.iter_descendants(entity) {
|
||||||
commands.entity(child).remove::<BlueprintInstanceDisabled>();
|
commands.entity(child).remove::<BlueprintInstanceDisabled>();
|
||||||
}
|
}
|
||||||
|
@ -884,7 +889,7 @@ pub(crate) fn blueprints_finalize_instances(
|
||||||
if hide_until_ready.is_some() {
|
if hide_until_ready.is_some() {
|
||||||
if let Some(original_visibility) = original_visibility {
|
if let Some(original_visibility) = original_visibility {
|
||||||
commands.entity(entity).insert(original_visibility.0);
|
commands.entity(entity).insert(original_visibility.0);
|
||||||
}else {
|
} else {
|
||||||
commands.entity(entity).insert(Visibility::Inherited);
|
commands.entity(entity).insert(Visibility::Inherited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub struct BlenvyPlugin {
|
||||||
// for save & load
|
// for save & load
|
||||||
pub save_component_filter: SceneFilter,
|
pub save_component_filter: SceneFilter,
|
||||||
pub save_resource_filter: SceneFilter,
|
pub save_resource_filter: SceneFilter,
|
||||||
pub save_path: PathBuf
|
pub save_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BlenvyPlugin {
|
impl Default for BlenvyPlugin {
|
||||||
|
@ -58,7 +58,7 @@ impl Default for BlenvyPlugin {
|
||||||
|
|
||||||
save_component_filter: SceneFilter::default(),
|
save_component_filter: SceneFilter::default(),
|
||||||
save_resource_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(),
|
ExportRegistryPlugin::default(),
|
||||||
BlueprintsPlugin::default(),
|
BlueprintsPlugin::default(),
|
||||||
#[cfg(not(target_arch = "wasm32"))] // save & load is only for non wasm platforms
|
#[cfg(not(target_arch = "wasm32"))] // save & load is only for non wasm platforms
|
||||||
SaveLoadPlugin::default()
|
SaveLoadPlugin::default(),
|
||||||
))
|
))
|
||||||
.insert_resource(BlenvyConfig {
|
.insert_resource(BlenvyConfig {
|
||||||
export_registry: self.export_registry,
|
export_registry: self.export_registry,
|
||||||
|
@ -85,7 +85,7 @@ impl Plugin for BlenvyPlugin {
|
||||||
|
|
||||||
save_component_filter: self.save_component_filter.clone(),
|
save_component_filter: self.save_component_filter.clone(),
|
||||||
save_resource_filter: self.save_resource_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 {
|
impl Plugin for ExportRegistryPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
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,27 +5,37 @@ use crate::{BlueprintInfo, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
||||||
use super::BlueprintWorld;
|
use super::BlueprintWorld;
|
||||||
|
|
||||||
pub(crate) fn spawn_from_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,
|
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);
|
println!("added blueprintWorld {:?}", blueprint_world);
|
||||||
|
|
||||||
// here we spawn the static part our game world/level, which is also a blueprint !
|
// 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...
|
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
|
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||||
HideUntilReady, // only reveal the level once it is ready
|
HideUntilReady, // only reveal the level once it is ready
|
||||||
GameWorldTag,
|
GameWorldTag,
|
||||||
)).id();
|
))
|
||||||
|
.id();
|
||||||
|
|
||||||
// here we spawn the dynamic entities part of our game world/level, which is also a blueprint !
|
// here we spawn the dynamic entities part of our game world/level, which is also a blueprint !
|
||||||
let __dynamic_world = commands.spawn((
|
let __dynamic_world = commands
|
||||||
BlueprintInfo::from_path(blueprint_world.path.replace(".glb", "_dynamic.glb").replace(".gltf", "_dynamic.gltf").as_str()), // all we need is a Blueprint info...
|
.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
|
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||||
HideUntilReady, // only reveal the level once it is ready
|
HideUntilReady, // only reveal the level once it is ready
|
||||||
GameWorldTag
|
GameWorldTag,
|
||||||
)).id();
|
))
|
||||||
|
.id();
|
||||||
|
|
||||||
// commands.entity(entity).add_child(static_world);
|
// commands.entity(entity).add_child(static_world);
|
||||||
// commands.entity(entity).add_child(dynamic_world);
|
// commands.entity(entity).add_child(dynamic_world);
|
||||||
|
|
|
@ -2,7 +2,6 @@ use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{BlueprintInfo, DynamicEntitiesRoot, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
use crate::{BlueprintInfo, DynamicEntitiesRoot, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
pub struct LoadingRequest {
|
pub struct LoadingRequest {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
@ -17,7 +16,6 @@ pub struct LoadingRequested {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
- Loading
|
- Loading
|
||||||
- load request recieved
|
- load request recieved
|
||||||
|
@ -33,7 +31,7 @@ General:
|
||||||
*/
|
*/
|
||||||
pub fn process_load_requests(
|
pub fn process_load_requests(
|
||||||
mut load_requests: EventReader<LoadingRequest>,
|
mut load_requests: EventReader<LoadingRequest>,
|
||||||
mut commands: Commands
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
let mut save_path: String = "".into();
|
let mut save_path: String = "".into();
|
||||||
for load_request in load_requests.read() {
|
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 {
|
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 ?
|
// TODO: replace with generic despawner ?
|
||||||
pub(crate) fn prepare_loading(
|
pub(crate) fn prepare_loading(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
gameworlds: Query<Entity, With<GameWorldTag>>,
|
gameworlds: Query<Entity, With<GameWorldTag>>,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
for e in gameworlds.iter() {
|
for e in gameworlds.iter() {
|
||||||
info!("--loading: despawn old world/level");
|
info!("--loading: despawn old world/level");
|
||||||
|
@ -62,9 +59,6 @@ pub(crate) fn prepare_loading(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub(crate) fn load_game(
|
pub(crate) fn load_game(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
|
@ -95,16 +89,18 @@ pub(crate) fn load_game(
|
||||||
},
|
},
|
||||||
bevy::prelude::Name::from("World_dynamic"),
|
bevy::prelude::Name::from("World_dynamic"),
|
||||||
DynamicEntitiesRoot,
|
DynamicEntitiesRoot,
|
||||||
GameWorldTag
|
GameWorldTag,
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let _static_data = commands.spawn((
|
let _static_data = commands
|
||||||
|
.spawn((
|
||||||
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
|
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
|
||||||
SpawnBlueprint,
|
SpawnBlueprint,
|
||||||
HideUntilReady,
|
HideUntilReady,
|
||||||
GameWorldTag,
|
GameWorldTag,
|
||||||
)).id();
|
))
|
||||||
|
.id();
|
||||||
|
|
||||||
//commands.entity(world_root).add_child(static_data);
|
//commands.entity(world_root).add_child(static_data);
|
||||||
//commands.entity(world_root).add_child(dynamic_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
|
/// internal helper component to store parents before resetting them
|
||||||
pub(crate) struct OriginalParent(pub(crate) Entity);
|
pub(crate) struct OriginalParent(pub(crate) Entity);
|
||||||
|
|
||||||
|
|
||||||
/// Marker component to Flag the root entity of all static entities (immutables)
|
/// Marker component to Flag the root entity of all static entities (immutables)
|
||||||
#[derive(Component, Reflect, Debug, Default)]
|
#[derive(Component, Reflect, Debug, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
|
@ -32,7 +31,6 @@ pub struct StaticEntitiesRoot;
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct DynamicEntitiesRoot;
|
pub struct DynamicEntitiesRoot;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Resource, Clone, Debug, Default, Reflect)]
|
#[derive(Resource, Clone, Debug, Default, Reflect)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct StaticEntitiesBlueprintInfo {
|
pub struct StaticEntitiesBlueprintInfo {
|
||||||
|
@ -40,9 +38,8 @@ pub struct StaticEntitiesBlueprintInfo {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct BlueprintWorld{
|
pub struct BlueprintWorld {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
impl BlueprintWorld {
|
impl BlueprintWorld {
|
||||||
|
@ -55,8 +52,6 @@ impl BlueprintWorld {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
/// Plugin for saving & loading
|
/// Plugin for saving & loading
|
||||||
pub struct SaveLoadPlugin {}
|
pub struct SaveLoadPlugin {}
|
||||||
|
@ -65,13 +60,10 @@ impl Plugin for SaveLoadPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.register_type::<Dynamic>()
|
app.register_type::<Dynamic>()
|
||||||
.register_type::<StaticEntitiesRoot>()
|
.register_type::<StaticEntitiesRoot>()
|
||||||
|
|
||||||
.add_event::<SavingRequest>()
|
.add_event::<SavingRequest>()
|
||||||
.add_event::<SaveFinished>()
|
.add_event::<SaveFinished>()
|
||||||
|
|
||||||
// common
|
// common
|
||||||
.add_systems(Update, (spawn_from_blueprintworld, )) // inject_dynamic_into_children
|
.add_systems(Update, (spawn_from_blueprintworld,)) // inject_dynamic_into_children
|
||||||
|
|
||||||
// saving
|
// saving
|
||||||
.add_systems(Update, process_save_requests)
|
.add_systems(Update, process_save_requests)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
|
@ -79,9 +71,7 @@ impl Plugin for SaveLoadPlugin {
|
||||||
(prepare_save_game, apply_deferred, save_game, cleanup_save)
|
(prepare_save_game, apply_deferred, save_game, cleanup_save)
|
||||||
.chain()
|
.chain()
|
||||||
.run_if(should_save),
|
.run_if(should_save),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
.add_event::<LoadingRequest>()
|
.add_event::<LoadingRequest>()
|
||||||
.add_event::<LoadingFinished>()
|
.add_event::<LoadingFinished>()
|
||||||
//loading
|
//loading
|
||||||
|
@ -93,7 +83,6 @@ impl Plugin for SaveLoadPlugin {
|
||||||
.run_if(should_load),
|
.run_if(should_load),
|
||||||
//.run_if(not(resource_exists::<LoadFirstStageDone>))
|
//.run_if(not(resource_exists::<LoadFirstStageDone>))
|
||||||
// .in_set(LoadingSet::Load),
|
// .in_set(LoadingSet::Load),
|
||||||
)
|
);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use bevy::{prelude::*, tasks::IoTaskPool};
|
|
||||||
use bevy::prelude::World;
|
use bevy::prelude::World;
|
||||||
|
use bevy::{prelude::*, tasks::IoTaskPool};
|
||||||
|
|
||||||
use crate::{BlenvyConfig, BlueprintInfo, Dynamic, FromBlueprint, RootEntity, SpawnBlueprint};
|
use crate::{BlenvyConfig, BlueprintInfo, Dynamic, FromBlueprint, RootEntity, SpawnBlueprint};
|
||||||
|
|
||||||
|
@ -16,17 +16,15 @@ pub struct SavingRequest {
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
pub struct SaveFinished; // TODO: merge the the events above
|
pub struct SaveFinished; // TODO: merge the the events above
|
||||||
|
|
||||||
|
|
||||||
/// resource that keeps track of the current save request
|
/// resource that keeps track of the current save request
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct SavingRequested {
|
pub struct SavingRequested {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn process_save_requests(
|
pub fn process_save_requests(
|
||||||
mut saving_requests: EventReader<SavingRequest>,
|
mut saving_requests: EventReader<SavingRequest>,
|
||||||
mut commands: Commands
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
let mut save_path: String = "".into();
|
let mut save_path: String = "".into();
|
||||||
for saving_request in saving_requests.read() {
|
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 {
|
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
|
// 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(
|
pub(crate) fn prepare_save_game(
|
||||||
saveables: Query<Entity, (With<Dynamic>, With<BlueprintInfo>)>,
|
saveables: Query<Entity, (With<Dynamic>, With<BlueprintInfo>)>,
|
||||||
|
@ -54,7 +50,8 @@ pub(crate) fn prepare_save_game(
|
||||||
|
|
||||||
mut commands: Commands,
|
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);
|
commands.entity(entity).insert(SpawnBlueprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +80,6 @@ pub(crate) fn prepare_save_game(
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub(crate) fn save_game(world: &mut World) {
|
pub(crate) fn save_game(world: &mut World) {
|
||||||
info!("saving");
|
info!("saving");
|
||||||
|
|
||||||
|
@ -125,7 +120,6 @@ pub(crate) fn save_game(world: &mut World) {
|
||||||
.allow::<BlueprintInfo>()
|
.allow::<BlueprintInfo>()
|
||||||
.allow::<SpawnBlueprint>()
|
.allow::<SpawnBlueprint>()
|
||||||
.allow::<Dynamic>()
|
.allow::<Dynamic>()
|
||||||
|
|
||||||
/*.deny::<CameraRenderGraph>()
|
/*.deny::<CameraRenderGraph>()
|
||||||
.deny::<CameraMainTextureUsages>()
|
.deny::<CameraMainTextureUsages>()
|
||||||
.deny::<Handle<Mesh>>()
|
.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
|
// for root entities, it is the same EXCEPT we make sure parents are not included
|
||||||
let filter_root = filter.clone().deny::<Parent>();
|
let filter_root = filter.clone().deny::<Parent>();
|
||||||
|
|
||||||
let filter_resources = config.clone()
|
let filter_resources = config
|
||||||
|
.clone()
|
||||||
.save_resource_filter
|
.save_resource_filter
|
||||||
.deny::<Time<Real>>()
|
.deny::<Time<Real>>()
|
||||||
.clone();
|
.clone();
|
||||||
|
@ -190,7 +185,6 @@ pub(crate) fn save_game(world: &mut World) {
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
|
|
||||||
let static_world_path = "levels/world.glb";
|
let static_world_path = "levels/world.glb";
|
||||||
let fake_foo = format!("(dynamic: {bla}, static: {static_world_path})");
|
let fake_foo = format!("(dynamic: {bla}, static: {static_world_path})");
|
||||||
let real_save_path = format!("{bla}.save.ron");
|
let real_save_path = format!("{bla}.save.ron");
|
||||||
|
@ -217,5 +211,4 @@ pub(crate) fn cleanup_save(
|
||||||
saving_finished.send(SaveFinished);
|
saving_finished.send(SaveFinished);
|
||||||
|
|
||||||
commands.remove_resource::<SavingRequested>();
|
commands.remove_resource::<SavingRequested>();
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,9 +2,8 @@ use std::time::Duration;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use blenvy::{
|
use blenvy::{
|
||||||
BlenvyPlugin, BlueprintAnimationPlayerLink,
|
BlenvyPlugin, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintInfo, GameWorldTag,
|
||||||
BlueprintAnimations, BlueprintInfo, GameWorldTag, HideUntilReady,
|
HideUntilReady, SpawnBlueprint,
|
||||||
SpawnBlueprint,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mod component_examples;
|
mod component_examples;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use blenvy::{
|
use blenvy::{
|
||||||
AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag, HideUntilReady, SpawnBlueprint
|
AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag,
|
||||||
|
HideUntilReady, SpawnBlueprint,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
@ -32,12 +33,8 @@ fn setup_game(mut commands: Commands) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// you can also spawn blueprint instances at runtime
|
// you can also spawn blueprint instances at runtime
|
||||||
pub fn spawn_blueprint_instance(
|
pub fn spawn_blueprint_instance(keycode: Res<ButtonInput<KeyCode>>, mut commands: Commands) {
|
||||||
keycode: Res<ButtonInput<KeyCode>>,
|
|
||||||
mut commands: Commands,
|
|
||||||
) {
|
|
||||||
if keycode.just_pressed(KeyCode::KeyS) {
|
if keycode.just_pressed(KeyCode::KeyS) {
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let range = 5.5;
|
let range = 5.5;
|
||||||
let x: f32 = rng.gen_range(-range..range);
|
let x: f32 = rng.gen_range(-range..range);
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
|
|
||||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
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;
|
use rand::Rng;
|
||||||
|
|
||||||
// mod game;
|
// mod game;
|
||||||
// use game::*;
|
// use game::*;
|
||||||
|
|
||||||
mod component_examples;
|
mod component_examples;
|
||||||
use component_examples::*;
|
|
||||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||||
|
use component_examples::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -39,19 +42,16 @@ fn main() {
|
||||||
// GamePlugin, // specific to our game
|
// GamePlugin, // specific to our game
|
||||||
ComponentsExamplesPlugin, // Showcases different type of components /structs
|
ComponentsExamplesPlugin, // Showcases different type of components /structs
|
||||||
))
|
))
|
||||||
|
|
||||||
.add_systems(Startup, setup_game)
|
.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();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is how you setup & spawn a level from a blueprint
|
// this is how you setup & spawn a level from a blueprint
|
||||||
fn setup_game(
|
fn setup_game(mut commands: Commands) {
|
||||||
mut commands: Commands,
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
|
||||||
// would be nice: contains both static & dynamic stuff
|
// would be nice: contains both static & dynamic stuff
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
BlueprintWorld::from_path("levels/World.glb"), // will take care of loading both static & dynamic data
|
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
|
// you can also spawn blueprint instances at runtime
|
||||||
fn spawn_blueprint_instance(
|
fn spawn_blueprint_instance(keycode: Res<ButtonInput<KeyCode>>, mut commands: Commands) {
|
||||||
keycode: Res<ButtonInput<KeyCode>>,
|
|
||||||
mut commands: Commands,
|
|
||||||
) {
|
|
||||||
if keycode.just_pressed(KeyCode::KeyT) {
|
if keycode.just_pressed(KeyCode::KeyT) {
|
||||||
// random position
|
// random position
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
@ -73,8 +70,7 @@ fn spawn_blueprint_instance(
|
||||||
// random name
|
// random name
|
||||||
let name_index: u64 = rng.gen();
|
let name_index: u64 = rng.gen();
|
||||||
|
|
||||||
commands
|
commands.spawn((
|
||||||
.spawn((
|
|
||||||
BlueprintInfo::from_path("blueprints/test.glb"),
|
BlueprintInfo::from_path("blueprints/test.glb"),
|
||||||
SpawnBlueprint,
|
SpawnBlueprint,
|
||||||
Dynamic,
|
Dynamic,
|
||||||
|
@ -86,19 +82,14 @@ fn spawn_blueprint_instance(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_movers(
|
fn move_movers(mut movers: Query<(&mut Transform), With<Dynamic>>) {
|
||||||
mut movers: Query<(&mut Transform), With<Dynamic>>
|
for mut transform in movers.iter_mut() {
|
||||||
) {
|
|
||||||
for mut transform in movers.iter_mut(){
|
|
||||||
// println!("moving dynamic entity");
|
// println!("moving dynamic entity");
|
||||||
transform.translation.x += 0.005;
|
transform.translation.x += 0.005;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_game(
|
fn save_game(keycode: Res<ButtonInput<KeyCode>>, mut save_requests: EventWriter<SavingRequest>) {
|
||||||
keycode: Res<ButtonInput<KeyCode>>,
|
|
||||||
mut save_requests: EventWriter<SavingRequest>,
|
|
||||||
) {
|
|
||||||
if keycode.just_pressed(KeyCode::KeyS) {
|
if keycode.just_pressed(KeyCode::KeyS) {
|
||||||
save_requests.send(SavingRequest {
|
save_requests.send(SavingRequest {
|
||||||
path: "scenes/save.scn.ron".into(),
|
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) {
|
if keycode.just_pressed(KeyCode::KeyL) {
|
||||||
load_requests.send(LoadingRequest {
|
load_requests.send(LoadingRequest {
|
||||||
path: "scenes/save.scn.ron".into(),
|
path: "scenes/save.scn.ron".into(),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{GameState, InAppRunning};
|
use crate::{GameState, InAppRunning};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use blenvy::{
|
use blenvy::{
|
||||||
AddToGameWorld, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag,
|
AddToGameWorld, BluePrintBundle, BlueprintInfo, Dynamic, GameWorldTag, HideUntilReady,
|
||||||
HideUntilReady, SpawnBlueprint,
|
SpawnBlueprint,
|
||||||
};
|
};
|
||||||
|
|
||||||
//use bevy_rapier3d::prelude::Velocity;
|
//use bevy_rapier3d::prelude::Velocity;
|
||||||
|
|
Loading…
Reference in New Issue