2022-07-01 15:07:22 +00:00
|
|
|
use indexmap::IndexMap;
|
2022-06-19 19:34:08 +00:00
|
|
|
|
2022-06-11 18:51:37 +00:00
|
|
|
use crate::static_data::DataLibrary;
|
|
|
|
use crate::static_data::MoveData;
|
2022-06-11 15:22:46 +00:00
|
|
|
use crate::StringKey;
|
2021-01-30 21:29:59 +00:00
|
|
|
|
2022-07-01 15:07:22 +00:00
|
|
|
/// A library to store all data for moves.
|
2021-01-30 21:29:59 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct MoveLibrary {
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The underlying map.
|
|
|
|
map: IndexMap<StringKey, MoveData>,
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MoveLibrary {
|
2022-07-01 15:07:22 +00:00
|
|
|
/// Instantiates a new Move Library.
|
2021-01-30 21:29:59 +00:00
|
|
|
pub fn new(capacity: usize) -> MoveLibrary {
|
|
|
|
MoveLibrary {
|
2022-07-01 15:07:22 +00:00
|
|
|
map: IndexMap::with_capacity(capacity),
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DataLibrary<'_, MoveData> for MoveLibrary {
|
2022-07-01 15:07:22 +00:00
|
|
|
fn map(&self) -> &IndexMap<StringKey, MoveData> {
|
2021-01-30 21:29:59 +00:00
|
|
|
&self.map
|
|
|
|
}
|
2022-07-01 15:07:22 +00:00
|
|
|
fn get_modify(&mut self) -> &mut IndexMap<StringKey, MoveData> {
|
|
|
|
&mut self.map
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-31 16:31:22 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
pub mod tests {
|
2022-06-19 19:34:08 +00:00
|
|
|
use hashbrown::HashSet;
|
|
|
|
|
2021-01-31 16:31:22 +00:00
|
|
|
use crate::static_data::libraries::data_library::DataLibrary;
|
|
|
|
use crate::static_data::libraries::move_library::MoveLibrary;
|
2022-06-19 19:34:08 +00:00
|
|
|
use crate::static_data::{MoveCategory, MoveData, MoveTarget};
|
2022-06-11 15:22:46 +00:00
|
|
|
use crate::StringKey;
|
2021-01-31 16:31:22 +00:00
|
|
|
|
|
|
|
fn build_move() -> MoveData {
|
|
|
|
MoveData::new(
|
2022-06-11 15:22:46 +00:00
|
|
|
&"foo".into(),
|
2022-07-01 15:07:22 +00:00
|
|
|
0.into(),
|
2021-01-31 16:31:22 +00:00
|
|
|
MoveCategory::Physical,
|
|
|
|
100,
|
|
|
|
100,
|
|
|
|
30,
|
|
|
|
MoveTarget::Any,
|
|
|
|
0,
|
2022-06-19 10:07:54 +00:00
|
|
|
None,
|
2021-01-31 16:31:22 +00:00
|
|
|
HashSet::new(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build() -> MoveLibrary {
|
|
|
|
let mut lib = MoveLibrary::new(1);
|
|
|
|
let m = build_move();
|
|
|
|
// Borrow as mut so we can insert
|
|
|
|
let w = &mut lib;
|
2022-06-11 15:22:46 +00:00
|
|
|
w.add(&StringKey::new("foo"), m);
|
2021-01-31 16:31:22 +00:00
|
|
|
// Drops borrow as mut
|
|
|
|
|
|
|
|
lib
|
|
|
|
}
|
|
|
|
}
|