2020-11-11 01:06:55 +00:00
|
|
|
use bevy_utils::{AHashExt, HashMap};
|
|
|
|
use std::hash::Hash;
|
2020-09-18 21:43:47 +00:00
|
|
|
|
2020-10-08 18:43:01 +00:00
|
|
|
#[derive(Debug)]
|
2020-09-18 21:43:47 +00:00
|
|
|
pub struct Axis<T> {
|
|
|
|
axis_data: HashMap<T, f32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Default for Axis<T>
|
|
|
|
where
|
|
|
|
T: Copy + Eq + Hash,
|
|
|
|
{
|
|
|
|
fn default() -> Self {
|
|
|
|
Axis {
|
|
|
|
axis_data: HashMap::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Axis<T>
|
|
|
|
where
|
|
|
|
T: Copy + Eq + Hash,
|
|
|
|
{
|
|
|
|
pub fn set(&mut self, axis: T, value: f32) -> Option<f32> {
|
|
|
|
self.axis_data.insert(axis, value)
|
|
|
|
}
|
|
|
|
|
2020-10-21 17:27:00 +00:00
|
|
|
pub fn get(&self, axis: T) -> Option<f32> {
|
|
|
|
self.axis_data.get(&axis).copied()
|
2020-09-18 21:43:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 17:27:00 +00:00
|
|
|
pub fn remove(&mut self, axis: T) -> Option<f32> {
|
|
|
|
self.axis_data.remove(&axis)
|
2020-09-18 21:43:47 +00:00
|
|
|
}
|
|
|
|
}
|