PkmnLib_rs/src/static_data/libraries/move_library.rs

67 lines
1.5 KiB
Rust
Raw Normal View History

2022-07-01 15:07:22 +00:00
use indexmap::IndexMap;
2022-06-11 18:51:37 +00:00
use crate::static_data::DataLibrary;
use crate::static_data::MoveData;
use crate::StringKey;
2022-07-01 15:07:22 +00:00
/// A library to store all data for moves.
#[derive(Debug)]
pub struct MoveLibrary {
2022-07-01 15:07:22 +00:00
/// The underlying map.
map: IndexMap<StringKey, MoveData>,
}
impl MoveLibrary {
2022-07-01 15:07:22 +00:00
/// Instantiates a new Move Library.
pub fn new(capacity: usize) -> MoveLibrary {
MoveLibrary {
2022-07-01 15:07:22 +00:00
map: IndexMap::with_capacity(capacity),
}
}
}
impl DataLibrary<'_, MoveData> for MoveLibrary {
2022-07-01 15:07:22 +00:00
fn map(&self) -> &IndexMap<StringKey, MoveData> {
&self.map
}
2022-07-01 15:07:22 +00:00
fn get_modify(&mut self) -> &mut IndexMap<StringKey, MoveData> {
&mut self.map
}
}
#[cfg(test)]
pub mod tests {
use hashbrown::HashSet;
use crate::static_data::libraries::data_library::DataLibrary;
use crate::static_data::libraries::move_library::MoveLibrary;
use crate::static_data::{MoveCategory, MoveData, MoveTarget};
use crate::StringKey;
fn build_move() -> MoveData {
MoveData::new(
&"foo".into(),
2022-07-01 15:07:22 +00:00
0.into(),
MoveCategory::Physical,
100,
100,
30,
MoveTarget::Any,
0,
None,
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;
w.add(&StringKey::new("foo"), m);
// Drops borrow as mut
lib
}
}