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 Display impls for Cooldown and Charges #66

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -16,6 +16,7 @@
- `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`
- added `Display` implementations for `Charges` and `Cooldown`

## Bugs (0.9)

Expand Down
8 changes: 7 additions & 1 deletion src/charges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::{
ecs::prelude::{Component, Resource},
reflect::Reflect,
};
use std::marker::PhantomData;
use std::{fmt::Display, marker::PhantomData};

use crate::{Abilitylike, CannotUseAbility};
use std::collections::HashMap;
Expand Down Expand Up @@ -114,6 +114,12 @@ pub struct Charges {
pub cooldown_strat: CooldownStrategy,
}

impl Display for Charges {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}/{}", self.current, self.max)
}
}

/// What happens when [`Charges`] are replenished?
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Reflect)]
pub enum ReplenishStrategy {
Expand Down
8 changes: 7 additions & 1 deletion src/cooldown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy::{
reflect::Reflect,
};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, marker::PhantomData};
use std::{collections::HashMap, fmt::Display, marker::PhantomData};

/// The time until each action of type `A` can be used again.
///
Expand Down Expand Up @@ -415,6 +415,12 @@ impl Cooldown {
}
}

impl Display for Cooldown {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?} / {:?}", self.elapsed_time, self.max_time)
}
}

#[cfg(test)]
mod tick_tests {
use super::*;
Expand Down
Loading