diff --git a/src/audio.rs b/src/audio.rs index 20cf814..e8680eb 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -2,9 +2,6 @@ /// TODO: Custom Asset: FmodEventMapper /// use crate::prelude::*; -use bevy::prelude::*; -use bevy_fmod::prelude::AudioSource; -use bevy_fmod::prelude::*; pub(crate) struct AudioPlugin; @@ -28,8 +25,8 @@ impl Plugin for AudioPlugin { ( play_audio.run_if(any_component_added::()), audio_trigger.run_if(on_event::()), - control_volume.run_if(resource_changed::()), - toggle_volume.run_if(just_pressed(KeyCode::M)), + control_volume.run_if(resource_changed::), + toggle_volume.run_if(just_pressed(KeyCode::KeyM)), ), ); } diff --git a/src/credits.rs b/src/credits.rs index aefd30e..6dcb18c 100644 --- a/src/credits.rs +++ b/src/credits.rs @@ -56,7 +56,7 @@ fn init_credits_ui( Credits, TextBundle { text: Text { - alignment: TextAlignment::Center, + justify: JustifyText::Center, sections: vec![], ..default() }, diff --git a/src/debug.rs b/src/debug.rs index 73f6d74..26c78b6 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,12 +1,3 @@ -use bevy::{ - diagnostic::{ - DiagnosticsStore, EntityCountDiagnosticsPlugin, FrameTimeDiagnosticsPlugin, - SystemInformationDiagnosticsPlugin, - }, - input::{keyboard::KeyboardInput, ButtonState}, - utils::{hashbrown::hash_map::Iter, HashMap}, -}; - use crate::prelude::*; pub(crate) struct DebugPlugin; @@ -28,19 +19,19 @@ impl Plugin for DebugPlugin { .add_systems( Update, ( - selected_gizmo.run_if(any_with_component::()), - selected_position.run_if(any_with_component::()), + selected_gizmo.run_if(any_with_component::), + selected_position.run_if(any_with_component::), ) - .run_if(resource_exists::()), + .run_if(resource_exists::), ) .add_systems(Startup, init_debug_ui) .add_systems( Update, ( toggle_debug_mode.run_if(on_event::()), - display_diagnostics.run_if(resource_exists::()), + display_diagnostics.run_if(resource_exists::), toggle_debug_ui.run_if(resource_changed_or_removed::()), - camera_info.run_if(resource_exists::()), + camera_info.run_if(resource_exists::), ), ); } @@ -84,7 +75,7 @@ fn toggle_debug_mode( .filter( |KeyboardInput { state, key_code, .. - }| *state == ButtonState::Pressed && *key_code == Some(KeyCode::F3), + }| *state == ButtonState::Pressed && *key_code == KeyCode::F3, ) .for_each(|_| match enabled { Some(_) => commands.remove_resource::(), @@ -137,7 +128,7 @@ fn display_diagnostics( root.iter_mut().for_each(|mut text| { text.sections = diagnostics .iter() - .map(|d| format!("{}: {:.0}\n", d.name, d.smoothed().unwrap_or(0.0),)) + .map(|d| format!("{}: {:.0}\n", d.suffix, d.smoothed().unwrap_or(0.0),)) .chain(debug_infos.iter().map(|(k, v)| format!("{}: {}\n", k, v))) .map(|s| TextSection::new(s, TextStyle { ..default() })) .collect(); @@ -166,21 +157,21 @@ fn aabb_gizmo( mut commands: Commands, ) { added.iter().for_each(|e| { - commands.entity(e).insert(AabbGizmo { + commands.entity(e).insert(ShowAabbGizmo { color: Some(Color::RED), }); }); removed.read().for_each(|e| { - commands.entity(e).remove::(); + commands.entity(e).remove::(); }); match active { Some(_) => selected.iter().for_each(|e| { - commands.entity(e).insert(AabbGizmo { + commands.entity(e).insert(ShowAabbGizmo { color: Some(Color::RED), }); }), None => selected.iter().for_each(|e| { - commands.entity(e).remove::(); + commands.entity(e).remove::(); }), } } diff --git a/src/display3d.rs b/src/display3d.rs index 70af931..03e13dc 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -1,33 +1,4 @@ -use crate::{ - game::{Board, BoardIndex, Piece, Side}, - prelude::*, - tweak::Tweaks, -}; -use bevy::{ - animation::RepeatAnimation, - core_pipeline::{ - bloom::BloomSettings, - experimental::taa::{TemporalAntiAliasPlugin, TemporalAntiAliasSettings}, - prepass::MotionVectorPrepass, - tonemapping::{DebandDither, Tonemapping}, - Skybox, - }, - input::{ - mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel}, - ButtonState, - }, - pbr::{ - ExtendedMaterial, MaterialExtension, ScreenSpaceAmbientOcclusionBundle, - ScreenSpaceAmbientOcclusionSettings, - }, - render::{ - render_resource::{AsBindGroup, ShaderRef, TextureViewDescriptor, TextureViewDimension}, - view::ColorGrading, - }, - utils::HashMap, - window::PrimaryWindow, -}; -use tweaks::*; +use crate::prelude::*; pub(crate) struct Display3dPlugin; @@ -43,7 +14,7 @@ impl Plugin for Display3dPlugin { ( initialize, fix_skybox.before(initialize), - update_tweaks.run_if(resource_exists::()), + update_tweaks.run_if(resource_exists::), ), ) .add_systems( @@ -62,7 +33,7 @@ impl Plugin for Display3dPlugin { set_piece_position.run_if(any_component_changed::()), set_piece_texture .run_if(any_component_changed::()) - .run_if(resource_exists::()), + .run_if(resource_exists::), select .run_if(in_state(GameState::Play)) .run_if(in_state(DisplayState::Display3d)) @@ -71,10 +42,10 @@ impl Plugin for Display3dPlugin { put_down.run_if(any_component_removed::()), switch_sides .run_if(in_state(GameState::Play)) - .run_if(state_changed::()), + .run_if(state_changed::), update_tweaks .run_if(on_event::>()) - .run_if(resource_exists::()), + .run_if(resource_exists::), scale_lighting.run_if( any_component_added::() .or_else(any_component_added::()) @@ -82,9 +53,9 @@ impl Plugin for Display3dPlugin { .or_else(on_event::>()), ), setup_capture_piece.run_if(any_component_changed::>()), - capture_piece.run_if(any_with_component::()), + capture_piece.run_if(any_with_component::), skip_animation - .run_if(just_pressed(KeyCode::Return).or_else(just_pressed(MouseButton::Left))) + .run_if(just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left))) .run_if(in_state(GameState::Play)), ), ) @@ -96,9 +67,9 @@ impl Plugin for Display3dPlugin { gizmo_system, selected_gizmo, moves_gizmo, - debug_selected.run_if(any_with_component::()), + debug_selected.run_if(any_with_component::), ) - .run_if(resource_exists::()) + .run_if(resource_exists::) .run_if(in_state(GameState::Play)) .run_if(in_state(DisplayState::Display3d)), ) @@ -112,8 +83,8 @@ impl Plugin for Display3dPlugin { .add_systems( OnEnter(GameState::Play), ( - set_piece_texture.run_if(resource_exists::()), - update_tweaks.run_if(resource_exists::()), + set_piece_texture.run_if(resource_exists::), + update_tweaks.run_if(resource_exists::), opening_animation .run_if(run_once()) .run_if(in_state(DisplayState::Display3d)), @@ -142,7 +113,7 @@ fn load_assets( mut meshes: ResMut>, mut materials: ResMut>, ) { - let hitbox_shape = meshes.add(shape::Box::new(1.0, 0.1, 1.0).into()); + let hitbox_shape = meshes.add(Cuboid::new(1.0, 0.1, 1.0)); let hitbox_material = materials.add(StandardMaterial { base_color: Color::NONE, perceptual_roughness: 0.0, @@ -278,12 +249,15 @@ fn hydrate_camera( ..default() }, BloomSettings { ..default() }, - Skybox(skybox_handle.clone()), + Skybox { + image: skybox_handle.clone(), + brightness: 1.0, + }, EnvironmentMapLight { diffuse_map: skybox_handle.clone(), specular_map: skybox_handle.clone(), + intensity: 1.0, }, - UiCameraConfig { show_ui: true }, FogSettings { ..default() }, ScreenSpaceAmbientOcclusionBundle { ..default() }, TemporalAntiAliasSettings { ..default() }, @@ -341,25 +315,26 @@ fn update_tweaks( camera_settings.iter_mut().for_each( |(entity, mut fog, mut color_grading, mut tonemapping, mut bloom)| { *fog = tweak - .get::("display3d_fog") + .get::("display3d_fog") .unwrap() .into(); *color_grading = tweak - .get::("display3d_color_grading") + .get::("display3d_color_grading") .unwrap() .into(); *tonemapping = tweak - .get::("display3d_color_tonemapping") + .get::("display3d_color_tonemapping") .unwrap() .into(); *bloom = tweak - .get::("display3d_bloom") + .get::("display3d_bloom") .unwrap() .into(); - let quality_level = tweak.get::( - "display3d_ssao_quality_level", - ); + let quality_level = tweak + .get::( + "display3d_ssao_quality_level", + ); match quality_level { Some(quality_level) => { commands @@ -373,7 +348,10 @@ fn update_tweaks( commands .entity(entity) .remove::(); - let msaa: Msaa = tweak.get::("display3d_msaa").unwrap().into(); + let msaa: Msaa = tweak + .get::("display3d_msaa") + .unwrap() + .into(); commands.insert_resource(msaa); } } @@ -542,7 +520,7 @@ fn gizmo_system(mut gizmos: Gizmos) { /// TODO: This has bad feel, needs to be tuned fn move_camera( - buttons: Res>, + buttons: Res>, mut events: EventReader, mut camera: Query<&mut Transform, (With, With)>, ) { @@ -1132,17 +1110,7 @@ fn scale_lighting( } pub(super) mod tweaks { - use bevy::{ - core_pipeline::{bloom::BloomSettings, tonemapping::Tonemapping}, - math::Vec3, - pbr::{FogFalloff, FogSettings, ScreenSpaceAmbientOcclusionQualityLevel}, - prelude::*, - render::{ - color::Color, - view::{ColorGrading, Msaa}, - }, - }; - use serde::Deserialize; + use super::*; #[derive(Debug, Deserialize)] pub enum TweakTonemapping { diff --git a/src/game.rs b/src/game.rs index 6040176..fc07ada 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,7 +1,3 @@ -use bevy::app::AppExit; -use bevy::utils::HashSet; - -use crate::audio::AudioEvent; use crate::prelude::*; pub(crate) struct GamePlugin; @@ -10,13 +6,13 @@ impl Plugin for GamePlugin { fn build(&self, app: &mut App) { app.add_event::() .add_event::() - .add_state::() + .init_state::() .insert_resource(Score { ..default() }) .add_systems(Startup, setup_board) .add_systems(OnEnter(GameState::Play), hide_valid_moves) .add_systems( Update, - manage_state_entities::().run_if(state_changed::()), + manage_state_entities::().run_if(state_changed::), ) .add_systems( Update, @@ -30,8 +26,8 @@ impl Plugin for GamePlugin { show_valid_moves.run_if(any_component_added::()), hide_valid_moves.run_if(any_component_removed::()), manage_score.run_if(any_component_added::()), - check_endgame.run_if(resource_changed::()), - reset_game.run_if(just_pressed(KeyCode::R)), + check_endgame.run_if(resource_changed::), + reset_game.run_if(just_pressed(KeyCode::KeyR)), ), ) .add_systems(OnEnter(GameState::Endgame), set_endgame.after(manage_score)) @@ -44,7 +40,7 @@ impl Plugin for GamePlugin { ) .add_systems( PostUpdate, - (debug_board.run_if(resource_exists::()),), + (debug_board.run_if(resource_exists::),), ) .add_systems(OnEnter(GameState::Restart), handle_restart) .add_systems(OnEnter(GameState::Quit), handle_quit); @@ -829,7 +825,9 @@ fn handle_selection( // De-select the piece info!("Applying moves {:?}", moves); if !(*done) { - moves.iter().for_each(|m| move_events.send(m.clone())); + moves.iter().for_each(|m| { + move_events.send(m.clone()); + }); *done = true; } } diff --git a/src/hit.rs b/src/hit.rs index 15fabe7..a832a44 100644 --- a/src/hit.rs +++ b/src/hit.rs @@ -1,8 +1,3 @@ -use bevy::render::{ - mesh::{MeshVertexAttribute, VertexAttributeValues}, - render_resource::VertexFormat, -}; - use crate::prelude::*; /// Hit data for 2d sprites @@ -32,6 +27,12 @@ impl Triangle { (self.edge_a()).cross(self.edge_b()) } + fn normal_plane(&self) -> Plane3d { + Plane3d { + normal: Direction3d::new(self.normal()).expect("Valid normal direction"), + } + } + fn edge_a(&self) -> Vec3 { self.v1 - self.v0 } @@ -56,7 +57,7 @@ impl Triangle { /// Heavily synthesized from these two resources: /// * Textbook: https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/ray-triangle-intersection-geometric-solution.html /// * Example: https://github.com/aevyrie/bevy_mod_raycast/blob/435d8ef100738797161ac3a9b910ea346a4ed6e6/src/raycast.rs#L43 -pub(crate) fn intersects3d(ray: &Ray, mesh: &Mesh, gt: &GlobalTransform) -> Option { +pub(crate) fn intersects3d(ray: &Ray3d, mesh: &Mesh, gt: &GlobalTransform) -> Option { let attr = MeshVertexAttribute::new("Vertex_Position", 0, VertexFormat::Float32x3); if let Some(verts) = mesh.attribute(attr) { if let Some(idxs) = mesh.indices() { @@ -84,7 +85,9 @@ pub(crate) fn intersects3d(ray: &Ray, mesh: &Mesh, gt: &GlobalTransform) -> Opti .map(|[v0, v1, v2]| Triangle { v0, v1, v2 }) .filter_map(|triangle| { // Calculate the distance this ray hits the plane normal to the tri - if let Some(d) = ray.intersect_plane(triangle.v0, triangle.normal()) { + if let Some(d) = + ray.intersect_plane(triangle.v0, triangle.normal_plane()) + { // Calculate the point on that plane which intersects let p = ray.get_point(d); // Inside out test diff --git a/src/intro.rs b/src/intro.rs index d360fca..4f91fdd 100644 --- a/src/intro.rs +++ b/src/intro.rs @@ -1,5 +1,3 @@ -use bevy::core::FrameCount; - use crate::prelude::*; pub(crate) struct IntroPlugin; @@ -10,7 +8,7 @@ impl Plugin for IntroPlugin { .add_systems( OnExit(GameState::Loading), init_intro_text - .run_if(resource_exists::()) + .run_if(resource_exists::) .run_if(run_once()), ) .add_systems(OnEnter(GameState::Intro), manage_intro) @@ -24,12 +22,12 @@ impl Plugin for IntroPlugin { // Updated for as long as there is scrolling text manage_scroll_text_animation.run_if( any_component_added::() - .or_else(just_pressed(KeyCode::Return)) + .or_else(just_pressed(KeyCode::Enter)) .or_else(just_pressed(MouseButton::Left)), ), // Play intro manages playing the intro of each individual paragraph // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated - scroll_text.run_if(any_with_component::()), + scroll_text.run_if(any_with_component::), ) .run_if(in_state(GameState::Intro)), ); @@ -108,7 +106,7 @@ fn init_intro_text( }, }) .collect(), - alignment: TextAlignment::Center, + justify: JustifyText::Center, ..default() }, ..default() @@ -239,8 +237,8 @@ fn scroll_text( tweaks_file: Res, tweaks: Res>, time: Res