diff --git a/src/entity/character.rs b/src/entity/character.rs index d10fc44..fe856e7 100644 --- a/src/entity/character.rs +++ b/src/entity/character.rs @@ -227,9 +227,13 @@ pub struct CharacterGuildCard { pub description: String, } + +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct CharacterEntityId(pub u32); + #[derive(Clone)] pub struct CharacterEntity { - pub id: u32, + pub id: CharacterEntityId, pub user_id: u32, pub slot: u32, @@ -249,7 +253,7 @@ pub struct CharacterEntity { impl std::default::Default for CharacterEntity { fn default() -> CharacterEntity { CharacterEntity { - id: 0, + id: CharacterEntityId(0), user_id: 0, slot: 0, name: "".into(), diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 15c90b5..292024a 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex}; pub struct InMemoryGateway { users: Arc>>, user_settings: Arc>>, - characters: Arc>>, + characters: Arc>>, items: Arc>>, } @@ -86,13 +86,13 @@ impl EntityGateway for InMemoryGateway { let mut characters = self.characters.lock().unwrap(); let id = characters .iter() - .fold(0, |sum, (i, _)| std::cmp::max(sum, *i)) + .fold(0, |sum, (i, _)| std::cmp::max(sum, i.0)) + 1; let mut c = CharacterEntity::default(); - c.id = id; + c.id = CharacterEntityId(id); c.user_id = user.id; - characters.insert(id, c.clone()); + characters.insert(CharacterEntityId(id), c.clone()); c } diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index 3c0cb13..9895bfb 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -6,22 +6,25 @@ pub mod tech; pub mod unit; pub mod mag; +use crate::entity::character::CharacterEntityId; + #[derive(PartialEq, Copy, Clone, Debug, Hash, Eq)] pub struct ItemEntityId(pub u32); #[derive(Hash, PartialEq, Eq, Debug, Clone)] pub struct ItemId(u32); - +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct BankName(String); #[derive(Clone, Debug, PartialEq)] pub enum ItemLocation { Inventory { - character_id: u32, + character_id: CharacterEntityId, index: usize, equipped: bool, }, Bank { - character_id: u32, - slot: usize, + character_id: CharacterEntityId, + slot: BankName, }, Floor { // floor: eventually diff --git a/src/ship/items.rs b/src/ship/items.rs index 6875d6d..7a11221 100644 --- a/src/ship/items.rs +++ b/src/ship/items.rs @@ -172,6 +172,7 @@ impl ActiveItemDatabase { #[cfg(test)] mod test { use super::*; + use crate::entity::character::CharacterEntityId; use crate::entity::item; use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation}; #[test] @@ -179,7 +180,7 @@ mod test { let item1 = Item { id: ItemEntityId(1), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 0, equipped: false, }, @@ -194,7 +195,7 @@ mod test { let item2 = Item { id: ItemEntityId(2), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 1, equipped: false, }, @@ -205,7 +206,7 @@ mod test { let item3 = Item { id: ItemEntityId(3), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 2, equipped: false, }, @@ -220,7 +221,7 @@ mod test { let item4 = Item { id: ItemEntityId(4), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 1, equipped: false, }, @@ -231,7 +232,7 @@ mod test { let item5 = Item { id: ItemEntityId(5), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 1, equipped: false, }, @@ -242,7 +243,7 @@ mod test { let item6 = Item { id: ItemEntityId(6), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 3, equipped: false, }, @@ -257,7 +258,7 @@ mod test { let item7 = Item { id: ItemEntityId(7), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 4, equipped: false, }, @@ -268,7 +269,7 @@ mod test { let item8 = Item { id: ItemEntityId(8), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 4, equipped: false, }, @@ -279,7 +280,7 @@ mod test { let item9 = Item { id: ItemEntityId(9), location: ItemLocation::Inventory { - character_id: 0, + character_id: CharacterEntityId(0), index: 4, equipped: false, },