Skip to content

Commit

Permalink
doc: Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanecelis committed Apr 21, 2024
1 parent a123326 commit e96d769
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bevy-input-sequence

This crate recognizes input sequences.
This crate recognizes input sequences from keyboard and gamepad.

# Use Cases

Expand All @@ -16,12 +16,18 @@ cargo install bevy-input-sequence

# Code Examples

Here are some code snippets. These also run as doctests so they are not quite
runnable examples, but those are described in the next section.
Here are some code snippets. These also run as doctests so they do a few things
differently than a regular runnable example:

## Run a System
- Use `MinimalPlugins` instead of `DefaultPlugins`,
- and call `app.update()` instead of `app.run()`.

Runs a system whenever the user presses the key sequence "hi" within a time limit.
The next section describes the runnable examples that come with the crate.

## Run a System on a Key Sequence

Runs a system whenever the user presses the key sequence `H I` or "hi" within a
time limit.

```rust
use bevy::prelude::*;
Expand All @@ -37,19 +43,22 @@ fn main() {

fn setup(mut commands: Commands) {
commands.add(
KeySequence::new(say_hi,
KeySequence::new(say_hello,
keyseq! { H I })
.time_limit(Duration::from_secs(2))
);
}

fn say_hi() {
fn say_hello() {
info!("hello");
}
```

## Send an Event on Key Sequence

Originally `bevy-input-sequence` always send an event. You can still do that
with the `action::send_event()`.

```rust
use bevy::prelude::*;
use bevy_input_sequence::prelude::*;
Expand Down Expand Up @@ -84,6 +93,10 @@ fn check_events(mut events: EventReader<MyEvent>) {

## Send an Event on Gamepad Button Sequence

Gamepads have something that keyboards don't: identity problems. Which player
hit the button sequence may be important to know. So the systems it accepts will
take an input of `Gamepad`.

```rust
use bevy::prelude::*;
use bevy_input_sequence::prelude::*;
Expand Down Expand Up @@ -187,9 +200,9 @@ cargo run --example run_if

| bevy-input-sequence | bevy |
| ------------------- | ---- |
| 0.1 | 0.11 |
| 0.2 | 0.12 |
| 0.3 | 0.13 |
| 0.2 | 0.12 |
| 0.1 | 0.11 |

# License

Expand Down
12 changes: 7 additions & 5 deletions src/action.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Common actions to do on key sequence matches
use bevy::ecs::{
event::{Event, EventWriter},
system::In,
use bevy::{
ecs::{
event::{Event, EventWriter},
system::In,
},
};

/// Send this event.
///
/// ```
/// ```rust
/// use bevy::prelude::*;
/// use bevy_input_sequence::prelude::*;
///
Expand All @@ -25,7 +27,7 @@ pub fn send_event<E: Event + Clone>(event: E) -> impl FnMut(EventWriter<E>) {
}
}

/// Sends an event with input, .e.g, [ButtonSequence] provides a [Gamepad] identifier.
/// Sends an event with input, .e.g, [ButtonSequence](crate::input_sequence::ButtonSequence) provides a [Gamepad](bevy::input::gamepad::Gamepad) identifier.
pub fn send_event_with_input<E: Event, Input: 'static, F: FnMut(Input) -> E>(
mut f: F,
) -> impl FnMut(In<Input>, EventWriter<E>) {
Expand Down
14 changes: 5 additions & 9 deletions src/cond_system.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
//! Extend
//! [IntoSystem](https://docs.rs/bevy/latest/bevy/ecs/system/trait.IntoSystem.html)
//! for conditional execution
//! Extend [IntoSystem] for conditional execution
use bevy::ecs::system::{CombinatorSystem, Combine, IntoSystem, System};
use std::borrow::Cow;

/// Extend
/// [IntoSystem](https://docs.rs/bevy/latest/bevy/ecs/system/trait.IntoSystem.html)
/// to allow for some conditional execution. Probably only appropriate for
/// one-shot systems. Prefer
/// [`run_if`](https://docs.rs/bevy/latest/bevy/ecs/schedule/trait.IntoSystemConfigs.html#method.run_if)
/// when directly adding to the scheduler.
/// Extend [IntoSystem] to allow for some conditional execution. Probably only
/// appropriate for one-shot systems. Prefer
/// [`run_if()`](bevy::ecs::schedule::IntoSystemConfigs::run_if()) when directly
/// adding to the scheduler.
pub trait IntoCondSystem<I, O, M>: IntoSystem<I, O, M> {
/// Only run self's system if the given `system` parameter returns true. No
/// output is provided. (This is convenient for running systems with
Expand Down

0 comments on commit e96d769

Please sign in to comment.