Skip to content

Commit

Permalink
Add more Default impls (#65)
Browse files Browse the repository at this point in the history
* Implement Default for more types

* Add release notes
  • Loading branch information
alice-i-cecile authored Sep 4, 2024
1 parent 45907c9 commit d5ba04f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/ability_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/charges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
///
Expand All @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion src/cooldown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d5ba04f

Please sign in to comment.