diff --git a/examples/shadow.rs b/examples/shadow.rs index 71c2a08..a35302f 100644 --- a/examples/shadow.rs +++ b/examples/shadow.rs @@ -4,28 +4,26 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, init) - .add_systems(Update, add_shadows) + .add_systems(Update, add_shadows) .run(); } -fn init( - server: Res, - mut commands: Commands, -) { - commands.spawn(SceneBundle { - scene: server.load("models/shadow-example.gltf#Scene0"), - ..default() - }); +fn init(server: Res, mut commands: Commands) { + commands.spawn(SceneBundle { + scene: server.load("models/shadow-example.gltf#Scene0"), + ..default() + }); } fn add_shadows( - mut lights: Query<(Entity, &mut PointLight), Added>, - mut commands: Commands, + mut lights: Query<(Entity, &mut PointLight), Added>, + mut commands: Commands, ) { - lights.iter_mut().for_each(|(e, mut l)| { - l.shadows_enabled = true; + lights.iter_mut().for_each(|(e, mut l)| { + l.shadows_enabled = true; - let config: bevy::pbr::CascadeShadowConfig = bevy::pbr::CascadeShadowConfigBuilder { ..default() }.into(); - commands.entity(e).insert(config); - }); -} \ No newline at end of file + let config: bevy::pbr::CascadeShadowConfig = + bevy::pbr::CascadeShadowConfigBuilder { ..default() }.into(); + commands.entity(e).insert(config); + }); +} diff --git a/src/audio.rs b/src/audio.rs index b1ba155..f3950e4 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -27,7 +27,9 @@ impl Plugin for AudioPlugin { audio_trigger.run_if(on_event::()), control_volume.run_if(resource_changed::), toggle_volume.run_if(just_pressed(KeyCode::KeyM)), - set_intensity.run_if(in_state(GameState::Play).and_then(resource_exists::.and_then(resource_changed::))), + set_intensity.run_if(in_state(GameState::Play).and_then( + resource_exists::.and_then(resource_changed::), + )), ), ); } @@ -171,10 +173,14 @@ fn set_intensity( (intensity_ratio * intensity_range) + intensity_min }; - query.iter() + query + .iter() .filter(|(_, event)| **event == AudioEvent::MainMusic) .for_each(|(source, _)| { info!("Setting music intensity to {:?}", value); - source.event_instance.set_parameter_by_name("Intensity", value, true).expect("Set intensity parameter"); + source + .event_instance + .set_parameter_by_name("Intensity", value, true) + .expect("Set intensity parameter"); }); -} \ No newline at end of file +} diff --git a/src/display3d.rs b/src/display3d.rs index d11529f..f623604 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -1,5 +1,5 @@ use bevy::core_pipeline::{ - contrast_adaptive_sharpening::ContrastAdaptiveSharpeningSettings, fxaa::Fxaa + contrast_adaptive_sharpening::ContrastAdaptiveSharpeningSettings, fxaa::Fxaa, }; use crate::prelude::*; @@ -12,6 +12,7 @@ impl Plugin for Display3dPlugin { TemporalAntiAliasPlugin, MaterialPlugin::::default(), )) + .init_state::() .insert_resource(Msaa::Off) .insert_resource(AmbientLight { color: Color::WHITE, @@ -28,7 +29,7 @@ impl Plugin for Display3dPlugin { // Systems related to color and camera .add_systems( Update, - ( + ( color_grading_tweak .run_if(resource_exists::) .run_if(on_event::>()), @@ -38,7 +39,7 @@ impl Plugin for Display3dPlugin { bloom_tweak .run_if(resource_exists::) .run_if(on_event::>()), - ) + ), ) .add_systems( Update, @@ -83,9 +84,9 @@ impl Plugin for Display3dPlugin { skip_animation .run_if(in_state(GameState::Play)) .run_if(pressed(KeyCode::Enter).or_else(pressed(MouseButton::Left))), - un_skip_animation - .run_if(in_state(GameState::Play)) - .run_if(just_released(KeyCode::Enter).or_else(just_released(MouseButton::Left))), + un_skip_animation.run_if(in_state(GameState::Play)).run_if( + just_released(KeyCode::Enter).or_else(just_released(MouseButton::Left)), + ), monitor_animations .run_if(in_state(GameState::Play)) .run_if(any_component_changed::()), @@ -105,18 +106,22 @@ impl Plugin for Display3dPlugin { .run_if(in_state(GameState::Play)) .run_if(in_state(DisplayState::Display3d)), ) + .add_systems( + Update, + ( + animate_title_light_in.run_if(in_state(DissolvingAnimation::In)), + animate_title_light_out.run_if(in_state(DissolvingAnimation::Out)), + ) + ) .add_systems( OnEnter(GameState::Intro), ( // Toggle hidden/visible 3d entities manage_state_entities::(), // fixup_shadows, - color_grading_tweak - .run_if(resource_exists::), - fog_tweak - .run_if(resource_exists::), - bloom_tweak - .run_if(resource_exists::), + color_grading_tweak.run_if(resource_exists::), + fog_tweak.run_if(resource_exists::), + bloom_tweak.run_if(resource_exists::), update_pieces.run_if(resource_exists::), ), ) @@ -129,20 +134,17 @@ impl Plugin for Display3dPlugin { .run_if(in_state(DisplayState::Display3d)), ), ) - .add_systems(OnEnter(GameState::Title), ( - fixup_shadows, - intro_title_dissolve, - )) + .add_systems( + OnEnter(GameState::Title), + (fixup_shadows, intro_title_dissolve), + ) .add_systems(OnExit(GameState::Title), outro_title_dissolve) .add_systems( Update, - continue_title.run_if( - in_state(GameState::Title) - .and_then(not(any_with_component::)) - .and_then( - just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left)), - ), - ), + continue_title + .run_if(in_state(GameState::Title)) + .run_if(not(any_with_component::)) + .run_if(just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left))), ); } } @@ -165,6 +167,14 @@ pub(crate) enum Dissolving { Out(f32), } +#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)] +enum DissolvingAnimation { + #[default] + None, + In, + Out +} + #[derive(Debug, Resource, Clone)] struct AssetsMap { hitbox_shape: Handle, @@ -352,13 +362,11 @@ fn hydrate_camera( }, BloomSettings { intensity: 0.0, - ..default() + ..default() }, FogSettings { color: Color::rgba(0.25, 0.25, 0.25, 1.0), - falloff: FogFalloff::Exponential { - density: 0.0, - }, + falloff: FogFalloff::Exponential { density: 0.0 }, ..default() }, )); @@ -465,7 +473,7 @@ fn set_board_model( } fn set_title_model( - mut titles: Query<(&mut Handle, &mut Transform), (Added, With)>, + mut titles: Query<(&mut Handle, &mut Transform, &mut Visibility), (Added, With)>, gltfs: Res>, tweaks: Res>, tweaks_file: Res, @@ -473,7 +481,7 @@ fn set_title_model( let tweak = tweaks .get(tweaks_file.handle.clone()) .expect("Load tweakfile"); - titles.iter_mut().for_each(|(mut handle, mut transform)| { + titles.iter_mut().for_each(|(mut handle, mut transform, mut visibility)| { info!("Setting title model"); let assets_handle = tweak .get_handle::("display3d_models_assets_file") @@ -489,9 +497,12 @@ fn set_title_model( ) .expect("Game title model") .clone(); + transform.translation -= Vec3::Y * 0.5; transform.rotate_local_z(std::f32::consts::PI); transform.rotate_local_y(std::f32::consts::PI / 2.0); + + *visibility = Visibility::Hidden; }); } @@ -631,8 +642,8 @@ fn update_pieces( // Set scene model for this piece // if *scene != *scene_handle { - warn!("Updating scene for piece {:?}", entity); - *scene = scene_handle.clone(); + warn!("Updating scene for piece {:?}", entity); + *scene = scene_handle.clone(); // } } }, @@ -952,14 +963,12 @@ fn skip_animation( let speed = tweak.get::("animation_fast_speed").unwrap(); players.iter_mut().for_each(|mut p| { debug!("Skipping animation"); - // HACK: Set the speed of the animation to turbo + // HACK: Set the speed of the animation to turbo p.set_speed(speed); }) } -fn un_skip_animation( - mut players: Query<&mut AnimationPlayer, With>, -) { +fn un_skip_animation(mut players: Query<&mut AnimationPlayer, With>) { players.iter_mut().for_each(|mut p| { debug!("Un-Skipping animation"); p.set_speed(1.0); @@ -1179,7 +1188,10 @@ struct Animating; fn monitor_animations( active: Query<(Entity, &AnimationPlayer), (Changed, With)>, - mut inactive: Query<(Entity, &mut AnimationPlayer), (Changed, Without)>, + mut inactive: Query< + (Entity, &mut AnimationPlayer), + (Changed, Without), + >, mut commands: Commands, ) { // Remove Animating component from players that are done @@ -1192,7 +1204,11 @@ fn monitor_animations( // Set inactive entities to active inactive.iter_mut().for_each(|(entity, mut player)| { if !player.is_finished() && *player.animation_clip() != Handle::::default() { - info!("Entity {:?} is playing {:?}, adding animating marker", entity, player.animation_clip()); + info!( + "Entity {:?} is playing {:?}, adding animating marker", + entity, + player.animation_clip() + ); commands.entity(entity).insert(Animating); player.set_speed(1.0); } @@ -1202,22 +1218,26 @@ fn monitor_animations( fn intro_title_dissolve( mut query: Query<(Entity, &Dissolvable), With>, mut commands: Commands, + mut next: ResMut>, ) { query.iter_mut().for_each(|(entity, dissolving)| { commands .entity(entity) .insert(Dissolving::In(dissolving.duration)); + next.set(DissolvingAnimation::In); }); } fn outro_title_dissolve( mut query: Query<(Entity, &Dissolvable), With>, mut commands: Commands, + mut next: ResMut>, ) { query.iter_mut().for_each(|(entity, dissolving)| { commands .entity(entity) .insert(Dissolving::Out(dissolving.duration)); + next.set(DissolvingAnimation::Out); }); } @@ -1239,6 +1259,7 @@ fn dissolve_animation( keys: Res>, mouse: Res>, time: Res