Skip to content
Snippets Groups Projects
Verified Commit 19e0083c authored by Louis's avatar Louis :fire:
Browse files

Lint + fmt

parent 09a697aa
No related branches found
No related tags found
No related merge requests found
hard_tabs = true
use_field_init_shorthand = true
use_try_shorthand = true
\ No newline at end of file
use bevy_asset::Handle;
use micro_musicbox::prelude::AudioSource; use micro_musicbox::prelude::AudioSource;
use std::fmt::Debug; use std::fmt::Debug;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::time::Duration; use std::time::Duration;
use bevy_asset::Handle;
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_render::prelude::*; use bevy_render::prelude::*;
...@@ -19,8 +19,6 @@ pub struct SplashStep { ...@@ -19,8 +19,6 @@ pub struct SplashStep {
step_type: SplashStepType, step_type: SplashStepType,
} }
pub type SplashAnimation = Vec<SplashStep>;
#[derive(Resource)] #[derive(Resource)]
pub struct LogoHandle(pub Handle<Image>); pub struct LogoHandle(pub Handle<Image>);
impl Deref for LogoHandle { impl Deref for LogoHandle {
...@@ -74,4 +72,4 @@ impl DerefMut for SplashTime { ...@@ -74,4 +72,4 @@ impl DerefMut for SplashTime {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0 &mut self.0
} }
} }
\ No newline at end of file
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
// use bevy::prelude::*;
use std::time::Duration;
use bevy_app::{App, Plugin, Update}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use std::time::Duration;
pub use crate::components::SplashSettings; pub use crate::components::SplashSettings;
use crate::components::{SplashTime, TweenClearColor}; use crate::components::{SplashTime, TweenClearColor};
...@@ -13,85 +12,85 @@ mod system; ...@@ -13,85 +12,85 @@ mod system;
#[derive(Default, Debug, Resource)] #[derive(Default, Debug, Resource)]
struct SplashManager { struct SplashManager {
elapsed: Duration, elapsed: Duration,
} }
#[derive(PartialOrd, PartialEq, Copy, Clone, Resource, Default)] #[derive(PartialOrd, PartialEq, Copy, Clone, Resource, Default)]
pub enum SplashState { pub enum SplashState {
#[default] #[default]
Loading, Loading,
Running, Running,
} }
impl SplashState { impl SplashState {
pub fn is_loading(&self) -> bool { pub fn is_loading(&self) -> bool {
matches!(&self, SplashState::Loading) matches!(&self, SplashState::Loading)
} }
pub fn is_running(&self) -> bool { pub fn is_running(&self) -> bool {
matches!(&self, SplashState::Running) matches!(&self, SplashState::Running)
} }
} }
pub fn is_loading(state: Res<SplashState>) -> bool { pub fn is_loading(state: Res<SplashState>) -> bool {
state.is_loading() state.is_loading()
} }
pub fn is_running(state: Res<SplashState>) -> bool { pub fn is_running(state: Res<SplashState>) -> bool {
state.is_running() state.is_running()
} }
pub fn started_running(state: Res<SplashState>) -> bool { 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> { pub struct AdventSplashPlugin<StateType: States> {
settings: SplashSettings<StateType>, settings: SplashSettings<StateType>,
} }
impl<StateType: States> AdventSplashPlugin<StateType> { impl<StateType: States> AdventSplashPlugin<StateType> {
pub fn with_settings(settings: SplashSettings<StateType>) -> AdventSplashPlugin<StateType> { pub fn with_settings(settings: SplashSettings<StateType>) -> AdventSplashPlugin<StateType> {
Self { settings } Self { settings }
} }
} }
impl<StateType: States + Copy> Plugin for AdventSplashPlugin<StateType> { impl<StateType: States + Copy> Plugin for AdventSplashPlugin<StateType> {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_resource::<SplashState>() app.init_resource::<SplashState>()
.insert_resource(SplashTime(Duration::from_secs(5))) .insert_resource(SplashTime(Duration::from_secs(5)))
.insert_resource(self.settings.clone()) .insert_resource(self.settings.clone())
.add_systems( .add_systems(
OnEnter(self.settings.run_in), OnEnter(self.settings.run_in),
system::load_assets::<StateType>, system::load_assets::<StateType>,
) )
.add_systems( .add_systems(
Update, Update,
system::monitor_asset_loading system::monitor_asset_loading
.run_if(is_loading) .run_if(is_loading)
.run_if(in_state(self.settings.run_in)), .run_if(in_state(self.settings.run_in)),
) )
.add_systems( .add_systems(
Update, Update,
system::spawn_splash_assets::<StateType> system::spawn_splash_assets::<StateType>
.run_if(started_running) .run_if(started_running)
.run_if(in_state(self.settings.run_in)), .run_if(in_state(self.settings.run_in)),
) )
.add_systems( .add_systems(
Update, Update,
(system::apply_window_scale, system::tick_time::<StateType>) (system::apply_window_scale, system::tick_time::<StateType>)
.run_if(is_running) .run_if(is_running)
.run_if(in_state(self.settings.run_in)), .run_if(in_state(self.settings.run_in)),
) )
.add_systems( .add_systems(
Update, Update,
system::tween_clear_color system::tween_clear_color
.run_if(is_running) .run_if(is_running)
.run_if(in_state(self.settings.run_in)) .run_if(in_state(self.settings.run_in))
.run_if(resource_exists::<TweenClearColor>), .run_if(resource_exists::<TweenClearColor>),
) )
.add_systems(OnExit(self.settings.run_in), system::cleanup_assets); .add_systems(OnExit(self.settings.run_in), system::cleanup_assets);
if self.settings.skip_on_input { if self.settings.skip_on_input {
app.add_systems( app.add_systems(
Update, Update,
system::window_skip::<StateType> system::window_skip::<StateType>
.run_if(is_running) .run_if(is_running)
.run_if(in_state(self.settings.run_in)), .run_if(in_state(self.settings.run_in)),
); );
} }
} }
} }
...@@ -3,11 +3,11 @@ use crate::components::{ ...@@ -3,11 +3,11 @@ use crate::components::{
}; };
use crate::SplashState; use crate::SplashState;
use micro_musicbox::prelude::MusicBox; use micro_musicbox::prelude::MusicBox;
use std::ops::Deref;
use std::time::Duration; 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_ecs::prelude::*;
use bevy_hierarchy::DespawnRecursiveExt;
use bevy_input::prelude::*; use bevy_input::prelude::*;
use bevy_math::Vec2; use bevy_math::Vec2;
use bevy_render::prelude::*; use bevy_render::prelude::*;
...@@ -15,7 +15,6 @@ use bevy_render::texture::ImageSampler; ...@@ -15,7 +15,6 @@ use bevy_render::texture::ImageSampler;
use bevy_sprite::prelude::*; use bevy_sprite::prelude::*;
use bevy_time::Time; use bevy_time::Time;
use bevy_transform::prelude::Transform; use bevy_transform::prelude::Transform;
use bevy_hierarchy::DespawnRecursiveExt;
use log::error; use log::error;
...@@ -127,14 +126,8 @@ pub fn tween_clear_color( ...@@ -127,14 +126,8 @@ pub fn tween_clear_color(
pub fn apply_window_scale( pub fn apply_window_scale(
window_query: Query<&OrthographicProjection>, window_query: Query<&OrthographicProjection>,
mut scaled_query: Query< mut scaled_query: Query<
( (&mut Transform, Option<&Handle<Image>>),
&mut Transform, (With<Handle<Image>>, With<ScaleToWindow>),
Option<&Handle<Image>>,
),
(
With<Handle<Image>>,
With<ScaleToWindow>,
),
>, >,
images: Res<Assets<Image>>, images: Res<Assets<Image>>,
) { ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment