diff --git a/examples/sync_resource_to_ui.rs b/examples/sync_resource_to_ui.rs index 4271822..263e019 100644 --- a/examples/sync_resource_to_ui.rs +++ b/examples/sync_resource_to_ui.rs @@ -4,12 +4,17 @@ use games::*; fn main() { App::new() .init_resource::() - .add_plugins(BaseGamePlugin { camera: CameraType::Camera3d }) + .add_plugins(BaseGamePlugin { + camera: CameraType::Camera3d, + }) .add_systems(Startup, init_ui) - .add_systems(Update, ( - sync_resource_to_ui::.run_if(resource_changed::), - update_foo.run_if(on_event::) - )) + .add_systems( + Update, + ( + sync_resource_to_ui::.run_if(resource_changed::), + update_foo.run_if(on_event::), + ), + ) .run(); } @@ -22,28 +27,27 @@ impl Display for Thing { } } -fn init_ui( - mut commands: Commands -) { +fn init_ui(mut commands: Commands) { commands.spawn(( - Node { - align_self: AlignSelf::Start, - justify_self: JustifySelf::Center, - ..default() - }, - Text("Displays a sync'd resource tracking the number of mouse events (mod 256)".into()), - )); - commands.spawn((Node { - align_self: AlignSelf::Center, - justify_self: JustifySelf::Center, - ..default() - }, Text("Placeholder".into()), SyncResource::::default())); + Node { + align_self: AlignSelf::Start, + justify_self: JustifySelf::Center, + ..default() + }, + Text("Displays a sync'd resource tracking the number of mouse events (mod 256)".into()), + )); + commands.spawn(( + Node { + align_self: AlignSelf::Center, + justify_self: JustifySelf::Center, + ..default() + }, + Text("Placeholder".into()), + SyncResource::::default(), + )); } -fn update_foo( - mut events: EventReader, - mut thing: ResMut, -) { +fn update_foo(mut events: EventReader, mut thing: ResMut) { events.read().for_each(|_| { thing.0 = thing.0.overflowing_add(1).0; }); diff --git a/src/base_game.rs b/src/base_game.rs index 19e0746..34958d7 100644 --- a/src/base_game.rs +++ b/src/base_game.rs @@ -2,31 +2,35 @@ use super::*; /// A good starting place for creating a game building on top of the base Bevy app pub struct BaseGamePlugin { - pub camera: CameraType + pub camera: CameraType, } impl Plugin for BaseGamePlugin { fn build(&self, app: &mut App) { - app.add_plugins(DefaultPlugins) - .add_plugins(DebuggingPlugin); + app.add_plugins(DefaultPlugins).add_plugins(DebuggingPlugin); // Add a camera setup system and startup - app.add_systems(Startup, match self.camera { - CameraType::Camera2d => setup_camera_2d, - CameraType::Camera3d => setup_camera_3d, - }); + app.add_systems( + Startup, + match self.camera { + CameraType::Camera2d => setup_camera_2d, + CameraType::Camera3d => setup_camera_3d, + }, + ); } } /// For selecting the type of camera this game requires pub enum CameraType { Camera2d, - Camera3d + Camera3d, } - /// System to toggle the visibility of entities based on their state -pub fn toggle_state_visibility(mut q: Query<(Entity, &mut Visibility, &S)>, curr: Res>) { +pub fn toggle_state_visibility( + mut q: Query<(Entity, &mut Visibility, &S)>, + curr: Res>, +) { q.iter_mut().for_each(|(e, mut v, s)| { if curr.get() == s { *v = Visibility::Inherited; @@ -37,14 +41,10 @@ pub fn toggle_state_visibility(mut q: Query<(Entity, &mut }); } -fn setup_camera_2d( - mut commands: Commands, -) { +fn setup_camera_2d(mut commands: Commands) { commands.spawn((Camera { ..default() }, Camera2d)); } -fn setup_camera_3d( - mut commands: Commands, -) { +fn setup_camera_3d(mut commands: Commands) { commands.spawn((Camera { ..default() }, Camera3d { ..default() })); } diff --git a/src/debug.rs b/src/debug.rs index 2faf811..f813367 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -7,10 +7,14 @@ impl Plugin for DebuggingPlugin { fn build(&self, app: &mut App) { app.init_state::() .add_systems(Startup, init_debug_ui) - .add_systems(Update, ( - toggle_state_visibility::.run_if(state_changed::), - toggle_debug_state.run_if(on_keyboard_press(KeyCode::F12)) - )); + .add_systems( + Update, + ( + toggle_state_visibility:: + .run_if(state_changed::), + toggle_debug_state.run_if(on_keyboard_press(KeyCode::F12)), + ), + ); } } @@ -39,9 +43,7 @@ fn toggle_debug_state( } /// Create the Debugging UI -fn init_debug_ui( - mut commands: Commands -) { +fn init_debug_ui(mut commands: Commands) { commands.spawn(( DebuggingState::On, Text(" Debug: ON ".into()), @@ -52,6 +54,6 @@ fn init_debug_ui( align_self: AlignSelf::Center, justify_self: JustifySelf::End, ..default() - } + }, )); } diff --git a/src/lib.rs b/src/lib.rs index 9f4e660..1242e5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,11 @@ mod ui; pub use std::fmt::Display; -pub use bevy::{prelude::*, input::{keyboard::KeyboardInput, ButtonState}, color::palettes::css::{BLACK, RED, WHITE}}; +pub use bevy::{ + color::palettes::css::{BLACK, RED, WHITE}, + input::{ButtonState, keyboard::KeyboardInput}, + prelude::*, +}; pub use base_game::*; pub use debug::*; diff --git a/src/scheduling.rs b/src/scheduling.rs index 7268c8a..c16ebbe 100644 --- a/src/scheduling.rs +++ b/src/scheduling.rs @@ -12,7 +12,5 @@ pub fn any_component_changed(q: Query>) -> bool /// Scheduling condition to trigger a system when a specific key is pressed pub fn on_keyboard_press(key: KeyCode) -> impl FnMut(Res>) -> bool { - move |keys: Res>| { - keys.just_pressed(key) - } + move |keys: Res>| keys.just_pressed(key) }