From 5cd9a3d0f5a15b4baabeea87b58633a2db84bf32 Mon Sep 17 00:00:00 2001 From: Idan Arye Date: Fri, 13 Dec 2024 04:13:18 +0200 Subject: [PATCH] Remove `TnuaControllerBundle` --- CHANGELOG.md | 4 ++++ demos/src/bin/platformer_2d.rs | 11 +++-------- demos/src/bin/platformer_3d.rs | 11 +++-------- demos/src/bin/shooter_like.rs | 11 +++-------- examples/example.rs | 4 ++-- examples/example_animating.rs | 4 ++-- src/controller.rs | 13 +------------ src/lib.rs | 16 ++++++++-------- 8 files changed, 26 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4773a3398..1631a96eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ NOTE: Subcrates have their own changelogs: [bevy-tnua-physics-integration-layer] ### Changed - Upgrade to Bevy 0.15. +### Removed +- `TnuaControllerBundle`. It is no longer needed since `TnuaController` uses + Bevy 0.15's required components feature. + ## 0.20.0 - 2024-10-12 ### Added - A `TnuaBuiltinKnockback` action for applying knockback that will not be diff --git a/demos/src/bin/platformer_2d.rs b/demos/src/bin/platformer_2d.rs index ed91072b9..550f7e4fb 100644 --- a/demos/src/bin/platformer_2d.rs +++ b/demos/src/bin/platformer_2d.rs @@ -176,15 +176,10 @@ fn setup_player(mut commands: Commands) { // Avian does not need an "IO" bundle. } - // This bundle container `TnuaController` - the main interface of Tnua with the user code - as - // well as the main components used as API between the main plugin and the physics backend - // integration. These components (and the IO bundle, in case of backends that need one like - // Rapier) are the only mandatory Tnua components - but this example will also add some - // components used for more advanced features. - // - // Read examples/src/character_control_systems/platformer_control_systems.rs to see how + // `TnuaController` is Tnua's main interface with the user code. Read + // examples/src/character_control_systems/platformer_control_systems.rs to see how // `TnuaController` is used in this example. - cmd.insert(TnuaControllerBundle::default()); + cmd.insert(TnuaController::default()); cmd.insert(CharacterMotionConfigForPlatformerDemo { dimensionality: Dimensionality::Dim2, diff --git a/demos/src/bin/platformer_3d.rs b/demos/src/bin/platformer_3d.rs index 25326e20b..81b534f23 100644 --- a/demos/src/bin/platformer_3d.rs +++ b/demos/src/bin/platformer_3d.rs @@ -188,15 +188,10 @@ fn setup_player(mut commands: Commands, asset_server: Res) { // Avian does not need an "IO" bundle. } - // This bundle container `TnuaController` - the main interface of Tnua with the user code - as - // well as the main components used as API between the main plugin and the physics backend - // integration. These components (and the IO bundle, in case of backends that need one like - // Rapier) are the only mandatory Tnua components - but this example will also add some - // components used for more advanced features. - // - // Read examples/src/character_control_systems/platformer_control_systems.rs to see how + // `TnuaController` is Tnua's main interface with the user code. Read + // examples/src/character_control_systems/platformer_control_systems.rs to see how // `TnuaController` is used in this example. - cmd.insert(TnuaControllerBundle::default()); + cmd.insert(TnuaController::default()); cmd.insert(CharacterMotionConfigForPlatformerDemo { dimensionality: Dimensionality::Dim3, diff --git a/demos/src/bin/shooter_like.rs b/demos/src/bin/shooter_like.rs index 96a049776..a772254f3 100644 --- a/demos/src/bin/shooter_like.rs +++ b/demos/src/bin/shooter_like.rs @@ -191,15 +191,10 @@ fn setup_player(mut commands: Commands, asset_server: Res) { // Avian does not need an "IO" bundle. } - // This bundle container `TnuaController` - the main interface of Tnua with the user code - as - // well as the main components used as API between the main plugin and the physics backend - // integration. These components (and the IO bundle, in case of backends that need one like - // Rapier) are the only mandatory Tnua components - but this example will also add some - // components used for more advanced features. - // - // Read examples/src/character_control_systems/platformer_control_systems.rs to see how + // `TnuaController` is Tnua's main interface with the user code. Read + // examples/src/character_control_systems/platformer_control_systems.rs to see how // `TnuaController` is used in this example. - cmd.insert(TnuaControllerBundle::default()); + cmd.insert(TnuaController::default()); cmd.insert(CharacterMotionConfigForPlatformerDemo { dimensionality: Dimensionality::Dim3, diff --git a/examples/example.rs b/examples/example.rs index ed9561233..0b4c2d295 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -83,8 +83,8 @@ fn setup_player( // engine. RigidBody::Dynamic, Collider::capsule(0.5, 1.0), - // This bundle holds the main components. - TnuaControllerBundle::default(), + // This is Tnua's interface component. + TnuaController::default(), // A sensor shape is not strictly necessary, but without it we'll get weird results. TnuaAvian3dSensorShape(Collider::cylinder(0.49, 0.0)), // Tnua can fix the rotation, but the character will still get rotated before it can do so. diff --git a/examples/example_animating.rs b/examples/example_animating.rs index e5a6e8515..1dd636c51 100644 --- a/examples/example_animating.rs +++ b/examples/example_animating.rs @@ -111,8 +111,8 @@ fn setup_player(mut commands: Commands, asset_server: Res) { // engine. RigidBody::Dynamic, Collider::capsule(0.5, 1.0), - // This bundle holds the main components. - TnuaControllerBundle::default(), + // This is Tnua's interface component. + TnuaController::default(), // A sensor shape is not strictly necessary, but without it we'll get weird results. TnuaAvian3dSensorShape(Collider::cylinder(0.49, 0.0)), // Tnua can fix the rotation, but the character will still get rotated before it can do so. diff --git a/src/controller.rs b/src/controller.rs index 913127e13..e4ebfa206 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -57,18 +57,6 @@ impl Plugin for TnuaControllerPlugin { } } -/// All the Tnua components needed to run a floating character controller. -/// -/// Note that this bundle only contains components defined by Tnua. The components of the physics -/// backend that turn the entity into a dynamic rigid body must be added separately. -#[derive(Default, Bundle)] -pub struct TnuaControllerBundle { - pub controller: TnuaController, - pub motor: TnuaMotor, - pub rigid_body_tracker: TnuaRigidBodyTracker, - pub proximity_sensor: TnuaProximitySensor, -} - struct FedEntry { fed_this_frame: bool, rescheduled_in: Option, @@ -97,6 +85,7 @@ struct FedEntry { /// /// Without [`TnuaControllerPlugin`] this component will not do anything. #[derive(Component, Default)] +#[require(TnuaMotor, TnuaRigidBodyTracker, TnuaProximitySensor)] pub struct TnuaController { current_basis: Option<(&'static str, Box)>, actions_being_fed: HashMap<&'static str, FedEntry>, diff --git a/src/lib.rs b/src/lib.rs index 0ffd22f34..eee89bce0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,8 +34,8 @@ //! where it should usually be registered) //! //! A Tnua controlled character must have a dynamic rigid body, everything from -//! `TnuaIOBundle` (e.g. - for Rapier 3D, use `TnuaRapier3dIOBundle`), and -//! everything from [`TnuaControllerBundle`](prelude::TnuaControllerBundle): +//! `TnuaIOBundle` (e.g. - for Rapier 3D, use `TnuaRapier3dIOBundle`), and a +//! [`TnuaController`](prelude::TnuaController) (and its automatically added required component): //! ```no_run //! # use bevy::prelude::*; //! # // Not importing from Rapier because there are two versions and the default features does not @@ -48,7 +48,7 @@ //! # let mut cmd = commands.spawn_empty(); //! cmd.insert(RigidBody::Dynamic); //! cmd.insert(TnuaRapier3dIOBundle::default()); // this one depends on the physics backend -//! cmd.insert(TnuaControllerBundle::default()); +//! cmd.insert(TnuaController::default()); //! ``` //! Typically though it'd also include a `Collider`. //! @@ -70,10 +70,10 @@ //! //! ## Controlling the Character //! -//! To control the character, update the [`TnuaController`](prelude::TnuaController) (added via tha -//! [`TnuaControllerBundle`](prelude::TnuaControllerBundle)) by feeding it a [basis](TnuaBasis) and -//! zero or more [actions](TnuaAction). For some of the advanced features to work, the system that -//! does this needs to be placed inside the [`TnuaUserControlsSystemSet`] system set. +//! To control the character, update the [`TnuaController`](prelude::TnuaController) by feeding it +//! a [basis](TnuaBasis) and zero or more [actions](TnuaAction). For some of the advanced features +//! to work, the system that does this needs to be placed inside the [`TnuaUserControlsSystemSet`] +//! system set. //! //! ```no_run //! # use bevy::prelude::*; @@ -140,7 +140,7 @@ pub use basis_action_traits::{ pub mod prelude { pub use crate::builtins::{TnuaBuiltinJump, TnuaBuiltinWalk}; - pub use crate::controller::{TnuaController, TnuaControllerBundle, TnuaControllerPlugin}; + pub use crate::controller::{TnuaController, TnuaControllerPlugin}; pub use crate::{TnuaAction, TnuaPipelineStages, TnuaUserControlsSystemSet}; }