Skip to content

Commit

Permalink
Merge branch 'main' into better-pools
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile authored Aug 29, 2023
2 parents 249a2f7 + 4d5b5c6 commit b5971c0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
Expand All @@ -31,10 +30,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
Expand All @@ -49,10 +47,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
Expand All @@ -65,7 +62,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Cache Cargo build files
Expand Down
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- added the `Pool::is_empty` and `Pool::is_full` helper methods to the `Pool` trait
- added `Add`, `Sub`, `AddAssign` and `SubAssign` implementations to the premade `Life` and `Mana` types and their corresponding pools
- added the `Display` trait to `Life`, `Mana`, `LifePool` and `ManaPool`
- removed the useless `AbilityPlugin::server()` plugin creation method

## Version 0.5

Expand Down
12 changes: 6 additions & 6 deletions src/charges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{Abilitylike, CannotUseAbility};

/// A component / resource that stores the [`Charges`] for each [`Abilitylike`] action of type `A`.
///
/// If [`Charges`] is set for an actions, it is only [`Abilitylike::ready`] when at least one charge is availabe.
/// If [`Charges`] is set for an actions, it is only [`Abilitylike::ready`] when at least one charge is available.
///
/// ```rust
/// use bevy::reflect::Reflect;
Expand Down Expand Up @@ -42,7 +42,7 @@ use crate::{Abilitylike, CannotUseAbility};
/// }
///
/// fn cooldowns() -> CooldownState<Action> {
/// // Ommitted cooldowns and charges will cause the action to be treated as if it always had available cooldowns / charges to use
/// // Omitted cooldowns and charges will cause the action to be treated as if it always had available cooldowns / charges to use.
/// CooldownState::new([
/// (Action::Dash, Cooldown::from_secs(2.)),
/// (Action::Spell, Cooldown::from_secs(4.5)),
Expand All @@ -57,22 +57,22 @@ use crate::{Abilitylike, CannotUseAbility};
/// }
/// }
///
/// // In a real game you'd spawn a bundle with the appropriate components
/// // In a real game you'd spawn a bundle with the appropriate components.
/// let mut abilities_bundle = AbilitiesBundle {
/// cooldowns: Action::cooldowns(),
/// charges: Action::charges(),
/// ..Default::default()
/// };
///
/// // You can also define resource pools using a seperate bundle
/// // Typically, you'll want to nest both of these bundles under a custom Bundle type for your characters
/// // You can also define resource pools using a separate bundle.
/// // Typically, you'll want to nest both of these bundles under a custom Bundle type for your characters.
/// let mut mana_bundle = PoolBundle {
/// // Max mana of 1000., regen rate of 10.
/// pool: ManaPool::new_full(Mana(100.0), Mana(1.0)),
/// ability_costs: Action::mana_costs(),
/// };
///
/// // Then, you can check if an action is ready to be used
/// // Then, you can check if an action is ready to be used.
/// // Consider using the `AbilityState` `WorldQuery` type instead for convenience!
/// if Action::Spell.ready(&abilities_bundle.charges, &abilities_bundle.cooldowns, Some(&mana_bundle.pool), Some(&mana_bundle.ability_costs)).is_ok() {
/// // When you use an action, remember to trigger it!
Expand Down
20 changes: 3 additions & 17 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use leafwing_input_manager::plugin::{InputManagerSystem, ToggleActions};
/// Each variant represents a "virtual button" whose state is stored in an [`ActionState`](crate::action_state::ActionState) struct.
///
/// Each [`InputManagerBundle`](crate::InputManagerBundle) contains:
/// - an [`InputMap`](crate::input_map::InputMap) component, which stores an entity-specific mapping between the assorted input streams and an internal repesentation of "actions"
/// - an [`InputMap`](crate::input_map::InputMap) component, which stores an entity-specific mapping between the assorted input streams and an internal representation of "actions"
/// - an [`ActionState`](crate::action_state::ActionState) component, which stores the current input state for that entity in an source-agnostic fashion
///
/// If you have more than one distinct type of action (e.g. menu actions, camera actions and player actions), consider creating multiple `Actionlike` enums
Expand All @@ -24,7 +24,7 @@ use leafwing_input_manager::plugin::{InputManagerSystem, ToggleActions};
/// 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:** Theses systems run during [`CoreStage::PreUpdate`].
/// **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.
/// The stable labels for these systems are available under [`InputManagerSystem`] enum.
Expand Down Expand Up @@ -52,20 +52,6 @@ impl<A: Abilitylike> Default for AbilityPlugin<A> {
}
}

impl<A: Abilitylike> AbilityPlugin<A> {
/// Creates a version of the plugin intended to run on the server
///
/// Inputs will not be processed; instead, [`ActionState`](crate::action_state::ActionState)
/// should be copied directly from the state provided by the client,
/// or constructed from [`ActionDiff`](crate::action_state::ActionDiff) event streams.
#[must_use]
pub fn server() -> Self {
Self {
_phantom: PhantomData,
}
}
}

impl<A: Abilitylike> Plugin for AbilityPlugin<A> {
fn build(&self, app: &mut App) {
use crate::systems::*;
Expand All @@ -74,7 +60,7 @@ impl<A: Abilitylike> Plugin for AbilityPlugin<A> {
app.add_systems(
PreUpdate,
tick_cooldowns::<A>
.run_if(run_if_enabled::<A>)
.run_if(actions_toggled::<A>)
.in_set(InputManagerSystem::Tick)
.before(InputManagerSystem::Update),
);
Expand Down
2 changes: 1 addition & 1 deletion src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ pub fn regenerate_resource_pool<P: RegeneratingPool + Component + Resource>(
}

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

0 comments on commit b5971c0

Please sign in to comment.