From 139e75786b69bbb246a687c9e743955cdc22b780 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Fri, 26 Aug 2022 15:57:32 +0200 Subject: [PATCH] editor: delete --- README.md | 1 + src/editor.rs | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c452b76..1bee3c3 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Edit the level `N: u32` with the command `bevyjam e`. * **Select**: left click to select, click in void to deselect, CTRL+click to select many, CTRL+A to select all * **Move selection**: arrows to move one step, Shift+arrows to move continuously +* **Delete selection**: delete * **Move camera**: CTRL+arrows * **Save**: CTRL+S diff --git a/src/editor.rs b/src/editor.rs index 55c1592..8474c1d 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -22,7 +22,8 @@ impl Plugin for EditorPlugin { SystemSet::on_update(AppState::Editor) .with_system(move_system) .with_system(input_control_system) - .with_system(follow_ends_system), + .with_system(follow_ends_system) + .with_system(remove_system), ); } } @@ -61,6 +62,9 @@ struct RotatingFilterAngle(f32); #[derive(Component)] struct AbsorbingFilterColor(Color); +#[derive(Component)] +struct Removable; + // Bundles #[derive(Bundle)] @@ -69,6 +73,9 @@ struct PlatformBundle { mesh: ColorMesh2dBundle, size: Size, platform: Platform, + #[bundle] + pickable: PickableBundle, + removable: Removable, } #[derive(Bundle)] @@ -89,6 +96,7 @@ struct CharacterBundle { #[bundle] pickable: PickableBundle, draggable: Draggable, + removable: Removable, } #[derive(Bundle)] @@ -97,6 +105,9 @@ struct AbsorbingFilterBundle { mesh: ColorMesh2dBundle, size: Size, color: AbsorbingFilterColor, + #[bundle] + pickable: PickableBundle, + removable: Removable, } #[derive(Bundle)] @@ -107,6 +118,7 @@ struct RotatingFilterBundle { #[bundle] pickable: PickableBundle, draggable: Draggable, + removable: Removable, } // Functions @@ -129,6 +141,8 @@ fn spawn_platform( }, size: Size(size), platform: Platform, + pickable: PickableBundle::default(), + removable: Removable, }) .id(); let ends = Ends( @@ -207,6 +221,7 @@ fn spawn_character( color: CharacterColor(color), pickable: PickableBundle::default(), draggable: Draggable, + removable: Removable, }) .with_children(|c| { c.spawn_bundle(Text2dBundle { @@ -245,6 +260,8 @@ fn spawn_absorbing_filter( }, size: Size(size), color: AbsorbingFilterColor(color), + pickable: PickableBundle::default(), + removable: Removable, }) .id(); let ends = Ends( @@ -322,6 +339,7 @@ fn spawn_rotating_filter( angle: RotatingFilterAngle(angle), pickable: PickableBundle::default(), draggable: Draggable, + removable: Removable, }) .with_children(|c| { c.spawn_bundle(Text2dBundle { @@ -584,6 +602,24 @@ fn move_system( } } +fn remove_system( + mut commands: Commands, + keyboard_input: Res>, + mut removable_query: Query<(Entity, &Selection, Option<&Ends>), With>, +) { + if keyboard_input.just_released(KeyCode::Delete) { + for (entity, selection, ends) in removable_query.iter_mut() { + if selection.selected() { + commands.entity(entity).despawn_recursive(); + if let Some(ends) = ends { + commands.entity(ends.0).despawn_recursive(); + commands.entity(ends.1).despawn_recursive(); + } + } + } + } +} + fn follow_ends_system( mut meshes: ResMut>, mut follower_query: Query<(&mut Transform, &mut Mesh2dHandle, &mut Size, &Ends)>,