diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-18 04:19:34 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-18 04:19:34 +0100 |
commit | 937e1ed8d240c1a5b42f5b8cf1104321b9d79c4a (patch) | |
tree | c9cc6f8ec35e3e9b1ba97b5fd42091cf0ab2afb6 /src/shared/ability.rs | |
parent | ab675360c0005718a3c9b8b5e7962af897269c04 (diff) |
fix: fix abilities selecting the right cooldown
Diffstat (limited to 'src/shared/ability.rs')
-rw-r--r-- | src/shared/ability.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/shared/ability.rs b/src/shared/ability.rs index 9639afe..cab7ae6 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -1,6 +1,8 @@ use crate::shared::player::*; use crate::shared::projectile::*; use crate::shared::*; +use bevy::utils::Duration; +use std::ops::*; #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub enum Ability { @@ -64,3 +66,54 @@ impl DirectionalAbility { } } } + +#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] +pub enum AbilitySlot { + A, + Q, + W, + E, + R, + F, + G, +} + +impl AbilitySlot { + pub fn to_label(self) -> &'static str { + match self { + AbilitySlot::A => "A", + AbilitySlot::Q => "Q", + AbilitySlot::W => "W", + AbilitySlot::E => "E", + AbilitySlot::R => "R", + AbilitySlot::F => "F", + AbilitySlot::G => "G", + } + } + + pub fn all() -> Vec<Self> { + vec![ + AbilitySlot::A, + AbilitySlot::Q, + AbilitySlot::W, + AbilitySlot::E, + AbilitySlot::R, + AbilitySlot::F, + AbilitySlot::G, + ] + } +} + +impl Index<AbilitySlot> for [Duration; 7] { + type Output = Duration; + + fn index(&self, ability_slot: AbilitySlot) -> &Self::Output { + &self[ability_slot as usize] + } +} + +impl IndexMut<AbilitySlot> for [Duration; 7] { + fn index_mut(&mut self, ability_slot: AbilitySlot) -> &mut Self::Output { + &mut self[ability_slot as usize] + } +} |