Skip to content

Commit

Permalink
Apply suggestions from grammar check (#486)
Browse files Browse the repository at this point in the history
* Apply suggestions from grammar check

* Possessive

* Revert incorrect suggestion

* Clearer language for UserInput

---------

Co-authored-by: Alice Cecile <[email protected]>
  • Loading branch information
Shute052 and alice-i-cecile authored Feb 22, 2024
1 parent b3e792a commit cd7f795
Show file tree
Hide file tree
Showing 27 changed files with 107 additions and 94 deletions.
2 changes: 1 addition & 1 deletion benches/input_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
});
let mut which_pressed_group = c.benchmark_group("which_pressed");

// Constructing our test app / input stream outside of the timed benchmark
// Constructing our test app / input stream outside the timed benchmark
let mut app = App::new();
app.add_plugins(InputPlugin);
app.send_input(KeyCode::KeyA);
Expand Down
2 changes: 1 addition & 1 deletion examples/arpg_indirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
PreUpdate,
copy_action_state.after(InputManagerSystem::ManualControl),
)
// Try it out, using QWER / left click / right click!
// Try it out, using QWER / left-click / right-click!
.add_systems(Update, report_abilities_used)
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/axis_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn spawn_player(mut commands: Commands) {
.insert(Action::Move, DualAxis::left_stick())
// Let's bind the right gamepad trigger to the throttle action
.insert(Action::Throttle, GamepadButtonType::RightTrigger2)
// And we'll use the right stick's x axis as a rudder control
// And we'll use the right stick's x-axis as a rudder control
.insert(
// This will trigger if the axis is moved 10% or more in either direction.
Action::Rudder,
Expand Down
10 changes: 6 additions & 4 deletions examples/consuming_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
.add_systems(Update, report_menus)
.add_systems(Update, open_main_menu)
.add_systems(Update, open_sub_menu)
// We want to ensure that if both the main menu and submenu are open
// We want to ensure that if both the main menu and submenu are open,
// only the submenu is closed if the user hits (or holds) Escape
.add_systems(Update, close_menu::<SubMenu>.before(close_menu::<MainMenu>))
// We can do this by ordering our systems and using `ActionState::consume`
Expand Down Expand Up @@ -67,8 +67,9 @@ fn open_sub_menu(action_state: Res<ActionState<MenuAction>>, mut menu_state: Res
}
}

// We want to be sure that e.g. the submenu is closed in preference to the main menu if both are open
// If you can, use a real focus system for this logic, but workarounds of this sort are necessary in bevy_egui
// We want to ensure that, e.g., the submenu is closed in preference to the main menu if both are open.
// If you can, use a real focus system for this logic.
// However, workarounds of this sort are necessary in bevy_egui
// as it is an immediate mode UI library
fn close_menu<M: Resource + Menu>(
mut action_state: ResMut<ActionState<MenuAction>>,
Expand All @@ -77,7 +78,7 @@ fn close_menu<M: Resource + Menu>(
if action_state.pressed(&MenuAction::CloseWindow) && menu_status.is_open() {
println!("Closing the top window, as requested.");
menu_status.close();
// Because the action is consumed, further systems won't see this action as pressed
// Because the action is consumed, further systems won't see this action as pressed,
// and it cannot be pressed again until after the next time it would be released.
action_state.consume(&MenuAction::CloseWindow);
}
Expand All @@ -86,6 +87,7 @@ fn close_menu<M: Resource + Menu>(
// A quick mock of some UI behavior for demonstration purposes
mod menu_mocking {
use bevy::prelude::Resource;

pub trait Menu {
fn is_open(&self) -> bool;

Expand Down
8 changes: 4 additions & 4 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn setup(mut commands: Commands) {
// This will return a binary button-like output.
.insert(CameraMovement::PanLeft, MouseWheelDirection::Left)
.insert(CameraMovement::PanRight, MouseWheelDirection::Right)
// Alternatively, you could model this as a virtual Dpad,
// which is extremely useful when you want to model 4-directional buttonlike inputs using the mouse wheel
// Alternatively, you could model this as a virtual Dpad.
// It's extremely useful for modeling 4-directional button-like inputs with the mouse wheel
// .insert(VirtualDpad::mouse_wheel(), Pan)
// Or even a continuous `DualAxis`!
// .insert(DualAxis::mouse_wheel(), Pan)
Expand All @@ -53,9 +53,9 @@ fn zoom_camera(
// Up and right axis movements are always positive by default
let zoom_delta = action_state.value(&CameraMovement::Zoom);

// We want to zoom in when we use mouse wheel up
// We want to zoom in when we use mouse wheel up,
// so we increase the scale proportionally
// Note that the projections scale should always be positive (or our images will flip)
// Note that the projection's scale should always be positive (or our images will flip)
camera_projection.scale *= 1. - zoom_delta * CAMERA_ZOOM_RATE;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/multiplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl PlayerBundle {
// you should coordinate with the `Gamepads` resource to determine the correct gamepad for each player
// and gracefully handle disconnects
// Note that this step is not required:
// if it is skipped all input maps will read from all connected gamepads
// if it is skipped, all input maps will read from all connected gamepads
.set_gamepad(Gamepad { id: 0 })
.build(),
Player::Two => InputMap::new([
Expand Down
2 changes: 1 addition & 1 deletion examples/register_gamepads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn join(
if button_inputs.pressed(GamepadButton::new(gamepad, GamepadButtonType::LeftTrigger))
&& button_inputs.pressed(GamepadButton::new(gamepad, GamepadButtonType::RightTrigger))
{
// Make sure a player can not join twice
// Make sure a player cannot join twice
if !joined_players.0.contains_key(&gamepad) {
println!("Player {} has joined the game!", gamepad.id);

Expand Down
8 changes: 4 additions & 4 deletions examples/send_actions_over_network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! [`ActionDiff`] event streams are minimalistic representations
//! of the action state, intended for serialization and networking
//! [`ActionDiff`] event streams are minimalistic representations of the action state,
//! intended for serialization and networking.
//! While they are less convenient to work with than the complete [`ActionState`],
//! they are much smaller, and can be created from and reconstructed into [`ActionState`]
//!
Expand Down Expand Up @@ -66,7 +66,7 @@ fn main() {
.add_event::<ActionDiffEvent<FpsAction>>()
// Reads in the event stream of `ActionDiffs` to update the `ActionState`
.add_systems(PreUpdate, process_action_diffs::<FpsAction>)
// Typically, the rest of this information would synchronized as well
// Typically, the rest of this information would synchronize as well
.add_systems(Startup, spawn_player);

// Starting up the game
Expand Down Expand Up @@ -140,7 +140,7 @@ fn spawn_player(mut commands: Commands) {
/// The events are sent directly;
/// in real applications they would be serialized to a networking protocol instead.
///
/// The [`ManualEventReader`] returned must be reused in order to avoid double-sending events
/// The [`ManualEventReader`] returned must be reused to avoid double-sending events
#[must_use]
fn send_events<A: Send + Sync + 'static + Debug + Clone + Event>(
client_app: &App,
Expand Down
9 changes: 5 additions & 4 deletions examples/twin_stick_controller.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! This is a fairly complete example that implements a twin stick controller.
//!
//! The controller supports both gamepad/MKB input and switches between them depending on
//! The controller supports both gamepad/MKB inputs and switches between them depending on
//! the most recent input.
//!
//! This example builds on top of several of the concepts introduced in other examples. In particular,
//! This example builds on top of several concepts introduced in other examples. In particular,
//! the `default_controls`. `mouse_position`, and `action_state_resource` examples.
use bevy::{
Expand Down Expand Up @@ -150,7 +150,7 @@ fn player_mouse_look(
.expect("Need a single primary window");

// Many steps can fail here, so we'll wrap in an option pipeline
// First check if cursor is in window
// First check if the cursor is in window
// Then check if the ray intersects the plane defined by the player
// Then finally compute the point along the ray to look at
if let Some(p) = window
Expand All @@ -169,7 +169,8 @@ fn player_mouse_look(
let Some(action_data) = action_state.action_data_mut(&PlayerAction::Look) else {
return;
};
// Flipping y sign here to be consistent with gamepad input. We could also invert the gamepad y axis
// Flipping y sign here to be consistent with gamepad input.
// We could also invert the gamepad y-axis
action_data.axis_pair = Some(DualAxisData::from_xy(Vec2::new(diff.x, -diff.y)));
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/action_diff.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Serialization-friendly representation of changes to [`ActionState`](crate::action_state::ActionState).
//!
//! These are predominantly intended for use in networked games, where the server needs to know what the players are doing,
//! and would like a compact, semantically-meaningful representation of the changes to the game state without needing to know
//! These are predominantly intended for use in networked games,
//! where the server needs to know what the players are doing.
//! They would like a compact, semantically meaningful representation of the changes to the game state without needing to know
//! about things like keybindings or input devices.
use bevy::{
Expand All @@ -15,7 +16,7 @@ use crate::Actionlike;
/// Stores presses and releases of buttons without timing information
///
/// These are typically accessed using the `Events<ActionDiffEvent>` resource.
/// Uses a minimal storage format, in order to facilitate transport over the network.
/// Uses a minimal storage format to facilitate transport over the network.
///
/// An `ActionState` can be fully reconstructed from a stream of `ActionDiff`.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/action_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::Actionlike;
/// # Examples
///
/// By default, [`update_action_state_from_interaction`](crate::systems::update_action_state_from_interaction) uses this component
/// in order to connect `bevy::ui` buttons to the corresponding `ActionState`.
/// to connect `bevy::ui` buttons to the corresponding `ActionState`.
///
/// ```rust
/// use bevy::prelude::*;
Expand Down
12 changes: 6 additions & 6 deletions src/action_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<A: Actionlike> ActionState<A> {
/// assert!(action_state.released(&Action::Jump));
/// assert!(!action_state.just_released(&Action::Run));
///
/// // Ticking time moves causes buttons that were just released to no longer be just released
/// // Ticking time moves causes buttons just released to no longer be just released
/// let t0 = Instant::now();
/// let t1 = Instant::now();
///
Expand All @@ -164,7 +164,7 @@ impl<A: Actionlike> ActionState<A> {
/// action_state.press(&Action::Jump);
/// assert!(action_state.just_pressed(&Action::Jump));
///
/// // Ticking time moves causes buttons that were just pressed to no longer be just pressed
/// // Ticking time moves causes buttons just pressed to no longer be just pressed
/// let t2 = Instant::now();
///
/// action_state.tick(t2, t1);
Expand All @@ -184,7 +184,7 @@ impl<A: Actionlike> ActionState<A> {
});
}

/// A reference to the [`ActionData`] of the corresponding `action` if populated.
/// A reference of the [`ActionData`] corresponding to the `action` if populated.
///
/// Generally, it'll be clearer to call `pressed` or so on directly on the [`ActionState`].
/// However, accessing the raw data directly allows you to examine detailed metadata holistically.
Expand All @@ -194,7 +194,7 @@ impl<A: Actionlike> ActionState<A> {
self.action_data.get(action)
}

/// A mutable reference of the [`ActionData`] of the corresponding `action` if populated.
/// A mutable reference of the [`ActionData`] corresponding to the `action` if populated.
///
/// Generally, it'll be clearer to call `pressed` or so on directly on the [`ActionState`].
/// However, accessing the raw data directly allows you to examine detailed metadata holistically.
Expand All @@ -204,7 +204,7 @@ impl<A: Actionlike> ActionState<A> {
self.action_data.get_mut(action)
}

/// A mutable reference of the [`ActionData`] of the corresponding `action`.
/// A mutable reference of the [`ActionData`] corresponding to the `action`.
///
/// Generally, it'll be clearer to call `pressed` or so on directly on the [`ActionState`].
/// However, accessing the raw data directly allows you to examine detailed metadata holistically.
Expand Down Expand Up @@ -516,7 +516,7 @@ impl<A: Actionlike> ActionState<A> {
///
/// If the action was pressed or released since the last time [`ActionState::tick`] was called
/// the value will be [`None`].
/// This ensures that all of our actions are assigned a timing and duration
/// This ensures that all our actions are assigned a timing and duration
/// that corresponds exactly to the start of a frame, rather than relying on idiosyncratic timing.
///
/// This will also be [`None`] if the action was never pressed or released.
Expand Down
18 changes: 10 additions & 8 deletions src/axislike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ impl PartialEq for SingleAxis {
&& FloatOrd(self.sensitivity) == FloatOrd(other.sensitivity)
}
}

impl Eq for SingleAxis {}

impl std::hash::Hash for SingleAxis {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.axis_type.hash(state);
Expand Down Expand Up @@ -318,7 +320,7 @@ impl DualAxis {
}
}

#[allow(clippy::doc_markdown)] // False alarm because it thinks DPad is an un-quoted item
#[allow(clippy::doc_markdown)] // False alarm because it thinks DPad is an unquoted item
/// A virtual DPad that you can get an [`DualAxis`] from.
///
/// Typically, you don't want to store a [`DualAxis`] in this type,
Expand Down Expand Up @@ -363,7 +365,7 @@ impl VirtualDPad {
}
}

#[allow(clippy::doc_markdown)] // False alarm because it thinks DPad is an un-quoted item
#[allow(clippy::doc_markdown)] // False alarm because it thinks DPad is an unquoted item
/// Generates a [`VirtualDPad`] corresponding to the DPad on a gamepad
pub const fn dpad() -> VirtualDPad {
VirtualDPad {
Expand All @@ -376,7 +378,8 @@ impl VirtualDPad {

/// Generates a [`VirtualDPad`] corresponding to the face buttons on a gamepad
///
/// North corresponds to up, west corresponds to left, east corresponds to right, south corresponds to down
/// North corresponds to up, west corresponds to left,
/// east corresponds to right, and south corresponds to down
pub const fn gamepad_face_buttons() -> VirtualDPad {
VirtualDPad {
up: InputKind::GamepadButton(GamepadButtonType::North),
Expand Down Expand Up @@ -488,7 +491,6 @@ impl VirtualAxis {
}
}

#[allow(clippy::doc_markdown)]
/// Generates a [`VirtualAxis`] corresponding to the horizontal gamepad face buttons.
pub const fn horizontal_gamepad_face_buttons() -> VirtualAxis {
VirtualAxis {
Expand All @@ -497,7 +499,6 @@ impl VirtualAxis {
}
}

#[allow(clippy::doc_markdown)]
/// Generates a [`VirtualAxis`] corresponding to the vertical gamepad face buttons.
pub const fn vertical_gamepad_face_buttons() -> VirtualAxis {
VirtualAxis {
Expand Down Expand Up @@ -527,7 +528,7 @@ pub enum AxisType {
MouseMotion(MouseMotionAxisType),
}

/// The direction of motion of the mouse wheel.
/// The motion direction of the mouse wheel.
///
/// Stored in the [`AxisType`] enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect)]
Expand All @@ -542,7 +543,7 @@ pub enum MouseWheelAxisType {
Y,
}

/// The direction of motion of the mouse.
/// The motion direction of the mouse.
///
/// Stored in the [`AxisType`] enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect)]
Expand Down Expand Up @@ -731,7 +732,7 @@ impl From<DualAxisData> for Vec2 {
/// If the size of a shape is 0.0, then all input values are read, except for 0.0.
///
/// All inputs are scaled to be continuous.
/// So with an ellipse deadzone of a radius of 0.1, the input range `0.1..=1.0` will be scaled to `0.0..=1.0`.
/// So with an ellipse deadzone with a radius of 0.1, the input range `0.1..=1.0` will be scaled to `0.0..=1.0`.
///
/// Deadzone values should be in the range `0.0..=1.0`.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Reflect)]
Expand Down Expand Up @@ -760,6 +761,7 @@ pub enum DeadZoneShape {
}

impl Eq for DeadZoneShape {}

impl std::hash::Hash for DeadZoneShape {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
match self {
Expand Down
8 changes: 4 additions & 4 deletions src/buttonlike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use serde::{Deserialize, Serialize};
/// By default, buttons are [`ButtonState::Released`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, Default)]
pub enum ButtonState {
/// The button was pressed since the most recent tick
/// The button has been pressed since the most recent tick
JustPressed,
/// This button is currently pressed (and was pressed before the most recent tick)
Pressed,
/// The button was released since the most recent tick
/// The button has been released since the most recent tick
JustReleased,
/// This button is currently released (and was released before the most recent tick)
#[default]
Expand Down Expand Up @@ -69,14 +69,14 @@ impl ButtonState {
*self == ButtonState::Released || *self == ButtonState::JustReleased
}

/// Was the button pressed since the last time [`ActionState::update`](crate::action_state::ActionState::update) was called?
/// Has the button been pressed since the last time [`ActionState::update`](crate::action_state::ActionState::update) was called?
#[inline]
#[must_use]
pub fn just_pressed(&self) -> bool {
*self == ButtonState::JustPressed
}

/// Was the button released since the last time [`ActionState::update`](crate::action_state::ActionState::update) was called?
/// Has the button been released since the last time [`ActionState::update`](crate::action_state::ActionState::update) was called?
#[inline]
#[must_use]
pub fn just_released(&self) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions src/clashing_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::cmp::Ordering;
/// How should clashing inputs by handled by an [`InputMap`]?
///
/// Inputs "clash" if and only if one [`UserInput`] is a strict subset of the other.
/// By example:
/// For example:
///
/// - `S` and `W`: does not clash
/// - `ControlLeft + S` and `S`: clashes
Expand Down Expand Up @@ -227,13 +227,13 @@ fn chord_chord_clash(chord_a: &Vec<InputKind>, chord_b: &Vec<InputKind>) -> bool
fn check_clash<A: Actionlike>(clash: &Clash<A>, input_streams: &InputStreams) -> Option<Clash<A>> {
let mut actual_clash: Clash<A> = clash.clone();

// For all inputs that were actually pressed that match action A
// For all inputs actually pressed that match action A
for input_a in clash
.inputs_a
.iter()
.filter(|&input| input_streams.input_pressed(input))
{
// For all inputs that were actually pressed that match action B
// For all inputs actually pressed that match action B
for input_b in clash
.inputs_b
.iter()
Expand Down
Loading

0 comments on commit cd7f795

Please sign in to comment.