diff --git a/CHANGELOG.md b/CHANGELOG.md index 197b8d5..a4b20e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ All notable changes to this project will be documented in this file. -## [0.4.0] - 2024-04-23 +## [0.5.0] - 2024-04-23 + +### Features +- Optimize look ups to incrementally search using O(log n) instead of O(m^2 log n). See [PR #7](https://github.com/not-elm/bevy-input-sequence/pull/7) for more details. ## [0.4.0] - 2024-04-23 diff --git a/Cargo.toml b/Cargo.toml index a78aa82..e120e43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy-input-sequence" -description = "Recognizes input sequences and send events" -version = "0.5.0" +description = "Recognizes and acts on input sequences" +version = "0.6.0" edition = "2021" authors = ["elm", "Shane Celis "] keywords = [ @@ -18,22 +18,18 @@ readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/elm-register/bevy-input-sequence" - [[example]] name = "keycode" path = "examples/keycode.rs" - [[example]] name = "gamepad_button" path = "examples/gamepad_button.rs" - [[example]] name = "multiple_input" path = "examples/multiple_input.rs" - [dependencies] bevy = { version = "0.14", default-features = false, features = [] } trie-rs = { version = "0.4" } @@ -43,3 +39,6 @@ keyseq = { version = "0.4.0", features = [ "bevy" ] } bevy = "0.14" trybuild = "1.0" version-sync = "0.9" + +[patch.crates-io] +keyseq = { path = "../keyseq" } diff --git a/README.md b/README.md index e670507..fe3da51 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bevy-input-sequence -Detect input sequences from the keyboard or a gamepad. +Recognizes and acts on input sequences from the keyboard or a gamepad. # Use Cases @@ -42,6 +42,7 @@ fn main() { } fn setup(mut commands: Commands) { + // Add key sequence. commands.add( KeySequence::new(say_hello, keyseq! { H I }) @@ -63,11 +64,11 @@ with `action::send_event()`. use bevy::prelude::*; use bevy_input_sequence::prelude::*; -// Define an event +/// Define an event. #[derive(Event, Clone, Debug)] struct MyEvent; -// Add event as an key sequence +/// Add event as an key sequence. fn main() { App::new() .add_plugins(MinimalPlugins) @@ -101,11 +102,11 @@ take an input of `Gamepad`. use bevy::prelude::*; use bevy_input_sequence::prelude::*; -// Define an event +/// Define an event. #[derive(Event, Clone, Debug)] struct MyEvent(Gamepad); -// Add event as an key sequence +/// Add event as an key sequence. fn main() { App::new() .add_plugins(MinimalPlugins) @@ -132,6 +133,41 @@ fn check_events(mut events: EventReader) { } ``` +## Trigger an Event on Key Sequence + +You can also trigger an event with `action::trigger()` or `action::trigger_targets()`. + +```rust +use bevy::prelude::*; +use bevy_input_sequence::prelude::*; + +/// Define an event. +#[derive(Event, Clone, Debug)] +struct MyEvent; + +/// Add event as an key sequence. +fn main() { + App::new() + .add_plugins(MinimalPlugins) + .add_plugins(InputSequencePlugin::default()) + .add_event::() + .add_systems(Startup, setup) + .observe(check_trigger) + .update(); // Normally you'd run it here. +} + +fn setup(mut commands: Commands) { + commands.add( + KeySequence::new(action::trigger(MyEvent), + keyseq! { Ctrl-E L M }) + ); +} + +fn check_trigger(mut trigger: Trigger) { + info!("got event {:?}", trigger.event()); +} +``` + ## KeySequence Creation Patterns `KeySequence::new` now returns `KeySequenceBuilder`, which implements `Command`. @@ -152,8 +188,8 @@ fn create_key_sequence(mut commands: Commands) { } fn create_key_sequence_and_add_it_to_an_entity(mut commands: Commands) { - let parent = commands.spawn_empty().id(); - commands.entity(parent).add(KeySequence::new( + let id = commands.spawn_empty().id(); + commands.entity(id).add(KeySequence::new( action::send_event(MyEvent), keyseq! { Ctrl-E L M } )); @@ -254,8 +290,8 @@ cargo run --example run_if | bevy-input-sequence | bevy | |---------------------|------| -| 0.5 | 0.14 | -| 0.3 ~ 0.4.0 | 0.13 | +| 0.5 ~ 0.6 | 0.14 | +| 0.3 ~ 0.4 | 0.13 | | 0.2 | 0.12 | | 0.1 | 0.11 | diff --git a/src/lib.rs b/src/lib.rs index a157c96..2b7884b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/bevy-input-sequence/0.5.0")] +#![doc(html_root_url = "https://docs.rs/bevy-input-sequence/0.6.0")] #![doc = include_str!("../README.md")] #![forbid(missing_docs)]