wipe board and reset board both implemented

main
Elijah Voigt 1 week ago
parent db4eb74a45
commit 4322863040

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

@ -2,20 +2,22 @@
// * Debug Panel // * Debug Panel
// * Describe cell I am hovering over (Note, Octave, etc) // * Describe cell I am hovering over (Note, Octave, etc)
// * Count # of cells on the board // * Count # of cells on the board
// * Save board state when playing
// * Restore board state from before playing
// * Wipe board
// * Fix tiling repeating // * Fix tiling repeating
// * Negative coordinates should not mirror // * Negative coordinates should not mirror
// // * Fix randomly audio not working
// * space -> play/pause sim
// * m -> un/mute audio
#![allow(clippy::complexity)] #![allow(clippy::complexity)]
// Only because of FromTemplat macros unfortunately... // Only because of FromTemplat macros unfortunately...
#![allow(dead_code)] #![allow(dead_code)]
use bevy::{ use bevy::{
feathers::{containers::*, theme::ThemeProps}, ui::{Checked, InteractionDisabled}, ui_widgets::{ feathers::{containers::*, theme::ThemeProps},
ActivateOnPress, Checkbox, SliderPrecision, SliderStep, ValueChange, checkbox_self_update, slider_self_update ui::{Checked, InteractionDisabled},
} ui_widgets::{
ActivateOnPress, Checkbox, SliderPrecision, SliderStep, ValueChange, checkbox_self_update,
slider_self_update,
},
}; };
use engine::*; use engine::*;
@ -33,6 +35,7 @@ fn main() {
.init_resource::<CellAssets>() .init_resource::<CellAssets>()
.init_resource::<Panning>() .init_resource::<Panning>()
.init_resource::<PitchMap>() .init_resource::<PitchMap>()
.init_resource::<LastBoardState>()
.insert_resource(ClearColor(WHITE.into())) .insert_resource(ClearColor(WHITE.into()))
.insert_resource(UiTheme(create_light_theme())) .insert_resource(UiTheme(create_light_theme()))
.init_state::<SimulationPlayback>() .init_state::<SimulationPlayback>()
@ -107,6 +110,8 @@ enum UiButton {
AddLowOctave, AddLowOctave,
SubLowOctave, SubLowOctave,
Note, Note,
Reset,
Wipe,
#[default] #[default]
None, None,
} }
@ -127,6 +132,8 @@ impl UiButton {
Self::AddLowOctave => "todo.png", Self::AddLowOctave => "todo.png",
Self::SubLowOctave => "todo.png", Self::SubLowOctave => "todo.png",
Self::Note => "todo.png", Self::Note => "todo.png",
Self::Reset => "return.png",
Self::Wipe => "trashcan.png",
Self::None => todo!(), Self::None => todo!(),
} }
} }
@ -246,7 +253,13 @@ fn the_ui() -> impl Scene {
}), }),
ui_button(UiButton::Play) ui_button(UiButton::Play)
SimulationPlayback::Run SimulationPlayback::Run
on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| { on(|
_: On<Activate>,
mut next: ResMut<NextState<SimulationPlayback>>,
mut last_board_state: ResMut<LastBoardState>,
coordinates: Query<&Coordinates, With<Cell>>
| {
last_board_state.coordinates = coordinates.iter().cloned().collect();
// Set simulation state // Set simulation state
next.set(SimulationPlayback::Run); next.set(SimulationPlayback::Run);
}), }),
@ -254,6 +267,28 @@ fn the_ui() -> impl Scene {
on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| { on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| {
next.set(SimulationPlayback::Step); next.set(SimulationPlayback::Step);
}), }),
ui_button(UiButton::Reset)
on(|
_: On<Activate>,
last_board_state: Res<LastBoardState>,
mut lifecycle: MessageWriter<Lifecycle>,
cells: Query<Entity, With<Cell>>,
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<Activate>, cells: Query<Entity, With<Cell>>, mut commands: Commands| {
cells.iter().for_each(|e| {
commands.entity(e).despawn();
});
}),
ui_button(UiButton::ZoomOut) ui_button(UiButton::ZoomOut)
on(|_: On<Activate>, mut projection: Query<&mut Projection>| { on(|_: On<Activate>, mut projection: Query<&mut Projection>| {
projection.iter_mut().for_each(|mut p| match *p { projection.iter_mut().for_each(|mut p| match *p {
@ -376,6 +411,11 @@ fn the_ui() -> impl Scene {
#[derive(Default, Debug, Resource)] #[derive(Default, Debug, Resource)]
struct NextCoordinates(Coordinates); struct NextCoordinates(Coordinates);
#[derive(Default, Debug, Resource)]
struct LastBoardState {
coordinates: Vec<Coordinates>,
}
#[derive(Debug, Default, Clone, PartialEq, Hash, Eq, Component, FromTemplate)] #[derive(Debug, Default, Clone, PartialEq, Hash, Eq, Component, FromTemplate)]
#[require(Visibility, Transform)] #[require(Visibility, Transform)]
struct Coordinates { struct Coordinates {
@ -626,7 +666,10 @@ fn new_cell(
let cell_pitch = pitch_map.coordinates_cell_pitch(&c); let cell_pitch = pitch_map.coordinates_cell_pitch(&c);
#[derive(Clone, Default, Component)] #[derive(Clone, Default, Component)]
enum Foo { #[default]A } enum Foo {
#[default]
A,
}
bsn! { bsn! {
Cell Cell
@ -800,12 +843,12 @@ impl CellPitch {
Note::FSharp, Note::FSharp,
Note::G, Note::G,
Note::GSharp, Note::GSharp,
].into_iter().flat_map(|note| { ]
(-5..6).map(move |octave| { .into_iter()
CellPitch { .flat_map(|note| {
note: note.clone(), (-5..6).map(move |octave| CellPitch {
octave, note: note.clone(),
} octave,
}) })
}) })
} }
@ -998,7 +1041,7 @@ impl PitchMap {
}; };
let octave: isize = { let octave: isize = {
let num_octaves: usize = self.octaves_up + self.octaves_down + 1; 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!("num_octaves: {:?}", num_octaves);
debug!("y_coord: {:?}", y_coord); debug!("y_coord: {:?}", y_coord);
(y_coord % num_octaves) as isize - 5 (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) /// When the pitch map changes, update all cells to use the correct pitch (note + octave)
fn reassign_cell_pitch( fn reassign_cell_pitch(mut query: Query<(&mut CellPitch, &Coordinates)>, pitch_map: Res<PitchMap>) {
mut query: Query<(&mut CellPitch, &Coordinates)>,
pitch_map: Res<PitchMap>,
) {
info!("query size: {:?}", query.iter().len()); info!("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);

Loading…
Cancel
Save