diff --git a/examples/shaders.rs b/examples/shaders.rs index 843587f..c350155 100644 --- a/examples/shaders.rs +++ b/examples/shaders.rs @@ -23,24 +23,23 @@ fn main() { .add_systems(Update, apply_skybox) .add_systems(Update, set_scene) .add_systems(Update, rotate) - .add_systems(Update, toggle_material.run_if( - |keys: Res>| -> bool { - keys.just_pressed(KeyCode::Space) - }) + .add_systems( + Update, + toggle_material + .run_if(|keys: Res>| -> bool { keys.just_pressed(KeyCode::Space) }), + ) + .add_systems( + Update, + init_materials + .run_if(|events: Query>| -> bool { !events.is_empty() }), ) - .add_systems(Update, init_materials.run_if(|events: Query>| -> bool { - !events.is_empty() - })) .run(); } #[derive(Component)] struct Root; -fn setup( - mut commands: Commands, - assets: Res, -) { +fn setup(mut commands: Commands, assets: Res) { commands.spawn((SceneBundle { ..default() }, Root)); commands.spawn(PointLightBundle { @@ -52,13 +51,10 @@ fn setup( ..default() }); - commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(-1.0, 1.5, 4.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }, - ) - ); + commands.spawn((Camera3dBundle { + transform: Transform::from_xyz(-1.0, 1.5, 4.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + },)); } fn apply_skybox( @@ -118,7 +114,6 @@ impl MaterialExtension for MatExt { } } - #[derive(Debug, Component)] struct Backup(T); @@ -143,9 +138,7 @@ fn init_materials( let ext_handle = materials.add(ExtendedMaterial { base, extension }); - commands - .entity(entity) - .insert(Backup(ext_handle.clone())); + commands.entity(entity).insert(Backup(ext_handle.clone())); }); } @@ -158,9 +151,7 @@ fn toggle_material( query.iter().for_each(|entity| { // Entity has standard material, and had extended material // Swap these materials - if let Ok( - (std_handle, Some(Backup(ext_handle))) - ) = std_mat.get(entity) { + if let Ok((std_handle, Some(Backup(ext_handle)))) = std_mat.get(entity) { info!("Swapping standard material for extended material"); commands .entity(entity) @@ -169,13 +160,11 @@ fn toggle_material( .remove::>>() .remove::>(); - return + return; } // In this branch we have the extended material assigned to the object - if let Ok( - (ext_handle, Some(Backup(std_handle))) - ) = ext_mat.get(entity) { + if let Ok((ext_handle, Some(Backup(std_handle)))) = ext_mat.get(entity) { // Entity has standard material, and had extended material // Swap these materials info!("Swapping extended material for standard material"); @@ -186,7 +175,7 @@ fn toggle_material( .remove::>>() .remove::>(); - return + return; } panic!("What is happening?") @@ -204,4 +193,4 @@ fn rotate( materials.iter_mut().for_each(|(_id, m)| { m.extension.cutoff = time.elapsed_seconds().sin().abs(); }) -} \ No newline at end of file +} diff --git a/src/credits.rs b/src/credits.rs index 992587b..df8c662 100644 --- a/src/credits.rs +++ b/src/credits.rs @@ -7,14 +7,12 @@ impl Plugin for CreditsPlugin { app.add_systems(Startup, init_credits_ui) .add_systems( Update, - ( - menu::exit_to_menu.run_if(in_state(GameState::Credits)), - ), + (menu::exit_to_menu.run_if(in_state(GameState::Credits)),), + ) + .add_systems( + OnEnter(GameState::Credits), + (update_credits, activate::.after(update_credits)), ) - .add_systems(OnEnter(GameState::Credits), ( - update_credits, - activate::.after(update_credits), - )) .add_systems(OnExit(GameState::Credits), deactivate::); } } @@ -64,18 +62,17 @@ fn update_credits( .get(tweaks_file.handle.clone()) .expect("Load tweakfile"); - query - .iter_mut() - .for_each(|mut text| { - let credits_text = tweak.get::("credits_text").unwrap(); - text.sections = { - credits_text.split('\n').map(|l| { - TextSection { - value: format!("{}\n", l), - style: TextStyle { ..default() }, - } - }).collect() - }; - info!("Text sections: {:?}", text.sections); - }); + query.iter_mut().for_each(|mut text| { + let credits_text = tweak.get::("credits_text").unwrap(); + text.sections = { + credits_text + .split('\n') + .map(|l| TextSection { + value: format!("{}\n", l), + style: TextStyle { ..default() }, + }) + .collect() + }; + info!("Text sections: {:?}", text.sections); + }); } diff --git a/src/display3d.rs b/src/display3d.rs index 1293b85..da924e5 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -4,18 +4,24 @@ use crate::{ tweak::Tweaks, }; use bevy::{ - animation::RepeatAnimation, core_pipeline::{ + animation::RepeatAnimation, + core_pipeline::{ experimental::taa::{TemporalAntiAliasPlugin, TemporalAntiAliasSettings}, prepass::MotionVectorPrepass, tonemapping::{DebandDither, Tonemapping}, Skybox, - }, input::mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel}, pbr::{ - ExtendedMaterial, MaterialExtension, - ScreenSpaceAmbientOcclusionBundle, ScreenSpaceAmbientOcclusionSettings, - }, render::{ + }, + input::mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel}, + pbr::{ + ExtendedMaterial, MaterialExtension, ScreenSpaceAmbientOcclusionBundle, + ScreenSpaceAmbientOcclusionSettings, + }, + render::{ render_resource::{AsBindGroup, ShaderRef, TextureViewDescriptor, TextureViewDimension}, view::ColorGrading, - }, utils::HashMap, window::PrimaryWindow + }, + utils::HashMap, + window::PrimaryWindow, }; use tweaks::*; @@ -72,7 +78,9 @@ impl Plugin for Display3dPlugin { ), setup_capture_piece.run_if(any_component_changed::>), capture_piece.run_if(any_with_component::()), - skip_animation.run_if(|keys: Res>| -> bool { keys.just_pressed(KeyCode::Return) }), + skip_animation.run_if(|keys: Res>| -> bool { + keys.just_pressed(KeyCode::Return) + }), ), ) .add_systems( @@ -572,7 +580,7 @@ fn set_piece_texture( if let Some(gltf) = gltfs.get(assets_handle) { // Why can't we just models.iter_many_mut(...).for_each(...)?? let mut stuff = models.iter_many_mut(children.iter_descendants(entity)); - while let Some((n, mut m)) = stuff.fetch_next() { + while let Some((n, mut m)) = stuff.fetch_next() { debug!("Setting piece texture for {:?}", n); match (*piece, side, n.as_str()) { (Piece::Queen, Side::A, "Queen.0") => { @@ -1288,7 +1296,13 @@ struct Backup(T); /// Sets up all pieces to have an associated "dissolve" material ready for capture fn setup_capture_piece( // All entities with materials are candidates for this procedure - events: Query<(Entity, &Handle), (Added>, Changed>)>, + events: Query< + (Entity, &Handle), + ( + Added>, + Changed>, + ), + >, // Only process newly created pieces (we do not delete pieces at runtime) query: Query, Added)>, // Children of pieces are the actual meshes that need materials @@ -1305,9 +1319,7 @@ fn setup_capture_piece( events .iter() // Only process if this is a child of a piece - .filter(|(child, _)| { - query.iter_many(parents.iter_ancestors(*child)).count() > 0 - }) + .filter(|(child, _)| query.iter_many(parents.iter_ancestors(*child)).count() > 0) // Handle this entity (mesh) .for_each(|(child, std_handle)| { let dis_handle = match cache.get(std_handle) { @@ -1322,7 +1334,7 @@ fn setup_capture_piece( .clone(); dissolve_materials.add(ExtendedMaterial { base, extension }) - }, + } Some(dis_handle) => dis_handle.clone(), }; @@ -1330,9 +1342,7 @@ fn setup_capture_piece( cache.insert(std_handle.clone(), dis_handle.clone()); // Add the dissolve handle as a Backup(T) - commands - .entity(child) - .insert(Backup(dis_handle.clone())); + commands.entity(child).insert(Backup(dis_handle.clone())); }); } @@ -1351,8 +1361,16 @@ fn capture_piece( mut kids: Local>, mut prog: Local, mut dissolve_materials: ResMut>, - object_standard_materials: Query<(Entity, &Handle, &Backup>)>, - object_dissolve_materials: Query<(Entity, &Handle, &Backup>)>, + object_standard_materials: Query<( + Entity, + &Handle, + &Backup>, + )>, + object_dissolve_materials: Query<( + Entity, + &Handle, + &Backup>, + )>, children: Query<&Children>, mut commands: Commands, time: Res