mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-19 07:53:25 +00:00
sync selection between editor and storyteller
This commit is contained in:
+6
-1
@@ -318,8 +318,13 @@ fn read_mouse_delta(
|
||||
|
||||
// TODO: Make it configurable
|
||||
fn send_undo_event(mut events: EventWriter<UndoRedo>, keyboard: Res<Input<KeyCode>>) {
|
||||
if keyboard.pressed(KeyCode::ControlLeft) && keyboard.just_pressed(KeyCode::Z) {
|
||||
if keyboard.pressed(KeyCode::ControlLeft) && keyboard.just_pressed(KeyCode::Z) && !keyboard.pressed(KeyCode::ShiftLeft) {
|
||||
events.send(UndoRedo::Undo);
|
||||
info!("Undo event sent");
|
||||
}
|
||||
|
||||
if keyboard.pressed(KeyCode::ControlLeft) && keyboard.just_pressed(KeyCode::Z) && keyboard.pressed(KeyCode::ShiftLeft) {
|
||||
events.send(UndoRedo::Redo);
|
||||
info!("Redo event sent");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ impl Plugin for SelectionPlugin {
|
||||
.map(bevy::utils::error)
|
||||
.run_if(resource_changed_or_removed::<Selection>()),
|
||||
);
|
||||
|
||||
app.add_systems(
|
||||
Update,
|
||||
sync_editor_selected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +49,30 @@ 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>)>,
|
||||
|
||||
Reference in New Issue
Block a user