70 lines
1.6 KiB
Rust
Executable File
70 lines
1.6 KiB
Rust
Executable File
use std::sync::Arc;
|
|
|
|
use indexmap::IndexMap;
|
|
|
|
use crate::static_data::DataLibrary;
|
|
use crate::static_data::MoveData;
|
|
use crate::StringKey;
|
|
|
|
/// A library to store all data for moves.
|
|
#[derive(Debug)]
|
|
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
|
pub struct MoveLibrary {
|
|
/// The underlying map.
|
|
map: IndexMap<StringKey, Arc<MoveData>>,
|
|
}
|
|
|
|
impl MoveLibrary {
|
|
/// Instantiates a new Move Library.
|
|
pub fn new(capacity: usize) -> MoveLibrary {
|
|
MoveLibrary {
|
|
map: IndexMap::with_capacity(capacity),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl DataLibrary<'_, MoveData> for MoveLibrary {
|
|
fn map(&self) -> &IndexMap<StringKey, Arc<MoveData>> {
|
|
&self.map
|
|
}
|
|
fn get_modify(&mut self) -> &mut IndexMap<StringKey, Arc<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(),
|
|
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".into()), m);
|
|
// Drops borrow as mut
|
|
|
|
lib
|
|
}
|
|
}
|