From 43228630401fbd0743eb58032fcd70a6606650e3 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Mon, 13 Jul 2026 21:11:32 -0700 Subject: [PATCH] wipe board and reset board both implemented --- life/assets/return.png | Bin 0 -> 392 bytes life/assets/trashcan.png | Bin 0 -> 198 bytes life/assets/trashcanOpen.png | Bin 0 -> 316 bytes life/src/main.rs | 80 ++++++++++++++++++++++++++--------- 4 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 life/assets/return.png create mode 100644 life/assets/trashcan.png create mode 100644 life/assets/trashcanOpen.png diff --git a/life/assets/return.png b/life/assets/return.png new file mode 100644 index 0000000000000000000000000000000000000000..15f9625a5054278c00809bb4c7de0ac932461769 GIT binary patch literal 392 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=3?wxlRx|@CmUKs7M+SzC{oH>NS%G}x0G|+7 zAWbS*%<6U$s7IhA$S=5meZ2qqe0~0UdHebA@9$@j$vyQKDEGwE#WBR=_}i(sg<2Fi z+KSIQ%XNIOzjgQ6m8gp^veL_by)XK~Aea%ApItS9{iom}-I^zBA1m=~IFZel#4M+J zMl>nyPtX-xm&7R|jS|!NHZ5h2QdpRg!NNZ4o$`(X0S3m6*M3QTJh?XaaEagzU#`XL zgt?98KD*OU{5O2l2|WuBqoSXao6l?)oE;alX=2RAtMik-P1N|jFej?brD@gSFt_8q z0`qT&S;s%-lTs5a-&d=`)!C=lzF_wK3?$zOPHh5GEa{HEjtmSN`?>!lvI6;{0X`wF zKpGPWF)}Oxin5gi`33KVbRj*>wqF&o-U3d7N?UrjNS%G}x0G|+7 zAWbS*%<6U$s7IhA$S=6xfB*dZ=kxW~%k$gEzprPwF7A5=C^y5?#WBR=_}goDxehDv zuqH%D|DUwu^FM#G<($5q%!*#=9*-Cj-l^HGzj0_{vqRBj zfskoxCub>`dHhnXad{DYJUwS_g`=VOT%Q#xVV&A}iI%c5KKj!iBrTpAzxB*at6lQn zp01u5bU$KWm*DA*^^ play/pause sim +// * m -> un/mute audio #![allow(clippy::complexity)] // Only because of FromTemplat macros unfortunately... #![allow(dead_code)] use bevy::{ - feathers::{containers::*, theme::ThemeProps}, ui::{Checked, InteractionDisabled}, ui_widgets::{ - ActivateOnPress, Checkbox, SliderPrecision, SliderStep, ValueChange, checkbox_self_update, slider_self_update - } + feathers::{containers::*, theme::ThemeProps}, + ui::{Checked, InteractionDisabled}, + ui_widgets::{ + ActivateOnPress, Checkbox, SliderPrecision, SliderStep, ValueChange, checkbox_self_update, + slider_self_update, + }, }; use engine::*; @@ -33,6 +35,7 @@ fn main() { .init_resource::() .init_resource::() .init_resource::() + .init_resource::() .insert_resource(ClearColor(WHITE.into())) .insert_resource(UiTheme(create_light_theme())) .init_state::() @@ -107,6 +110,8 @@ enum UiButton { AddLowOctave, SubLowOctave, Note, + Reset, + Wipe, #[default] None, } @@ -127,6 +132,8 @@ impl UiButton { Self::AddLowOctave => "todo.png", Self::SubLowOctave => "todo.png", Self::Note => "todo.png", + Self::Reset => "return.png", + Self::Wipe => "trashcan.png", Self::None => todo!(), } } @@ -246,7 +253,13 @@ fn the_ui() -> impl Scene { }), ui_button(UiButton::Play) SimulationPlayback::Run - on(|_: On, mut next: ResMut>| { + on(| + _: On, + mut next: ResMut>, + mut last_board_state: ResMut, + coordinates: Query<&Coordinates, With> + | { + last_board_state.coordinates = coordinates.iter().cloned().collect(); // Set simulation state next.set(SimulationPlayback::Run); }), @@ -254,6 +267,28 @@ fn the_ui() -> impl Scene { on(|_: On, mut next: ResMut>| { next.set(SimulationPlayback::Step); }), + ui_button(UiButton::Reset) + on(| + _: On, + last_board_state: Res, + mut lifecycle: MessageWriter, + cells: Query>, + mut commands: Commands, + | { + // Todo: reconcile board instead of despawn/spawning the world + cells.iter().for_each(|e| { + commands.entity(e).despawn(); + }); + last_board_state.coordinates.iter().for_each(|c| { + lifecycle.write(Lifecycle::Alive(c.clone())); + }); + }), + ui_button(UiButton::Wipe) + on(|_: On, cells: Query>, mut commands: Commands| { + cells.iter().for_each(|e| { + commands.entity(e).despawn(); + }); + }), ui_button(UiButton::ZoomOut) on(|_: On, mut projection: Query<&mut Projection>| { projection.iter_mut().for_each(|mut p| match *p { @@ -376,6 +411,11 @@ fn the_ui() -> impl Scene { #[derive(Default, Debug, Resource)] struct NextCoordinates(Coordinates); +#[derive(Default, Debug, Resource)] +struct LastBoardState { + coordinates: Vec, +} + #[derive(Debug, Default, Clone, PartialEq, Hash, Eq, Component, FromTemplate)] #[require(Visibility, Transform)] struct Coordinates { @@ -626,7 +666,10 @@ fn new_cell( let cell_pitch = pitch_map.coordinates_cell_pitch(&c); #[derive(Clone, Default, Component)] - enum Foo { #[default]A } + enum Foo { + #[default] + A, + } bsn! { Cell @@ -800,12 +843,12 @@ impl CellPitch { Note::FSharp, Note::G, Note::GSharp, - ].into_iter().flat_map(|note| { - (-5..6).map(move |octave| { - CellPitch { - note: note.clone(), - octave, - } + ] + .into_iter() + .flat_map(|note| { + (-5..6).map(move |octave| CellPitch { + note: note.clone(), + octave, }) }) } @@ -998,7 +1041,7 @@ impl PitchMap { }; let octave: isize = { let num_octaves: usize = self.octaves_up + self.octaves_down + 1; - let y_coord: usize = c.y.strict_abs() as usize; // TODO: shift first or something + let y_coord: usize = c.y.strict_abs() as usize; // TODO: shift first or something debug!("num_octaves: {:?}", num_octaves); debug!("y_coord: {:?}", y_coord); (y_coord % num_octaves) as isize - 5 @@ -1010,10 +1053,7 @@ 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, -) { +fn reassign_cell_pitch(mut query: Query<(&mut CellPitch, &Coordinates)>, pitch_map: Res) { info!("query size: {:?}", query.iter().len()); query.iter_mut().for_each(|(mut cell_pitch, c)| { *cell_pitch = pitch_map.coordinates_cell_pitch(c);