Skip to content

Commit 251f59d

Browse files
authored
Add 0.16 support (#13)
* feature: Support bevy 0.16. * style: Reformat. * chore: Bump keyseq. * chore: Remove patch crate.
1 parent 2973e87 commit 251f59d

File tree

13 files changed

+1584
-852
lines changed

13 files changed

+1584
-852
lines changed

Cargo.lock

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

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 and acts on input sequences"
4-
version = "0.7.0"
4+
version = "0.8.0"
55
edition = "2021"
66
authors = ["elm", "Shane Celis <shane.celis@gmail.com>"]
77
keywords = [
@@ -31,11 +31,11 @@ name = "multiple_input"
3131
path = "examples/multiple_input.rs"
3232

3333
[dependencies]
34-
bevy = { version = "0.15", default-features = false, features = [] }
34+
bevy = { version = "0.16", default-features = false, features = ["std", "async_executor", "bevy_log"] }
3535
trie-rs = { version = "0.4" }
36-
keyseq = { version = "0.5.0", features = [ "bevy" ] }
36+
keyseq = { version = "0.6.0", features = [ "bevy" ] }
3737

3838
[dev-dependencies]
39-
bevy = "0.15"
39+
bevy = "0.16"
4040
trybuild = "1.0"
4141
version-sync = "0.9"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ cargo run --example run_if
290290

291291
| bevy-input-sequence | bevy |
292292
|---------------------|------|
293+
| 0.8 | 0.16 |
293294
| 0.7 | 0.15 |
294295
| 0.5 ~ 0.6 | 0.14 |
295296
| 0.3 ~ 0.4 | 0.13 |

src/action.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use bevy::ecs::{
2323
/// ```
2424
pub fn send_event<E: Event + Clone>(event: E) -> impl FnMut(EventWriter<E>) {
2525
move |mut writer: EventWriter<E>| {
26-
writer.send(event.clone());
26+
writer.write(event.clone());
2727
}
2828
}
2929

@@ -49,6 +49,6 @@ pub fn send_event_with_input<E: Event, Input: 'static, F: FnMut(Input) -> E>(
4949
mut f: F,
5050
) -> impl FnMut(In<Input>, EventWriter<E>) {
5151
move |In(x), mut writer: EventWriter<E>| {
52-
writer.send(f(x));
52+
writer.write(f(x));
5353
}
5454
}

src/cache/button.rs

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Cache the trie for reuse.
22
use crate::input_sequence::InputSequence;
3-
use bevy::{ecs::system::Resource, prelude::{In, Entity, GamepadButton}};
3+
use bevy::{
4+
ecs::prelude::Resource,
5+
prelude::{Entity, GamepadButton, In},
6+
};
47
use std::collections::HashMap;
58
use trie_rs::{
69
inc_search::{IncSearch, Position},
@@ -14,8 +17,7 @@ pub struct ButtonSequenceCache {
1417
position: HashMap<Entity, Position>,
1518
}
1619

17-
impl ButtonSequenceCache
18-
{
20+
impl ButtonSequenceCache {
1921
/// Retrieve the cached trie without iterating through `sequences`. Or if
2022
/// the cache has been invalidated, build and cache a new trie using the
2123
/// `sequences` iterator.
@@ -24,7 +26,8 @@ impl ButtonSequenceCache
2426
sequences: impl Iterator<Item = &'a InputSequence<GamepadButton, In<Entity>>>,
2527
) -> &Trie<GamepadButton, InputSequence<GamepadButton, In<Entity>>> {
2628
self.trie.get_or_insert_with(|| {
27-
let mut builder: TrieBuilder<GamepadButton, InputSequence<GamepadButton, In<Entity>>> = TrieBuilder::new();
29+
let mut builder: TrieBuilder<GamepadButton, InputSequence<GamepadButton, In<Entity>>> =
30+
TrieBuilder::new();
2831
for sequence in sequences {
2932
builder.insert(sequence.acts.clone(), sequence.clone());
3033
}
@@ -61,57 +64,57 @@ impl ButtonSequenceCache
6164
.unwrap_or_else(move || trie.inc_search())
6265
}
6366

64-
// impl<'i, A, I> ButtonSequenceCache<'i, A, I>
65-
// where
66-
// A: Ord + Clone + Send + Sync + TypePath + 'static,
67-
// I: SystemInput + Send + Sync,
68-
// I::Inner<'i>: Clone + Eq + Hash + 'static,
69-
// {
70-
// // /// Retrieve the cached trie without iterating through `sequences`. Or if
71-
// // /// the cache has been invalidated, build and cache a new trie using the
72-
// // /// `sequences` iterator.
73-
// // pub fn trie<'a>(
74-
// // &mut self,
75-
// // sequences: impl Iterator<Item = &'a InputSequence<A, I>>,
76-
// // ) -> &Trie<A, InputSequence<A, I>> {
77-
// // self.trie.get_or_insert_with(|| {
78-
// // let mut builder: TrieBuilder<A, InputSequence<A, I>> = TrieBuilder::new();
79-
// // for sequence in sequences {
80-
// // builder.insert(sequence.acts.clone(), sequence.clone());
81-
// // }
82-
// // // info!(
83-
// // // "Building trie for {} input sequences.",
84-
// // // A::short_type_path()
85-
// // // );
86-
// // assert!(
87-
// // self.position.is_empty(),
88-
// // "Position should be none when rebuilding trie"
89-
// // );
90-
// // builder.build()
91-
// // })
92-
// // }
67+
// impl<'i, A, I> ButtonSequenceCache<'i, A, I>
68+
// where
69+
// A: Ord + Clone + Send + Sync + TypePath + 'static,
70+
// I: SystemInput + Send + Sync,
71+
// I::Inner<'i>: Clone + Eq + Hash + 'static,
72+
// {
73+
// // /// Retrieve the cached trie without iterating through `sequences`. Or if
74+
// // /// the cache has been invalidated, build and cache a new trie using the
75+
// // /// `sequences` iterator.
76+
// // pub fn trie<'a>(
77+
// // &mut self,
78+
// // sequences: impl Iterator<Item = &'a InputSequence<A, I>>,
79+
// // ) -> &Trie<A, InputSequence<A, I>> {
80+
// // self.trie.get_or_insert_with(|| {
81+
// // let mut builder: TrieBuilder<A, InputSequence<A, I>> = TrieBuilder::new();
82+
// // for sequence in sequences {
83+
// // builder.insert(sequence.acts.clone(), sequence.clone());
84+
// // }
85+
// // // info!(
86+
// // // "Building trie for {} input sequences.",
87+
// // // A::short_type_path()
88+
// // // );
89+
// // assert!(
90+
// // self.position.is_empty(),
91+
// // "Position should be none when rebuilding trie"
92+
// // );
93+
// // builder.build()
94+
// // })
95+
// // }
9396

94-
// // /// Store a search.
95-
// // pub fn store(&mut self, key: I, position: Position) {
96-
// // self.position.insert(key, position);
97-
// // }
97+
// // /// Store a search.
98+
// // pub fn store(&mut self, key: I, position: Position) {
99+
// // self.position.insert(key, position);
100+
// // }
98101

99-
// // /// Recall a search OR create a new search.
100-
// // pub fn recall<'a, 'b>(
101-
// // &'b mut self,
102-
// // key: I,
103-
// // sequences: impl Iterator<Item = &'a InputSequence<A, I>>,
104-
// // ) -> IncSearch<'a, A, InputSequence<A, I>>
105-
// // where
106-
// // 'b: 'a,
107-
// // {
108-
// // let position = self.position.get(&key).cloned();
109-
// // let trie = self.trie(sequences);
110-
// // position
111-
// // .map(move |p| IncSearch::resume(trie, p))
112-
// // .unwrap_or_else(move || trie.inc_search())
113-
// // }
114-
// }
102+
// // /// Recall a search OR create a new search.
103+
// // pub fn recall<'a, 'b>(
104+
// // &'b mut self,
105+
// // key: I,
106+
// // sequences: impl Iterator<Item = &'a InputSequence<A, I>>,
107+
// // ) -> IncSearch<'a, A, InputSequence<A, I>>
108+
// // where
109+
// // 'b: 'a,
110+
// // {
111+
// // let position = self.position.get(&key).cloned();
112+
// // let trie = self.trie(sequences);
113+
// // position
114+
// // .map(move |p| IncSearch::resume(trie, p))
115+
// // .unwrap_or_else(move || trie.inc_search())
116+
// // }
117+
// }
115118

116119
/// Clears the cache.
117120
pub fn reset(&mut self) {

src/cache/key.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Cache the trie for reuse.
2-
use crate::{KeyChord, input_sequence::InputSequence};
3-
use bevy::ecs::system::Resource;
2+
use crate::{input_sequence::InputSequence, KeyChord};
3+
use bevy::ecs::prelude::Resource;
44
use trie_rs::{
55
inc_search::{IncSearch, Position},
66
map::{Trie, TrieBuilder},
@@ -13,8 +13,7 @@ pub struct KeySequenceCache {
1313
position: Option<Position>,
1414
}
1515

16-
impl KeySequenceCache
17-
{
16+
impl KeySequenceCache {
1817
/// Retrieve the cached trie without iterating through `sequences`. Or if
1918
/// the cache has been invalidated, build and cache a new trie using the
2019
/// `sequences` iterator.
@@ -23,7 +22,8 @@ impl KeySequenceCache
2322
sequences: impl Iterator<Item = &'a InputSequence<KeyChord, ()>>,
2423
) -> &Trie<KeyChord, InputSequence<KeyChord, ()>> {
2524
self.trie.get_or_insert_with(|| {
26-
let mut builder: TrieBuilder<KeyChord, InputSequence<KeyChord, ()>> = TrieBuilder::new();
25+
let mut builder: TrieBuilder<KeyChord, InputSequence<KeyChord, ()>> =
26+
TrieBuilder::new();
2727
for sequence in sequences {
2828
builder.insert(sequence.acts.clone(), sequence.clone());
2929
}

src/chord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::{
22
input::keyboard::KeyCode,
3-
prelude::{Deref, DerefMut, Resource, ReflectResource},
3+
prelude::{Deref, DerefMut, ReflectResource, Resource},
44
reflect::{Enum, Reflect},
55
};
66

src/cond_system.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
//! Extend [IntoSystem] for conditional execution
2-
use bevy::ecs::system::{CombinatorSystem, Combine, IntoSystem, System, SystemInput, SystemIn};
2+
use bevy::ecs::system::{CombinatorSystem, Combine, IntoSystem, System, SystemIn, SystemInput};
33
use std::borrow::Cow;
44

55
/// Extend [IntoSystem] to allow for some conditional execution. Probably only
66
/// appropriate for one-shot systems. Prefer
77
/// [`run_if()`](bevy::ecs::schedule::IntoSystemConfigs::run_if()) when directly
88
/// adding to the scheduler.
99
pub trait IntoCondSystem<I, O, M>: IntoSystem<I, O, M>
10-
where I: SystemInput,
10+
where
11+
I: SystemInput,
1112
{
1213
/// Only run self's system if the given `system` parameter returns true. No
1314
/// output is provided. (This is convenient for running systems with
@@ -36,8 +37,12 @@ pub trait IntoCondSystem<I, O, M>: IntoSystem<I, O, M>
3637
}
3738
}
3839

39-
impl<I, O, M, T> IntoCondSystem<I, O, M> for T where T: IntoSystem<I, O, M>,
40-
I: SystemInput {}
40+
impl<I, O, M, T> IntoCondSystem<I, O, M> for T
41+
where
42+
T: IntoSystem<I, O, M>,
43+
I: SystemInput,
44+
{
45+
}
4146

4247
/// A one-shot conditional system comprised of consequent `SystemA` and
4348
/// conditional `SystemB`.

src/input_sequence.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
//! Input sequences for keys and gamepad buttons
22
use crate::{cond_system::IntoCondSystem, time_limit::TimeLimit, KeyChord};
3-
use std::{
4-
fmt,
5-
marker::PhantomData,
6-
};
3+
use std::{fmt, marker::PhantomData};
74

85
use bevy::{
9-
hierarchy::BuildChildren,
106
ecs::{
11-
prelude::In,
127
component::Component,
138
entity::Entity,
9+
prelude::In,
1410
system::{IntoSystem, System, SystemId, SystemInput},
1511
world::World,
1612
},
1713
input::gamepad::GamepadButton,
14+
prelude::{ChildOf, EntityWorldMut},
1815
reflect::Reflect,
1916
};
2017

@@ -35,7 +32,6 @@ pub struct InputSequence<Act, I: SystemInput + 'static> {
3532
pub time_limit: Option<TimeLimit>,
3633
}
3734

38-
3935
impl<Act: Clone> Clone for InputSequence<Act, ()> {
4036
fn clone(&self) -> Self {
4137
Self {
@@ -123,7 +119,7 @@ where
123119
}
124120
}
125121

126-
impl<Act, S, I> bevy::ecs::world::Command for InputSequenceBuilder<Act, S, I>
122+
impl<Act, S, I> bevy::prelude::Command for InputSequenceBuilder<Act, S, I>
127123
where
128124
Act: Send + Sync + 'static,
129125
S: System<In = I, Out = ()> + Send + Sync + 'static,
@@ -133,8 +129,7 @@ where
133129
let act = self.build(world);
134130
let system_entity = act.system_id.entity();
135131
let id = world.spawn(act).id();
136-
world.entity_mut(system_entity)
137-
.set_parent(id);
132+
world.entity_mut(system_entity).insert(ChildOf(id));
138133
}
139134
}
140135

@@ -144,13 +139,15 @@ where
144139
S: System<In = I, Out = ()> + Send + Sync + 'static,
145140
I: SystemInput + Send + Sync + 'static,
146141
{
147-
fn apply(self, id: Entity, world: &mut World) {
148-
let act = self.build(world);
149-
let system_entity = act.system_id.entity();
150-
let mut entity = world.get_entity_mut(id).unwrap();
151-
entity.insert(act);
152-
world.entity_mut(system_entity)
153-
.set_parent(id);
142+
fn apply(self, mut entity_world: EntityWorldMut) {
143+
let id = entity_world.id();
144+
entity_world.world_scope(move |world: &mut World| {
145+
let act = self.build(world);
146+
let system_entity = act.system_id.entity();
147+
let mut entity = world.get_entity_mut(id).unwrap();
148+
entity.insert(act);
149+
world.entity_mut(system_entity).insert(ChildOf(id));
150+
});
154151
}
155152
}
156153

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.7.0")]
1+
#![doc(html_root_url = "https://docs.rs/bevy-input-sequence/0.8.0")]
22
#![doc = include_str!("../README.md")]
33
#![forbid(missing_docs)]
44

0 commit comments

Comments
 (0)