diff --git a/RELEASES.md b/RELEASES.md index aefddda..cc20e34 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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) diff --git a/src/charges.rs b/src/charges.rs index 994a237..ad840b5 100644 --- a/src/charges.rs +++ b/src/charges.rs @@ -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; @@ -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 { diff --git a/src/cooldown.rs b/src/cooldown.rs index fee1a4b..f77254a 100644 --- a/src/cooldown.rs +++ b/src/cooldown.rs @@ -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. /// @@ -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::*;