CharacterEntityId
This commit is contained in:
parent
de8f44f269
commit
0954d85e5a
@ -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(),
|
||||
|
@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex};
|
||||
pub struct InMemoryGateway {
|
||||
users: Arc<Mutex<HashMap<u32, UserAccount>>>,
|
||||
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
|
||||
characters: Arc<Mutex<HashMap<u32, CharacterEntity>>>,
|
||||
characters: Arc<Mutex<HashMap<CharacterEntityId, CharacterEntity>>>,
|
||||
items: Arc<Mutex<HashMap<ItemEntityId, Item>>>,
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user