Skip to content

Commit

Permalink
Remove TnuaControllerBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
idanarye committed Dec 13, 2024
1 parent 8144a25 commit 5cd9a3d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions demos/src/bin/platformer_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions demos/src/bin/platformer_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,10 @@ fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
// 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,
Expand Down
11 changes: 3 additions & 8 deletions demos/src/bin/shooter_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,10 @@ fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
// 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,
Expand Down
4 changes: 2 additions & 2 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/example_animating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
// 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.
Expand Down
13 changes: 1 addition & 12 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Timer>,
Expand Down Expand Up @@ -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<dyn DynamicBasis>)>,
actions_being_fed: HashMap<&'static str, FedEntry>,
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
//! where it should usually be registered)
//!
//! A Tnua controlled character must have a dynamic rigid body, everything from
//! `Tnua<physics-backend>IOBundle` (e.g. - for Rapier 3D, use `TnuaRapier3dIOBundle`), and
//! everything from [`TnuaControllerBundle`](prelude::TnuaControllerBundle):
//! `Tnua<physics-backend>IOBundle` (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
Expand All @@ -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`.
//!
Expand All @@ -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::*;
Expand Down Expand Up @@ -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};
}

Expand Down

0 comments on commit 5cd9a3d

Please sign in to comment.