Skip to content

Commit 5719b11

Browse files
authored
Minor bump to support bevy 0.14. (#9)
* chore: Update for bevy 0.14. * style: Run cargo fmt.
1 parent 5a43f8e commit 5719b11

File tree

10 files changed

+166
-134
lines changed

10 files changed

+166
-134
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bevy-input-sequence"
33
description = "Recognizes input sequences and send events"
4-
version = "0.4.0"
4+
version = "0.5.0"
55
edition = "2021"
66
authors = ["elm", "Shane Celis <[email protected]>"]
77
keywords = [
@@ -35,11 +35,11 @@ path = "examples/multiple_input.rs"
3535

3636

3737
[dependencies]
38-
bevy = { version = "0.13", default-features = false, features = [] }
38+
bevy = { version = "0.14", default-features = false, features = [] }
3939
trie-rs = { version = "0.4" }
40-
keyseq = { version = "0.2.3", features = [ "bevy" ] }
40+
keyseq = { version = "0.3.0", features = [ "bevy" ] }
4141

4242
[dev-dependencies]
43-
bevy = "0.13"
43+
bevy = "0.14"
4444
trybuild = "1.0"
4545
version-sync = "0.9"

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bevy-input-sequence
22

3-
This crate recognizes input sequences from keyboard and gamepad.
3+
Detect input sequences from the keyboard or a gamepad.
44

55
# Use Cases
66

@@ -19,14 +19,14 @@ cargo install bevy-input-sequence
1919
Here are some code snippets. These also run as doctests so they do a few things
2020
differently than a regular runnable example:
2121

22-
- Use `MinimalPlugins` instead of `DefaultPlugins`,
23-
- and call `app.update()` instead of `app.run()`.
22+
- Instead of `DefaultPlugins` they use `MinimalPlugins`.
23+
- Instead of `app.run()` they call `app.update()`.
2424

2525
The next section describes the runnable examples that come with the crate.
2626

2727
## Run a System on a Key Sequence
2828

29-
Runs a system whenever the user presses the key sequence `H I` or "hi" within a
29+
Run a system whenever the user presses the key sequence `H I` or "hi" within a
3030
time limit.
3131

3232
```rust
@@ -56,8 +56,8 @@ fn say_hello() {
5656

5757
## Send an Event on Key Sequence
5858

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

6262
```rust
6363
use bevy::prelude::*;
@@ -94,7 +94,7 @@ fn check_events(mut events: EventReader<MyEvent>) {
9494
## Send an Event on Gamepad Button Sequence
9595

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

100100
```rust
@@ -132,9 +132,9 @@ fn check_events(mut events: EventReader<MyEvent>) {
132132
}
133133
```
134134

135-
## KeySequence creation patterns
135+
## KeySequence Creation Patterns
136136

137-
`KeySequence::new` now returns an implementing of `Command` instead of itself.
137+
`KeySequence::new` now returns `KeySequenceBuilder`, which implements `Command`.
138138
Therefore, you need to call `Commands::add` instead of `Commands::spawn`.
139139

140140
```rust
@@ -146,7 +146,7 @@ struct MyEvent;
146146

147147
fn create_key_sequence(mut commands: Commands) {
148148
commands.add(KeySequence::new(
149-
action::send_event(bevy::app::AppExit),
149+
action::send_event(bevy::app::AppExit::default()),
150150
keyseq! { ctrl-E L M }
151151
));
152152
}
@@ -163,15 +163,25 @@ fn create_key_sequence_and_add_it_to_an_entity(mut commands: Commands) {
163163
keyseq! { ctrl-E L M }
164164
));
165165
}
166+
```
167+
168+
### Advanced Creation
169+
170+
The `KeySequenceBuilder` requires a `&mut World` to build it. You can build it
171+
yourself like so:
172+
173+
```rust
174+
use bevy::prelude::*;
175+
use bevy_input_sequence::prelude::*;
166176

167177
fn create_key_sequence_within_command(mut commands: Commands) {
168178
commands.add(|world: &mut World| {
169179
let builder = KeySequence::new(
170-
action::send_event(MyEvent),
180+
move || { info!("got it"); },
171181
keyseq! { ctrl-E L M }
172182
);
173-
let key_sequence = builder.build(world);
174-
// And then put it somewhere?
183+
let key_sequence: KeySequence = builder.build(world);
184+
// And then put it somewhere? It ought to go as a component.
175185
});
176186
}
177187
```
@@ -244,6 +254,7 @@ cargo run --example run_if
244254

245255
| bevy-input-sequence | bevy |
246256
|---------------------|------|
257+
| 0.5 | 0.14 |
247258
| 0.3 ~ 0.4.0 | 0.13 |
248259
| 0.2 | 0.12 |
249260
| 0.1 | 0.11 |

examples/keycode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum Direction {
88
}
99

1010
#[derive(Event, Clone, Debug)]
11+
#[allow(dead_code)]
1112
struct MyEvent(Direction);
1213

1314
fn main() {
@@ -49,6 +50,6 @@ fn setup(mut commands: Commands) {
4950

5051
fn event_listener(mut er: EventReader<MyEvent>) {
5152
for e in er.read() {
52-
println!("{e:?} emitted.");
53+
println!("{:?} emitted.", e);
5354
}
5455
}

examples/minimal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010
}
1111

1212
fn setup(mut commands: Commands) {
13+
info!("Type H I or \"hi\".");
1314
commands.add(KeySequence::new(say_hi, keyseq! { H I }));
1415
}
1516

examples/multiple_input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use bevy::prelude::*;
22
use bevy_input_sequence::prelude::*;
33

44
#[derive(Event, Clone, Debug)]
5+
#[allow(dead_code)]
56
struct MyEvent(u8, Option<Gamepad>);
67

78
fn main() {

src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Cache the trie for reuse.
22
use crate::input_sequence::InputSequence;
3-
use bevy::{ecs::system::Resource, log::info, reflect::TypePath};
3+
use bevy::{ecs::system::Resource, reflect::TypePath};
44
use std::{collections::HashMap, hash::Hash};
55
use trie_rs::{
66
inc_search::{IncSearch, Position},

src/input_sequence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
}
7272
}
7373

74-
impl<Act, S> bevy::ecs::system::Command for InputSequenceBuilder<Act, S>
74+
impl<Act, S> bevy::ecs::world::Command for InputSequenceBuilder<Act, S>
7575
where
7676
Act: Send + Sync + 'static,
7777
S: System<Out = ()> + Send + Sync + 'static,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![doc(html_root_url = "https://docs.rs/bevy-input-sequence/0.4.0")]
1+
#![doc(html_root_url = "https://docs.rs/bevy-input-sequence/0.5.0")]
22
#![doc = include_str!("../README.md")]
33
#![forbid(missing_docs)]
44

src/plugin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use bevy::{
22
app::{App, Plugin, Update},
33
core::FrameCount,
44
ecs::{
5+
intern::Interned,
56
query::Added,
67
removal_detection::RemovedComponents,
78
schedule::{IntoSystemConfigs, ScheduleLabel, SystemSet},
@@ -14,7 +15,6 @@ use bevy::{
1415
},
1516
log::warn,
1617
time::Time,
17-
utils::intern::Interned,
1818
};
1919
use std::collections::{HashMap, VecDeque};
2020

@@ -49,7 +49,7 @@ impl Plugin for InputSequencePlugin {
4949
fn build(&self, app: &mut App) {
5050
if self
5151
.match_key
52-
.unwrap_or(app.world.get_resource::<ButtonInput<KeyCode>>().is_some())
52+
.unwrap_or(app.world().get_resource::<ButtonInput<KeyCode>>().is_some())
5353
{
5454
// Add key sequence.
5555
app.init_resource::<InputSequenceCache<KeyChord, ()>>();
@@ -83,7 +83,7 @@ impl Plugin for InputSequencePlugin {
8383
}
8484

8585
if self.match_button.unwrap_or(
86-
app.world
86+
app.world()
8787
.get_resource::<ButtonInput<GamepadButton>>()
8888
.is_some(),
8989
) {

0 commit comments

Comments
 (0)