Skip to content

Commit

Permalink
Add TickActionStateSystem set to allow configuring tick_action_state …
Browse files Browse the repository at this point in the history
…individually (#639)
  • Loading branch information
mvlabat authored Oct 5, 2024
1 parent 36441c7 commit 60db926
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/action_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use action_data::*;
/// Actions can be disabled in four different ways, with increasing granularity:
///
/// 1. By disabling updates to all actions using a run condition on [`InputManagerSystem::Update`](crate::plugin::InputManagerSystem::Update).
/// 2. By disabling updates to all actions of type `A` using a run condition on [`tick_action_state::<A>`](crate::systems::tick_action_state).
/// 2. By disabling updates to all actions of type `A` using a run condition on [`TickActionStateSystem::<A>`](crate::plugin::TickActionStateSystem).
/// 3. By setting a specific action state to disabled using [`ActionState::disable`].
/// 4. By disabling a specific action using [`ActionState::disable_action`].
///
Expand Down
31 changes: 29 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ impl<A: Actionlike + TypePath + bevy::reflect::GetTypeRegistration> Plugin
// Main schedule
app.add_systems(
PreUpdate,
(tick_action_state::<A>, clear_central_input_store)
(
tick_action_state::<A>.in_set(TickActionStateSystem::<A>::new()),
clear_central_input_store,
)
.in_set(InputManagerSystem::Tick)
.before(InputManagerSystem::Update),
)
Expand Down Expand Up @@ -182,6 +185,7 @@ impl<A: Actionlike + TypePath + bevy::reflect::GetTypeRegistration> Plugin
app.add_systems(
FixedPostUpdate,
tick_action_state::<A>
.in_set(TickActionStateSystem::<A>::new())
.in_set(InputManagerSystem::Tick)
.before(InputManagerSystem::Update),
);
Expand All @@ -193,7 +197,9 @@ impl<A: Actionlike + TypePath + bevy::reflect::GetTypeRegistration> Plugin
Machine::Server => {
app.add_systems(
PreUpdate,
tick_action_state::<A>.in_set(InputManagerSystem::Tick),
tick_action_state::<A>
.in_set(TickActionStateSystem::<A>::new())
.in_set(InputManagerSystem::Tick),
);
}
};
Expand Down Expand Up @@ -284,6 +290,27 @@ pub enum InputManagerSystem {
ManualControl,
}

#[derive(SystemSet, Clone, Hash, Debug, PartialEq, Eq)]
/// [`SystemSet`] for the [`tick_action_state`](crate::systems::tick_action_state) system, is a child set of [`InputManagerSystem::Tick`].
pub struct TickActionStateSystem<A: Actionlike> {
phantom_data: PhantomData<A>,
}

impl<A: Actionlike> TickActionStateSystem<A> {
/// Creates a [`TickActionStateSystem`] set instance.
pub fn new() -> Self {
Self {
phantom_data: PhantomData,
}
}
}

impl<A: Actionlike> Default for TickActionStateSystem<A> {
fn default() -> Self {
Self::new()
}
}

/// A plugin to handle accumulating mouse movement and scroll events.
///
/// This is a clearer, more reliable and more efficient approach to computing the total mouse movement and scroll for the frame.
Expand Down

0 comments on commit 60db926

Please sign in to comment.