diff --git a/engine/Cargo.toml b/engine/Cargo.toml index c610d6e..709552f 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -bevy = "0.18.1" +bevy = "0.19.0" [features] dev = ["bevy/dynamic_linking", "bevy/file_watcher", "bevy/debug", "bevy/bevy_light", "bevy/free_camera"] diff --git a/engine/src/lib.rs b/engine/src/lib.rs index 046bb24..07288e1 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -1,4 +1,13 @@ +pub use std::time::Duration; + pub use bevy::{ - color::palettes::basic::*, input::common_conditions::*, platform::collections::HashSet, + audio::Volume, + color::palettes::basic::*, + input::{ + common_conditions::*, + mouse::{AccumulatedMouseMotion, MouseMotion}, + }, + picking::hover::Hovered, + platform::collections::{HashMap, HashSet}, prelude::*, }; diff --git a/life/Cargo.lock b/life/Cargo.lock index f65aad5..40618cc 100644 --- a/life/Cargo.lock +++ b/life/Cargo.lock @@ -124,9 +124,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "alsa" -version = "0.11.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812947049edcd670a82cd5c73c3661d2e58468577ba8489de58e1a73c04cbd5d" +checksum = "7c88dbbce13b232b26250e1e2e6ac18b6a891a646b8148285036ebce260ac5c3" dependencies = [ "alsa-sys", "bitflags 2.13.0", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "alsa-sys" -version = "0.4.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad7569085a265dd3f607ebecce7458eaab2132a84393534c95b18dcbc3f31e04" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" dependencies = [ "libc", "pkg-config", @@ -2122,11 +2122,11 @@ dependencies = [ [[package]] name = "coreaudio-rs" -version = "0.14.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5d7dca3ebcf65a035582c9ad4385371a9d9ee6537474d2a278f4e1e475bb58" +checksum = "1aae284fbaf7d27aa0e292f7677dfbe26503b0d555026f702940805a630eac17" dependencies = [ - "bitflags 2.13.0", + "bitflags 1.3.2", "libc", "objc2-audio-toolbox", "objc2-core-audio", @@ -2136,9 +2136,9 @@ dependencies = [ [[package]] name = "cpal" -version = "0.17.3" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8942da362c0f0d895d7cac616263f2f9424edc5687364dfd1d25ef7eba506d7" +checksum = "5b1f9c7312f19fc2fa12fd7acaf38de54e8320ba10d1a02dcbe21038def51ccb" dependencies = [ "alsa", "coreaudio-rs", diff --git a/life/src/main.rs b/life/src/main.rs index 17d7bb9..0c97aea 100644 --- a/life/src/main.rs +++ b/life/src/main.rs @@ -1,13 +1,3 @@ -// TODO: Rearchitected so it's Cell and Coordiantes not Cell { position { coordiantes } } - -use std::time::Duration; - -use bevy::{ - audio::Volume, - input::mouse::{AccumulatedMouseMotion, MouseMotion}, - picking::hover::Hovered, - platform::collections::HashMap, -}; use engine::*; const TILE: &str = "tileGrey_01.png"; @@ -22,10 +12,12 @@ fn main() { .init_resource::() .init_resource::() .init_resource::() + .insert_resource(ClearColor(WHITE.into())) .init_state::() .init_state::() .add_message::() - .add_systems(Startup, setup) + .add_systems(Startup, the_camera.spawn()) + .add_systems(Startup, the_ui.spawn()) .add_systems(Startup, load_audio_tones) .add_systems(Startup, load_materials) .add_systems(Startup, load_meshes) @@ -87,14 +79,14 @@ fn main() { const SCALE: f32 = 100.0; -#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component)] +#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)] enum AudioPlayback { #[default] Mute, Play, } -#[derive(Debug, Component, PartialEq)] +#[derive(Debug, Component, PartialEq, Default, FromTemplate)] #[require(Visibility, Transform)] enum UiButton { Power, @@ -105,6 +97,8 @@ enum UiButton { ZoomIn, PlayAudio, MuteAudio, + #[default] + None, } impl UiButton { @@ -118,6 +112,7 @@ impl UiButton { Self::ZoomIn => "zoomIn.png", Self::PlayAudio => "audioOn.png", Self::MuteAudio => "audioOff.png", + Self::None => todo!(), } } } @@ -169,82 +164,71 @@ fn on_add_ui_button( .observe(responsive_button_out); } -fn setup(mut commands: Commands) { - commands.spawn(( - Camera2d, - Camera { - clear_color: ClearColorConfig::Custom(WHITE.into()), - ..default() - }, - )); - - commands - .spawn(( - Node { - top: Val::Px(0.0), - left: Val::Px(0.0), - height: Val::Px(40.0), - width: Val::Percent(100.0), - ..default() - }, - Transform::default(), - )) - .with_children(|parent| { - parent.spawn(UiButton::Power).observe(shutdown); - // TODO: Reset button - parent - .spawn((UiButton::Pause, SimulationPlayback::Run)) - .observe(pause_sim); - parent - .spawn((UiButton::Play, SimulationPlayback::Pause)) - .observe(play_sim); - parent.spawn(UiButton::Step).observe(step_sim); - parent.spawn(UiButton::ZoomOut).observe(zoom_out); - parent.spawn(UiButton::ZoomIn).observe(zoom_in); - // TODO: Mute/Unmute Toggle - parent - .spawn((UiButton::MuteAudio, AudioPlayback::Play)) - .observe(mute_audio); - parent - .spawn((UiButton::PlayAudio, AudioPlayback::Mute)) - .observe(play_audio); - }); - - fn shutdown(_trigger: On>, mut writer: MessageWriter) { - writer.write(AppExit::Success); - } - fn play_sim(_trigger: On>, mut next: ResMut>) { - // Set simulation state - next.set(SimulationPlayback::Run); - } - fn pause_sim(_trigger: On>, mut next: ResMut>) { - // Set simulation state - next.set(SimulationPlayback::Pause); +fn the_camera() -> impl Scene { + bsn! { + Camera2d } - fn step_sim(_trigger: On>, mut next: ResMut>) { - next.set(SimulationPlayback::Step); - } - fn zoom_out(_trigger: On>, mut projection: Query<&mut Projection>) { - projection.iter_mut().for_each(|mut p| match *p { - Projection::Orthographic(ref mut o) => { - o.scale /= 0.5; - } - _ => todo!(), - }); - } - fn zoom_in(_trigger: On>, mut projection: Query<&mut Projection>) { - projection.iter_mut().for_each(|mut p| match *p { - Projection::Orthographic(ref mut o) => { - o.scale *= 0.5; - } - _ => todo!(), - }); - } - fn play_audio(_trigger: On>, mut next: ResMut>) { - next.set(AudioPlayback::Play); - } - fn mute_audio(_trigger: On>, mut next: ResMut>) { - next.set(AudioPlayback::Mute); +} + +fn the_ui() -> impl Scene { + bsn! { + Node { + top: Val::Px(0.0), + left: Val::Px(0.0), + height: Val::Px(40.0), + width: Val::Percent(100.0), + } + Transform + Children [ + UiButton::Power + on(|_: On>, mut writer: MessageWriter| { + writer.write(AppExit::Success); + }), + UiButton::Pause + SimulationPlayback::Run + on(|_: On>, mut next: ResMut>| { + // Set simulation state + next.set(SimulationPlayback::Pause); + }), + UiButton::Play + SimulationPlayback::Pause + on(|_: On>, mut next: ResMut>| { + // Set simulation state + next.set(SimulationPlayback::Run); + }), + UiButton::Step + on(|_: On>, mut next: ResMut>| { + next.set(SimulationPlayback::Step); + }), + UiButton::ZoomOut + on(|_: On>, mut projection: Query<&mut Projection>| { + projection.iter_mut().for_each(|mut p| match *p { + Projection::Orthographic(ref mut o) => { + o.scale /= 0.5; + } + _ => todo!(), + }); + }), + UiButton::ZoomIn + on(|_: On>, mut projection: Query<&mut Projection>| { + projection.iter_mut().for_each(|mut p| match *p { + Projection::Orthographic(ref mut o) => { + o.scale *= 0.5; + } + _ => todo!(), + }); + }), + UiButton::MuteAudio + AudioPlayback::Play + on(|_: On>, mut next: ResMut>| { + next.set(AudioPlayback::Play); + }), + UiButton::PlayAudio + AudioPlayback::Mute + on(|_: On>, mut next: ResMut>| { + next.set(AudioPlayback::Mute); + }), + ] } } @@ -433,7 +417,8 @@ fn assert_cell_uniqueness(q: Query<(Entity, &Coordinates), With>) { }) } -#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component)] +#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)] +#[allow(dead_code)] enum SimulationPlayback { #[default] Pause, @@ -663,7 +648,7 @@ fn control_volume(state: ResMut>, mut sinks: Query<&mut Aud sinks.iter_mut().for_each(|mut sink| { sink.set_volume(volume); }) - }, + } AudioPlayback::Mute => sinks.iter_mut().for_each(|mut sink| { sink.set_volume(Volume::SILENT); }), diff --git a/prototypes/Cargo.toml b/prototypes/Cargo.toml index 6a6c152..44b5959 100644 --- a/prototypes/Cargo.toml +++ b/prototypes/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -bevy = "0.18.1" +bevy = "0.19.0" [dependencies.engine] path = "../engine"