Scene in memory persistance and debug tools (#24)

![image](https://github.com/storytold/storyteller-bevy/assets/10954133/10eb5c33-2154-4e9d-95ce-1d8e8b822d22)
Debug tools example

---------

Co-authored-by: Danny McGee <dannymcgee@gmail.com>
This commit is contained in:
rewin
2024-02-02 22:51:18 +03:00
committed by GitHub
parent 2df86eaf58
commit 8f0b916eaa
15 changed files with 415 additions and 388 deletions
+32
View File
@@ -25,6 +25,8 @@ impl Plugin for SelectionPlugin {
.after(SceneSpawnerSystem),
);
app.add_systems(Update, tag_scene_elements);
#[cfg(feature = "wasm")]
app.add_systems(
Update,
@@ -36,6 +38,8 @@ impl Plugin for SelectionPlugin {
.map(bevy::utils::error)
.run_if(resource_changed_or_removed::<Selection>()),
);
app.add_systems(Update, sync_editor_selected);
}
}
@@ -48,6 +52,34 @@ pub struct Selected;
#[derive(Resource, Deref, DerefMut, Debug)]
pub struct Selection(Entity);
fn sync_editor_selected(
mut cmd: Commands,
q_new_selected: Query<Entity, (Added<Selected>, Without<space_editor::prelude::Selected>)>,
q_editor_selected: Query<Entity, With<space_editor::prelude::Selected>>,
q_selected: Query<Entity, With<Selected>>,
q_added_editor_selected: Query<
Entity,
(Without<Selected>, Added<space_editor::prelude::Selected>),
>,
) {
for ent in q_new_selected.iter() {
for ed_ent in q_editor_selected.iter() {
cmd.entity(ed_ent)
.remove::<space_editor::prelude::Selected>();
}
cmd.entity(ent).insert(space_editor::prelude::Selected);
}
for ent in q_added_editor_selected.iter() {
cmd.entity(ent).insert(Selected);
cmd.insert_resource(Selection(ent));
for ent in q_selected.iter() {
cmd.entity(ent).remove::<Selected>();
}
}
}
fn tag_scene_elements(
mut cmd: Commands,
q_scene_elements: Query<(Entity, &Children), (With<SceneElement>, Without<Selectable>)>,