2022-06-19 19:34:08 +00:00
|
|
|
use hashbrown::HashMap;
|
|
|
|
|
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
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct MoveLibrary {
|
2022-06-11 15:22:46 +00:00
|
|
|
map: HashMap<StringKey, MoveData>,
|
|
|
|
list: Vec<StringKey>,
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MoveLibrary {
|
|
|
|
pub fn new(capacity: usize) -> MoveLibrary {
|
|
|
|
MoveLibrary {
|
|
|
|
map: HashMap::with_capacity(capacity),
|
|
|
|
list: Vec::with_capacity(capacity),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DataLibrary<'_, MoveData> for MoveLibrary {
|
2022-06-11 15:22:46 +00:00
|
|
|
fn map(&self) -> &HashMap<StringKey, MoveData> {
|
2021-01-30 21:29:59 +00:00
|
|
|
&self.map
|
|
|
|
}
|
|
|
|
|
2022-06-11 15:22:46 +00:00
|
|
|
fn list_values(&self) -> &Vec<StringKey> {
|
2021-01-30 21:29:59 +00:00
|
|
|
&self.list
|
|
|
|
}
|
|
|
|
|
2022-06-11 15:22:46 +00:00
|
|
|
fn get_modify(&mut self) -> (&mut HashMap<StringKey, MoveData>, &mut Vec<StringKey>) {
|
2021-01-30 21:29:59 +00:00
|
|
|
(&mut self.map, &mut self.list)
|
|
|
|
}
|
|
|
|
}
|
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(),
|
2021-01-31 16:31:22 +00:00
|
|
|
0,
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|