Skip to content

Commit

Permalink
Update to leafwing-input-manager 0.15 (#60)
Browse files Browse the repository at this point in the history
* Bump LWIM version

* Don't try to register the types :(

* Remove ToggleActions functionality

* Add public system sets

* Fix example
  • Loading branch information
alice-i-cecile authored Sep 3, 2024
1 parent 2c7929b commit 12e5e0b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bevy = { version = "0.14", default-features = false, features = [
"bevy_gilrs",
] }
serde = { version = "1.0", features = ["derive"] }
leafwing-input-manager = "0.14"
leafwing-input-manager = { version = "0.15", default-features = false }

leafwing_abilities_macros = { path = "macros", version = "0.3" }
thiserror = "1.0.37"
Expand All @@ -45,3 +45,5 @@ bevy = { version = "0.14", default-features = false, features = [
"x11",
"default_font",
] }
# Needed to provide implementations for standard input devices
leafwing-input-manager = { version = "0.15", default-features = true }
6 changes: 6 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes

## Version 0.9

- now support `leafwing-input-manager` 0.15
- all types provided by this library are now `Reflect`
- removed `ToggleActions`: this functionality no longer makes sense with changes to how LWIM disables actions. Use run conditions directly on the new `AbilitySystem::TickCooldowns` system set

## Version 0.8

- now supports Bevy 0.14
Expand Down
4 changes: 1 addition & 3 deletions examples/cooldown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ impl CookieAbility {

fn key_bindings() -> InputMap<CookieAbility> {
// CookieAbility::AddOne is pressed manually when the cookie is clicked on
InputMap::default()
.insert(CookieAbility::DoubleCookies, KeyCode::Space)
.build()
InputMap::default().with(CookieAbility::DoubleCookies, KeyCode::Space)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ mod tests {

use crate as leafwing_abilities;

#[derive(Abilitylike, Actionlike, Reflect, Clone, Hash, PartialEq, Eq)]
#[derive(Abilitylike, Actionlike, Reflect, Clone, Hash, PartialEq, Eq, Debug)]
enum TestAbility {
TestAction,
}
Expand Down
23 changes: 11 additions & 12 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Contains main plugin exported by this crate.
use crate::{AbilitiesBundle, Abilitylike};
use crate::Abilitylike;
use bevy::ecs::prelude::*;
use core::marker::PhantomData;

use bevy::app::{App, Plugin, PreUpdate};
use leafwing_input_manager::plugin::{InputManagerSystem, ToggleActions};
use leafwing_input_manager::plugin::InputManagerSystem;

/// A [`Plugin`] that collects [`Input`](bevy::input::Input) from disparate sources, producing an [`ActionState`](crate::action_state::ActionState) that can be conveniently checked
///
Expand All @@ -21,9 +21,6 @@ use leafwing_input_manager::plugin::{InputManagerSystem, ToggleActions};
///
/// ## Systems
///
/// All systems added by this plugin can be dynamically enabled and disabled by setting the value of the [`ToggleActions<A>`] resource is set.
/// This can be useful when working with states to pause the game, navigate menus or so on.
///
/// **WARNING:** These systems run during [`CoreStage::PreUpdate`].
/// If you have systems that care about inputs and actions that also run during this stage,
/// you must define an ordering between your systems or behavior will be very erratic.
Expand All @@ -43,6 +40,14 @@ pub struct AbilityPlugin<A: Abilitylike> {
_phantom: PhantomData<A>,
}

/// System sets provided by [`leafwing_abilities`](crate).
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
pub enum AbilitySystem {
/// Updates the cooldowns of all abilities,
/// including their charges and global cooldowns if applicable.
TickCooldowns,
}

// Deriving default induces an undesired bound on the generic
impl<A: Abilitylike> Default for AbilityPlugin<A> {
fn default() -> Self {
Expand All @@ -60,15 +65,9 @@ impl<A: Abilitylike> Plugin for AbilityPlugin<A> {
app.add_systems(
PreUpdate,
tick_cooldowns::<A>
.run_if(actions_toggled::<A>)
.in_set(AbilitySystem::TickCooldowns)
.in_set(InputManagerSystem::Tick)
.before(InputManagerSystem::Update),
);

// Type registration
app.register_type::<AbilitiesBundle<A>>();

// Resources
app.init_resource::<ToggleActions<A>>();
}
}
6 changes: 0 additions & 6 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{charges::ChargeState, cooldown::CooldownState, Abilitylike};

use bevy::ecs::prelude::*;
use bevy::time::Time;
use leafwing_input_manager::plugin::ToggleActions;

/// Advances all [`CooldownState`] components and resources for ability type `A`.
pub fn tick_cooldowns<A: Abilitylike>(
Expand Down Expand Up @@ -52,8 +51,3 @@ pub fn regenerate_resource_pool<P: RegeneratingPool + Component + Resource>(
pool.regenerate(delta_time);
}
}

/// Returns [`ShouldRun::No`] if [`DisableInput`] exists and [`ShouldRun::Yes`] otherwise
pub(super) fn actions_toggled<A: Abilitylike>(toggle_actions: Res<ToggleActions<A>>) -> bool {
toggle_actions.enabled
}

0 comments on commit 12e5e0b

Please sign in to comment.