Disable last selected note to avoid crash when no notes selected

main
Elijah Voigt 1 week ago
parent 7054bdd469
commit d0703fcedf

@ -86,6 +86,7 @@ fn main() {
update_material, update_material,
update_debug_info_cell_count, update_debug_info_cell_count,
update_debug_info_coordinates, update_debug_info_coordinates,
update_note_interactivity,
), ),
) )
.add_systems(Update, cell_lifecycle.run_if(on_message::<Lifecycle>)) .add_systems(Update, cell_lifecycle.run_if(on_message::<Lifecycle>))
@ -311,7 +312,7 @@ fn primary_ui() -> impl Scene {
// TODO: if last selected note and de-selected, undo that move please // TODO: if last selected note and de-selected, undo that move please
let this_note = notes.get(change.source).unwrap(); let this_note = notes.get(change.source).unwrap();
pitch_map.set_note(this_note, change.value); 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<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| { on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| {
if value_change.is_final { if value_change.is_final {
pitch_map.octaves_up = value_change.value as usize; 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), on(slider_self_update),
@ -507,7 +508,7 @@ fn primary_ui() -> impl Scene {
on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| { on(|value_change: On<ValueChange<f32>>, mut pitch_map: ResMut<PitchMap>| {
if value_change.is_final { if value_change.is_final {
pitch_map.octaves_down = value_change.value as usize; 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), 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) /// 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<PitchMap>) { fn reassign_cell_pitch(mut query: Query<(&mut CellPitch, &Coordinates)>, pitch_map: Res<PitchMap>) {
info!("query size: {:?}", query.iter().len()); debug!("query size: {:?}", query.iter().len());
query.iter_mut().for_each(|(mut cell_pitch, c)| { query.iter_mut().for_each(|(mut cell_pitch, c)| {
*cell_pitch = pitch_map.coordinates_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)); *t = Text::new(format!("{},{}", coordinates.0.x, coordinates.0.y));
}); });
} }
fn update_note_interactivity(
checked: Query<Entity, (With<Note>, With<Checkbox>, With<Checked>)>,
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::<InteractionDisabled>();
});
}
}

Loading…
Cancel
Save