From d0703fcedf05a95e850b3e9f30fa2ec15349a723 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 14 Jul 2026 15:25:47 -0700 Subject: [PATCH] Disable last selected note to avoid crash when no notes selected --- life/src/main.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/life/src/main.rs b/life/src/main.rs index 9c65054..5976035 100644 --- a/life/src/main.rs +++ b/life/src/main.rs @@ -86,6 +86,7 @@ fn main() { update_material, update_debug_info_cell_count, update_debug_info_coordinates, + update_note_interactivity, ), ) .add_systems(Update, cell_lifecycle.run_if(on_message::)) @@ -311,7 +312,7 @@ fn primary_ui() -> impl Scene { // TODO: if last selected note and de-selected, undo that move please let this_note = notes.get(change.source).unwrap(); pitch_map.set_note(this_note, change.value); - info!("(note {:?}) Updated pitch map: {:#?}", this_note, pitch_map); + debug!("(note {:?}) Updated pitch map: {:#?}", this_note, pitch_map); } } @@ -497,7 +498,7 @@ fn primary_ui() -> impl Scene { on(|value_change: On>, mut pitch_map: ResMut| { if value_change.is_final { pitch_map.octaves_up = value_change.value as usize; - info!("(octave up) Updated pitch map: {:#?}", pitch_map); + debug!("(octave up) Updated pitch map: {:#?}", pitch_map); } }) on(slider_self_update), @@ -507,7 +508,7 @@ fn primary_ui() -> impl Scene { on(|value_change: On>, mut pitch_map: ResMut| { if value_change.is_final { pitch_map.octaves_down = value_change.value as usize; - info!("(octave down) Updated pitch map: {:#?}", pitch_map); + debug!("(octave down) Updated pitch map: {:#?}", pitch_map); } }) on(slider_self_update), @@ -1163,10 +1164,10 @@ impl PitchMap { /// When the pitch map changes, update all cells to use the correct pitch (note + octave) fn reassign_cell_pitch(mut query: Query<(&mut CellPitch, &Coordinates)>, pitch_map: Res) { - info!("query size: {:?}", query.iter().len()); + debug!("query size: {:?}", query.iter().len()); query.iter_mut().for_each(|(mut cell_pitch, c)| { *cell_pitch = pitch_map.coordinates_cell_pitch(c); - info!("Updating cell pitch for {:?}", c); + debug!("Updating cell pitch for {:?}", c); }); } @@ -1212,3 +1213,18 @@ fn update_debug_info_coordinates( *t = Text::new(format!("{},{}", coordinates.0.x, coordinates.0.y)); }); } + +fn update_note_interactivity( + checked: Query, With, With)>, + mut commands: Commands, +) { + if checked.iter().len() == 1 { + checked.iter().for_each(|e| { + commands.entity(e).insert(InteractionDisabled); + }); + } else { + checked.iter().for_each(|e| { + commands.entity(e).remove::(); + }); + } +}