Skip to content

Commit

Permalink
Remove PressScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice Cecile committed Jan 23, 2024
1 parent a81caef commit f8d61b8
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 105 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- all non-insertion methods now take `&A: Actionlike` rather than `A: Actionlike` to avoid pointless cloning
- removed `multimap` dependency in favor of regular `HashMap` which allowed to derive `Reflect` for `InputMap`
- removed widely unused and untested dynamic actions functionality: this should be more feasible to implement directly with the changed architecture
- removed widely unused `PressScheduler` functionality: this can be re-implemented externally
- `ActionState` now stores a `HashMap` internally
- `ActionState::update` now takes a `HashMap<A, ActionState>` rather than relying on ordering
- `InputMap::which_pressed` now returns a `HashMap<A, ActionState>`
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod input_mocking;
pub mod input_streams;
pub mod orientation;
pub mod plugin;
pub mod press_scheduler;
pub mod scan_codes;
pub mod systems;
pub mod user_input;
Expand Down
45 changes: 0 additions & 45 deletions src/press_scheduler.rs

This file was deleted.

21 changes: 3 additions & 18 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
input_map::InputMap,
input_streams::InputStreams,
plugin::ToggleActions,
press_scheduler::PressScheduler,
Actionlike,
};

Expand Down Expand Up @@ -83,12 +82,7 @@ pub fn update_action_state<A: Actionlike>(
#[cfg(feature = "egui")] mut maybe_egui: Query<(Entity, &'static mut EguiContext)>,
action_state: Option<ResMut<ActionState<A>>>,
input_map: Option<Res<InputMap<A>>>,
press_scheduler: Option<ResMut<PressScheduler<A>>>,
mut query: Query<(
&mut ActionState<A>,
&InputMap<A>,
Option<&mut PressScheduler<A>>,
)>,
mut query: Query<(&mut ActionState<A>, &InputMap<A>)>,
) {
let gamepad_buttons = gamepad_buttons.into_inner();
let gamepad_button_axes = gamepad_button_axes.into_inner();
Expand Down Expand Up @@ -136,15 +130,9 @@ pub fn update_action_state<A: Actionlike>(

let resources = input_map
.zip(action_state)
.map(|(input_map, action_state)| {
(
Mut::from(action_state),
input_map.into_inner(),
press_scheduler.map(Mut::from),
)
});
.map(|(input_map, action_state)| (Mut::from(action_state), input_map.into_inner()));

for (mut action_state, input_map, press_scheduler) in query.iter_mut().chain(resources) {
for (mut action_state, input_map) in query.iter_mut().chain(resources) {
let input_streams = InputStreams {
gamepad_buttons,
gamepad_button_axes,
Expand All @@ -159,9 +147,6 @@ pub fn update_action_state<A: Actionlike>(
};

action_state.update(input_map.which_pressed(&input_streams, *clash_strategy));
if let Some(mut press_scheduler) = press_scheduler {
press_scheduler.apply(&mut action_state);
}
}
}

Expand Down
41 changes: 0 additions & 41 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bevy::prelude::*;
use leafwing_input_manager::prelude::*;
use leafwing_input_manager::press_scheduler::PressScheduler;

#[derive(Actionlike, Clone, Copy, Debug, Reflect, PartialEq, Eq, Hash)]
enum Action {
Expand Down Expand Up @@ -247,43 +246,3 @@ fn duration() {
.resource::<ActionState<Action>>()
.pressed(&Action::PayRespects));
}

#[test]
fn schedule_presses() {
use bevy::input::InputPlugin;

let mut app = App::new();

app.add_plugins(MinimalPlugins)
.add_plugins(InputPlugin)
.add_plugins(InputManagerPlugin::<Action>::default())
.init_resource::<ActionState<Action>>()
.insert_resource(InputMap::<Action>::new([(Action::PayRespects, KeyCode::F)]))
.init_resource::<PressScheduler<Action>>();

// Initializing
app.update();

// Press
app.world
.resource_mut::<PressScheduler<Action>>()
.schedule_press(&Action::PayRespects);

assert!(app
.world
.resource::<ActionState<Action>>()
.released(&Action::PayRespects));

// Check
app.update();
assert!(app
.world
.resource::<ActionState<Action>>()
.just_pressed(&Action::PayRespects));

app.update();
assert!(app
.world
.resource::<ActionState<Action>>()
.just_released(&Action::PayRespects));
}

0 comments on commit f8d61b8

Please sign in to comment.