diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000000000000000000000000000000000000..2b6f66e87d12dad0d933b81de57925300dd3a3fe --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +hard_tabs = true +use_field_init_shorthand = true +use_try_shorthand = true \ No newline at end of file diff --git a/src/components.rs b/src/components.rs index 65a74a1ba020190c77d831c2380fa6dd430490bb..e5eca0749d6365d7cb03c65671e0ae414b66a5fb 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,8 +1,8 @@ +use bevy_asset::Handle; use micro_musicbox::prelude::AudioSource; use std::fmt::Debug; use std::ops::{Deref, DerefMut}; use std::time::Duration; -use bevy_asset::Handle; use bevy_ecs::prelude::*; use bevy_render::prelude::*; @@ -19,8 +19,6 @@ pub struct SplashStep { step_type: SplashStepType, } -pub type SplashAnimation = Vec<SplashStep>; - #[derive(Resource)] pub struct LogoHandle(pub Handle<Image>); impl Deref for LogoHandle { @@ -74,4 +72,4 @@ impl DerefMut for SplashTime { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 20dca36b28503c186e20334170e8c12be968a160..66f3bd1f31e6e57a261c396b124ca941431ce2c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,8 @@ #![allow(clippy::type_complexity)] -// use bevy::prelude::*; -use std::time::Duration; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; +use std::time::Duration; pub use crate::components::SplashSettings; use crate::components::{SplashTime, TweenClearColor}; @@ -13,85 +12,85 @@ mod system; #[derive(Default, Debug, Resource)] struct SplashManager { - elapsed: Duration, + elapsed: Duration, } #[derive(PartialOrd, PartialEq, Copy, Clone, Resource, Default)] pub enum SplashState { - #[default] - Loading, - Running, + #[default] + Loading, + Running, } impl SplashState { - pub fn is_loading(&self) -> bool { - matches!(&self, SplashState::Loading) - } - pub fn is_running(&self) -> bool { - matches!(&self, SplashState::Running) - } + pub fn is_loading(&self) -> bool { + matches!(&self, SplashState::Loading) + } + pub fn is_running(&self) -> bool { + matches!(&self, SplashState::Running) + } } pub fn is_loading(state: Res<SplashState>) -> bool { - state.is_loading() + state.is_loading() } pub fn is_running(state: Res<SplashState>) -> bool { - state.is_running() + state.is_running() } pub fn started_running(state: Res<SplashState>) -> bool { - state.is_changed() && state.is_running() + state.is_changed() && state.is_running() } pub struct AdventSplashPlugin<StateType: States> { - settings: SplashSettings<StateType>, + settings: SplashSettings<StateType>, } impl<StateType: States> AdventSplashPlugin<StateType> { - pub fn with_settings(settings: SplashSettings<StateType>) -> AdventSplashPlugin<StateType> { - Self { settings } - } + pub fn with_settings(settings: SplashSettings<StateType>) -> AdventSplashPlugin<StateType> { + Self { settings } + } } impl<StateType: States + Copy> Plugin for AdventSplashPlugin<StateType> { - fn build(&self, app: &mut App) { - app.init_resource::<SplashState>() - .insert_resource(SplashTime(Duration::from_secs(5))) - .insert_resource(self.settings.clone()) - .add_systems( - OnEnter(self.settings.run_in), - system::load_assets::<StateType>, - ) - .add_systems( - Update, - system::monitor_asset_loading - .run_if(is_loading) - .run_if(in_state(self.settings.run_in)), - ) - .add_systems( - Update, - system::spawn_splash_assets::<StateType> - .run_if(started_running) - .run_if(in_state(self.settings.run_in)), - ) - .add_systems( - Update, - (system::apply_window_scale, system::tick_time::<StateType>) - .run_if(is_running) - .run_if(in_state(self.settings.run_in)), - ) - .add_systems( - Update, - system::tween_clear_color - .run_if(is_running) - .run_if(in_state(self.settings.run_in)) - .run_if(resource_exists::<TweenClearColor>), - ) - .add_systems(OnExit(self.settings.run_in), system::cleanup_assets); + fn build(&self, app: &mut App) { + app.init_resource::<SplashState>() + .insert_resource(SplashTime(Duration::from_secs(5))) + .insert_resource(self.settings.clone()) + .add_systems( + OnEnter(self.settings.run_in), + system::load_assets::<StateType>, + ) + .add_systems( + Update, + system::monitor_asset_loading + .run_if(is_loading) + .run_if(in_state(self.settings.run_in)), + ) + .add_systems( + Update, + system::spawn_splash_assets::<StateType> + .run_if(started_running) + .run_if(in_state(self.settings.run_in)), + ) + .add_systems( + Update, + (system::apply_window_scale, system::tick_time::<StateType>) + .run_if(is_running) + .run_if(in_state(self.settings.run_in)), + ) + .add_systems( + Update, + system::tween_clear_color + .run_if(is_running) + .run_if(in_state(self.settings.run_in)) + .run_if(resource_exists::<TweenClearColor>), + ) + .add_systems(OnExit(self.settings.run_in), system::cleanup_assets); - if self.settings.skip_on_input { - app.add_systems( - Update, - system::window_skip::<StateType> - .run_if(is_running) - .run_if(in_state(self.settings.run_in)), - ); - } - } + if self.settings.skip_on_input { + app.add_systems( + Update, + system::window_skip::<StateType> + .run_if(is_running) + .run_if(in_state(self.settings.run_in)), + ); + } + } } diff --git a/src/system.rs b/src/system.rs index 30007abbad34ec6c3407fa4729b9960792531ff7..e0ef8ec79d461b1c3e0168fbbb3490fbc5681f95 100644 --- a/src/system.rs +++ b/src/system.rs @@ -3,11 +3,11 @@ use crate::components::{ }; use crate::SplashState; use micro_musicbox::prelude::MusicBox; -use std::ops::Deref; use std::time::Duration; -use bevy_asset::{Assets, AssetServer, Handle, LoadState, RecursiveDependencyLoadState}; +use bevy_asset::{AssetServer, Assets, Handle, LoadState, RecursiveDependencyLoadState}; use bevy_ecs::prelude::*; +use bevy_hierarchy::DespawnRecursiveExt; use bevy_input::prelude::*; use bevy_math::Vec2; use bevy_render::prelude::*; @@ -15,7 +15,6 @@ use bevy_render::texture::ImageSampler; use bevy_sprite::prelude::*; use bevy_time::Time; use bevy_transform::prelude::Transform; -use bevy_hierarchy::DespawnRecursiveExt; use log::error; @@ -127,14 +126,8 @@ pub fn tween_clear_color( pub fn apply_window_scale( window_query: Query<&OrthographicProjection>, mut scaled_query: Query< - ( - &mut Transform, - Option<&Handle<Image>>, - ), - ( - With<Handle<Image>>, - With<ScaleToWindow>, - ), + (&mut Transform, Option<&Handle<Image>>), + (With<Handle<Image>>, With<ScaleToWindow>), >, images: Res<Assets<Image>>, ) {