Skip to content

Commit

Permalink
update for mandatory component derive
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Dec 30, 2021
1 parent bdc1713 commit 2108357
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
27 changes: 19 additions & 8 deletions crates/bevy_scene/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
use bevy_asset::Handle;
use bevy_ecs::{
bundle::Bundle, change_detection::ResMut, entity::Entity, prelude::Changed, system::Query,
bundle::Bundle,
change_detection::ResMut,
entity::Entity,
prelude::{Changed, Component},
system::Query,
};
use bevy_transform::components::{GlobalTransform, Transform};

use crate::{DynamicScene, InstanceId, Scene, SceneSpawner};

#[derive(Default, Component)]
pub struct HasSceneInstance(Option<InstanceId>);

#[derive(Default, Bundle)]
pub struct SceneBundle {
pub scene: Handle<Scene>,
pub instance_id: Option<InstanceId>,
pub instance_id: HasSceneInstance,
pub transform: Transform,
pub global_transform: GlobalTransform,
}

#[allow(clippy::type_complexity)]
pub fn scene_bundle_spawner(
mut scene_to_spawn: Query<
(Entity, &Handle<Scene>, &mut Option<InstanceId>),
(Entity, &Handle<Scene>, &mut HasSceneInstance),
Changed<Handle<Scene>>,
>,
mut scene_spawner: ResMut<SceneSpawner>,
) {
for (entity, scene, mut instance) in scene_to_spawn.iter_mut() {
if let Some(id) = instance.replace(scene_spawner.spawn_as_child(scene.clone(), entity)) {
if let Some(id) = instance
.0
.replace(scene_spawner.spawn_as_child(scene.clone(), entity))
{
scene_spawner.despawn_instance(id);
}
}
Expand All @@ -32,22 +42,23 @@ pub fn scene_bundle_spawner(
#[derive(Default, Bundle)]
pub struct DynamicSceneBundle {
pub scene: Handle<DynamicScene>,
pub instance_id: Option<InstanceId>,
pub instance_id: HasSceneInstance,
pub transform: Transform,
pub global_transform: GlobalTransform,
}

#[allow(clippy::type_complexity)]
pub fn dynamic_scene_bundle_spawner(
mut dynamic_scene_to_spawn: Query<
(Entity, &Handle<DynamicScene>, &mut Option<InstanceId>),
(Entity, &Handle<DynamicScene>, &mut HasSceneInstance),
Changed<Handle<DynamicScene>>,
>,
mut scene_spawner: ResMut<SceneSpawner>,
) {
for (entity, dynamic_scene, mut instance) in dynamic_scene_to_spawn.iter_mut() {
if let Some(id) =
instance.replace(scene_spawner.spawn_dynamic_as_child(dynamic_scene.clone(), entity))
if let Some(id) = instance
.0
.replace(scene_spawner.spawn_dynamic_as_child(dynamic_scene.clone(), entity))
{
scene_spawner.despawn_instance(id);
}
Expand Down
1 change: 0 additions & 1 deletion examples/game/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ fn spawn_bonus(
transform: Transform::from_xyz(0.0, 2.0, 0.0),
..Default::default()
});
children.spawn_scene(game.bonus.handle.clone());
})
.id(),
);
Expand Down

0 comments on commit 2108357

Please sign in to comment.