A lot more work on a bunch of different parts of the system.

This commit is contained in:
2022-06-11 17:22:46 +02:00
parent 10e93949e4
commit 6e8f4dd4a5
35 changed files with 735 additions and 197 deletions

View File

@@ -1,11 +1,12 @@
use crate::static_data::items::item::Item;
use crate::static_data::libraries::data_library::DataLibrary;
use crate::StringKey;
use hashbrown::HashMap;
#[derive(Debug)]
pub struct ItemLibrary {
map: HashMap<String, Box<Item>>,
list: Vec<String>,
map: HashMap<StringKey, Box<Item>>,
list: Vec<StringKey>,
}
impl ItemLibrary {
@@ -18,15 +19,15 @@ impl ItemLibrary {
}
impl DataLibrary<'_, Box<Item>> for ItemLibrary {
fn map(&self) -> &HashMap<String, Box<Item>> {
fn map(&self) -> &HashMap<StringKey, Box<Item>> {
&self.map
}
fn list_values(&self) -> &Vec<String> {
fn list_values(&self) -> &Vec<StringKey> {
&self.list
}
fn get_modify(&mut self) -> (&mut HashMap<String, Box<Item>>, &mut Vec<String>) {
fn get_modify(&mut self) -> (&mut HashMap<StringKey, Box<Item>>, &mut Vec<StringKey>) {
(&mut self.map, &mut self.list)
}
}
@@ -41,7 +42,7 @@ pub mod tests {
fn build_item() -> Item {
Item::new(
"foo",
&"foo".into(),
ItemCategory::MiscItem,
BattleItemCategory::MiscBattleItem,
100,
@@ -54,7 +55,7 @@ pub mod tests {
let m = build_item();
// Borrow as mut so we can insert
let w = &mut lib;
w.add("foo", Box::from(m));
w.add(&"foo".into(), Box::from(m));
// Drops borrow as mut
lib