Skip to content

Commit

Permalink
Rename ActionBind::with_axis2d into ActionBind::with_xy_axis
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Oct 24, 2024
1 parent f9e6892 commit 841aa92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Remove world access from conditions and modifiers. This means that you no longer can write game-specific conditions or modifiers. But it's much nicer (and faster) to just do it in observers instead.
- Values from `Input` are now converted to the action-level dimension only after applying all input-level modifiers and conditions. This allows things like mapping the Y-axis of `ActionValue::Axis2D` into an action with `ActionValueDim::Axis1D`.
- Rename `ActionBind::with_axis2d` into `ActionBind::with_xy_axis`.
- Modifiers are now allowed to change passed value dimensions.
- All built-in modifiers now handle values of any dimention.
- Replace `with_held_timer` with `relative_speed` that just accepts a boolean.
Expand Down
24 changes: 15 additions & 9 deletions src/input_context/context_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,21 @@ impl ActionBind {

/// Maps WASD keys as 2-dimentional input.
///
/// See also [`Self::with_axis2d`].
/// In Bevy's 3D space, the -Z axis points forward and the +Z axis points
/// toward the camera. To map movement correctly in 3D space, you will
/// need to invert Y and apply it to Z translation inside your observer.
///
/// Shorthand for [`Self::with_xy_axis`].
pub fn with_wasd(&mut self) -> &mut Self {
self.with_axis2d(KeyCode::KeyW, KeyCode::KeyA, KeyCode::KeyS, KeyCode::KeyD)
self.with_xy_axis(KeyCode::KeyW, KeyCode::KeyA, KeyCode::KeyS, KeyCode::KeyD)
}

/// Maps keyboard arrow keys as 2-dimentional input.
///
/// See also [`Self::with_axis2d`].
/// Shorthand for [`Self::with_xy_axis`].
/// See also [`Self::with_wasd`].
pub fn with_arrows(&mut self) -> &mut Self {
self.with_axis2d(
self.with_xy_axis(
KeyCode::ArrowUp,
KeyCode::ArrowLeft,
KeyCode::ArrowDown,
Expand All @@ -151,23 +156,24 @@ impl ActionBind {

/// Maps D-pad as 2-dimentional input.
///
/// See also [`Self::with_axis2d`].
/// Shorthand for [`Self::with_xy_axis`].
/// See also [`Self::with_wasd`].
pub fn with_dpad(&mut self) -> &mut Self {
self.with_axis2d(
self.with_xy_axis(
GamepadButtonType::DPadUp,
GamepadButtonType::DPadLeft,
GamepadButtonType::DPadDown,
GamepadButtonType::DPadRight,
)
}

/// Maps 4 keys as 2-dimentional input.
/// Maps 4 buttons as 2-dimentional input.
///
/// This is a convenience "preset" that uses [`SwizzleAxis`] and [`Negate`] to
/// bind the keys to cardinal directions.
/// bind the buttons to X and Y axes.
///
/// The order of arguments follows the common "WASD" mapping.
pub fn with_axis2d<I: Into<Input>>(&mut self, up: I, left: I, down: I, right: I) -> &mut Self {
pub fn with_xy_axis<I: Into<Input>>(&mut self, up: I, left: I, down: I, right: I) -> &mut Self {
self.with(InputBind::new(up).with_modifier(SwizzleAxis::YXZ))
.with(InputBind::new(left).with_modifier(Negate::default()))
.with(
Expand Down

0 comments on commit 841aa92

Please sign in to comment.