Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more Default impls #65

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
- to better support working with multiple resource pools for a single `Abilitylike`:
- `ready_no_cost` and `trigger_no_cost` have been added to `Abilitylike`
- when working with multiple resource pools, you should pass in `NullPool` as the type argument for `AbilityState`
- `Default` is now implemented for `Charges` and `Cooldown`

## Bugs (0.9)

2 changes: 1 addition & 1 deletion src/ability_state.rs
Original file line number Diff line number Diff line change
@@ -233,7 +233,7 @@ mod tests {
/// Used in [`AbilityState`] to get the type system to play nice when no resource pool type is needed.
///
/// Values of this type should never be constructed.
#[derive(Component)]
#[derive(Component, Debug, Default)]
pub struct NullPool;

impl Pool for NullPool {
8 changes: 5 additions & 3 deletions src/charges.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ impl<A: Abilitylike> Default for ChargeState<A> {
///
/// Charges refresh when [`Charges::refresh`] is called manually,
/// or when the corresponding cooldown expires (if the [`InputManagerPlugin`](crate::plugin::InputManagerPlugin) is added).
#[derive(Clone, PartialEq, Eq, Debug, Reflect)]
#[derive(Clone, Default, PartialEq, Eq, Debug, Reflect)]
pub struct Charges {
current: u8,
max: u8,
@@ -115,11 +115,12 @@ pub struct Charges {
}

/// What happens when [`Charges`] are replenished?
#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Reflect)]
pub enum ReplenishStrategy {
/// A single charge will be recovered.
///
/// Usually paired with [`CooldownStrategy::ConstantlyRefresh`].
#[default]
OneAtATime,
/// All charges will be recovered.
///
@@ -128,13 +129,14 @@ pub enum ReplenishStrategy {
}

/// How do these charges replenish when cooldowns are refreshed?
#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Reflect)]
pub enum CooldownStrategy {
/// Cooldowns refresh will have no effect on the charges.
Ignore,
/// Cooldowns will replenish charges whenever the current charges are less than the max.
///
/// Usually paired with [`ReplenishStrategy::OneAtATime`].
#[default]
ConstantlyRefresh,
/// Cooldowns will only replenish charges when 0 charges are available.
///
2 changes: 1 addition & 1 deletion src/cooldown.rs
Original file line number Diff line number Diff line change
@@ -255,7 +255,7 @@ impl<A: Abilitylike> CooldownState<A> {
/// cooldown.refresh();
/// assert!(cooldown.ready().is_ok());
/// ```
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Reflect)]
#[derive(Clone, Default, PartialEq, Eq, Debug, Serialize, Deserialize, Reflect)]
pub struct Cooldown {
max_time: Duration,
/// The amount of time that has elapsed since all [`Charges`](crate::charges::Charges) were fully replenished.