Skip to content

Commit 3f1fd98

Browse files
authored
feat: Add Reflect derive to KeyChord. (#17)
refactor: Deprecate `send_event` for `write_message`. chore: Bump to version 0.9.1.
1 parent aac215b commit 3f1fd98

File tree

12 files changed

+633
-580
lines changed

12 files changed

+633
-580
lines changed

Cargo.lock

Lines changed: 589 additions & 553 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bevy-input-sequence"
33
description = "Recognizes and acts on input sequences"
4-
version = "0.9.0"
4+
version = "0.9.1"
55
edition = "2021"
66
authors = ["elm", "Shane Celis <shane.celis@gmail.com>"]
77
keywords = [

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn say_hello() {
5858
## Send an Event on Key Sequence
5959

6060
Originally `bevy-input-sequence` always sent an event. You can still do that
61-
with `action::send_event()`.
61+
with `action::write_message()`.
6262

6363
```rust
6464
use bevy::prelude::*;
@@ -80,7 +80,7 @@ fn main() {
8080

8181
fn setup(mut commands: Commands) {
8282
commands.queue(
83-
KeySequence::new(action::send_event(MyEvent),
83+
KeySequence::new(action::write_message(MyEvent),
8484
keyseq! { Ctrl-E Alt-L Shift-M })
8585
);
8686
}
@@ -118,7 +118,7 @@ fn main() {
118118

119119
fn setup(mut commands: Commands) {
120120
commands.queue(
121-
ButtonSequence::new(action::send_event_with_input(|gamepad| MyEvent(gamepad)),
121+
ButtonSequence::new(action::write_message_with_input(|gamepad| MyEvent(gamepad)),
122122
[GamepadButton::North,
123123
GamepadButton::East,
124124
GamepadButton::South,
@@ -181,20 +181,20 @@ struct MyEvent;
181181

182182
fn create_key_sequence(mut commands: Commands) {
183183
commands.queue(KeySequence::new(
184-
action::send_event(bevy::app::AppExit::default()),
184+
action::write_message(bevy::app::AppExit::default()),
185185
keyseq! { Ctrl-E L M }
186186
));
187187
}
188188

189189
fn create_key_sequence_and_add_it_to_an_entity(mut commands: Commands) {
190190
let id = commands.spawn_empty().id();
191191
commands.entity(id).queue(KeySequence::new(
192-
action::send_event(MyEvent),
192+
action::write_message(MyEvent),
193193
keyseq! { Ctrl-E L M }
194194
));
195195
// OR
196196
commands.spawn_empty().queue(KeySequence::new(
197-
action::send_event(MyEvent),
197+
action::write_message(MyEvent),
198198
keyseq! { Ctrl-E L M }
199199
));
200200
}

examples/gamepad_button.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
fn setup(mut commands: Commands) {
1818
commands.queue(
1919
ButtonSequence::new(
20-
action::send_event_with_input(|gamepad| MyEvent(0, gamepad)),
20+
action::write_message_with_input(|gamepad| MyEvent(0, gamepad)),
2121
[
2222
GamepadButton::North,
2323
GamepadButton::East,
@@ -30,7 +30,7 @@ fn setup(mut commands: Commands) {
3030

3131
commands.queue(
3232
ButtonSequence::new(
33-
action::send_event_with_input(|gamepad| MyEvent(1, gamepad)),
33+
action::write_message_with_input(|gamepad| MyEvent(1, gamepad)),
3434
[
3535
GamepadButton::North,
3636
GamepadButton::West,

examples/keycode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn setup(mut commands: Commands) {
2626
// Specify key codes directly.
2727
commands.queue(
2828
KeySequence::new(
29-
action::send_event(MyEvent(Direction::Clockwise)),
29+
action::write_message(MyEvent(Direction::Clockwise)),
3030
[KeyCode::KeyW,
3131
KeyCode::KeyD,
3232
KeyCode::KeyS,
@@ -38,7 +38,7 @@ fn setup(mut commands: Commands) {
3838
// Use keyseq! macro.
3939
commands.queue(
4040
KeySequence::new(
41-
action::send_event(MyEvent(Direction::CounterClockwise)),
41+
action::write_message(MyEvent(Direction::CounterClockwise)),
4242
keyseq!{ W A S D },
4343
)
4444
.time_limit(Duration::from_secs(1)),

examples/keymod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
fn setup(mut commands: Commands) {
1818
commands.queue(
1919
KeySequence::new(
20-
action::send_event(MyEvent),
20+
action::write_message(MyEvent),
2121
keyseq! { Ctrl-W Ctrl-D Ctrl-S Ctrl-A },
2222
)
2323
.time_limit(Duration::from_secs(1)),

examples/multiple_input.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ fn main() {
1717

1818
fn setup(mut commands: Commands) {
1919
commands.queue(
20-
KeySequence::new(action::send_event(MyEvent(1, None)), keyseq! { W D S A })
20+
KeySequence::new(action::write_message(MyEvent(1, None)), keyseq! { W D S A })
2121
.time_limit(Duration::from_secs(5)),
2222
);
2323

2424
commands.queue(
2525
ButtonSequence::new(
26-
action::send_event_with_input(|gamepad| MyEvent(2, Some(gamepad))),
26+
action::write_message_with_input(|gamepad| MyEvent(2, Some(gamepad))),
2727
[
2828
GamepadButton::North,
2929
GamepadButton::East,
@@ -35,13 +35,13 @@ fn setup(mut commands: Commands) {
3535
);
3636

3737
commands.queue(
38-
KeySequence::new(action::send_event(MyEvent(3, None)), keyseq! { W A S D })
38+
KeySequence::new(action::write_message(MyEvent(3, None)), keyseq! { W A S D })
3939
.time_limit(Duration::from_secs(5)),
4040
);
4141

4242
commands.queue(
4343
ButtonSequence::new(
44-
action::send_event_with_input(|gamepad| MyEvent(4, Some(gamepad))),
44+
action::write_message_with_input(|gamepad| MyEvent(4, Some(gamepad))),
4545
[
4646
GamepadButton::North,
4747
GamepadButton::West,

examples/only_if.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ fn main() {
2929

3030
fn setup(mut commands: Commands) {
3131
commands.queue(KeySequence::new(
32-
action::send_event(GlobalEvent),
32+
action::write_message(GlobalEvent),
3333
keyseq! { Escape },
3434
));
3535
commands.queue(
3636
KeySequence::new(
37-
action::send_event(MyEvent).only_if(in_state(AppState::Game)),
37+
action::write_message(MyEvent).only_if(in_state(AppState::Game)),
3838
keyseq! { Space },
3939
)
4040
.time_limit(Duration::from_secs(1)),

examples/run_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
fn setup(mut commands: Commands) {
3131
commands.queue(
3232
KeySequence::new(
33-
action::send_event(MyEvent).only_if(in_state(AppState::Game)),
33+
action::write_message(MyEvent).only_if(in_state(AppState::Game)),
3434
keyseq! { Space },
3535
)
3636
.time_limit(Duration::from_secs(1)),

src/action.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy::ecs::{
44
system::In,
55
};
66

7-
/// Send this event.
7+
/// Write a message.
88
///
99
/// ```rust
1010
/// use bevy::prelude::*;
@@ -16,15 +16,21 @@ use bevy::ecs::{
1616
/// struct MyEvent;
1717
///
1818
/// KeySequence::new(
19-
/// action::send_event(MyEvent),
19+
/// action::write_message(MyEvent),
2020
/// keyseq! { Space });
2121
/// ```
22-
pub fn send_event<E: Message + Clone>(event: E) -> impl FnMut(MessageWriter<E>) {
22+
pub fn write_message<E: Message + Clone>(event: E) -> impl FnMut(MessageWriter<E>) {
2323
move |mut writer: MessageWriter<E>| {
2424
writer.write(event.clone());
2525
}
2626
}
2727

28+
/// Send an event.
29+
#[deprecated(since = "0.9.1", note = "please use `write_message` instead")]
30+
pub fn send_event<E: Message + Clone>(event: E) -> impl FnMut(MessageWriter<E>) {
31+
write_message(event)
32+
}
33+
2834
/// Trigger an event.
2935
pub fn trigger<'a, E>(event: E) -> impl FnMut(Commands)
3036
where
@@ -36,13 +42,24 @@ where
3642
}
3743
}
3844

39-
/// Sends an event with input, .e.g,
45+
/// Write a message with input, .e.g,
4046
/// [ButtonSequence](crate::input_sequence::ButtonSequence) provides a
4147
/// [Gamepad](bevy::input::gamepad::Gamepad) identifier.
42-
pub fn send_event_with_input<E: Message, Input: 'static, F: FnMut(Input) -> E>(
48+
pub fn write_message_with_input<E: Message, Input: 'static, F: FnMut(Input) -> E>(
4349
mut f: F,
4450
) -> impl FnMut(In<Input>, MessageWriter<E>) {
4551
move |In(x), mut writer: MessageWriter<E>| {
4652
writer.write(f(x));
4753
}
4854
}
55+
56+
/// Sends an event with input.
57+
#[deprecated(
58+
since = "0.9.1",
59+
note = "please use `write_message_with_input` instead"
60+
)]
61+
pub fn send_event_with_input<E: Message, Input: 'static, F: FnMut(Input) -> E>(
62+
f: F,
63+
) -> impl FnMut(In<Input>, MessageWriter<E>) {
64+
write_message_with_input(f)
65+
}

0 commit comments

Comments
 (0)