|
|
@ -16,7 +16,7 @@ pub struct InMemoryGateway { |
|
|
|
users: Arc<Mutex<HashMap<u32, UserAccount>>>,
|
|
|
|
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
|
|
|
|
guildcards: Arc<Mutex<HashMap<u32, GuildCard>>>,
|
|
|
|
characters: Arc<Mutex<HashMap<u32, Character>>>,
|
|
|
|
characters: Arc<Mutex<HashMap<u32, CharacterEntity>>>,
|
|
|
|
items: Arc<Mutex<HashMap<ItemEntityId, Item>>>,
|
|
|
|
}
|
|
|
|
|
|
|
@ -74,7 +74,7 @@ impl EntityGateway for InMemoryGateway { |
|
|
|
new_settings
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_characters_by_user(&self, user: &UserAccount) -> [Option<Character>; 4] {
|
|
|
|
fn get_characters_by_user(&self, user: &UserAccount) -> [Option<CharacterEntity>; 4] {
|
|
|
|
let characters = self.characters.lock().unwrap();
|
|
|
|
let mut chars = [None; 4];
|
|
|
|
characters
|
|
|
@ -84,21 +84,21 @@ impl EntityGateway for InMemoryGateway { |
|
|
|
chars
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_character_by_user(&mut self, user: &UserAccount) -> Character {
|
|
|
|
fn new_character_by_user(&mut self, user: &UserAccount) -> CharacterEntity {
|
|
|
|
let mut characters = self.characters.lock().unwrap();
|
|
|
|
let id = characters
|
|
|
|
.iter()
|
|
|
|
.fold(0, |sum, (i, _)| std::cmp::max(sum, *i))
|
|
|
|
+ 1;
|
|
|
|
|
|
|
|
let mut c = Character::default();
|
|
|
|
let mut c = CharacterEntity::default();
|
|
|
|
c.id = id;
|
|
|
|
c.user_id = user.id;
|
|
|
|
characters.insert(id, c.clone());
|
|
|
|
c
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_character(&mut self, char: &Character) {
|
|
|
|
fn set_character(&mut self, char: &CharacterEntity) {
|
|
|
|
let mut characters = self.characters.lock().unwrap();
|
|
|
|
characters.insert(char.id, char.clone());
|
|
|
|
}
|
|
|
@ -127,7 +127,7 @@ impl EntityGateway for InMemoryGateway { |
|
|
|
items.insert(item.id, item.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_items_by_character(&self, character: &Character) -> Vec<Item> {
|
|
|
|
fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<Item> {
|
|
|
|
let items = self.items.lock().unwrap();
|
|
|
|
items
|
|
|
|
.iter()
|
|
|
@ -144,7 +144,7 @@ impl EntityGateway for InMemoryGateway { |
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_guild_card_by_character(&self, character: &Character) -> GuildCard {
|
|
|
|
fn create_guild_card_by_character(&self, character: &CharacterEntity) -> GuildCard {
|
|
|
|
let mut guildcards = self.guildcards.lock().unwrap();
|
|
|
|
let user = self.get_user_by_id(character.user_id).unwrap();
|
|
|
|
let settings = self.get_user_settings_by_user(&user).unwrap();
|
|
|
@ -172,7 +172,7 @@ impl EntityGateway for InMemoryGateway { |
|
|
|
new_guildcard
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_guild_card_by_character(&self, character: &Character) -> Option<GuildCard> {
|
|
|
|
fn get_guild_card_by_character(&self, character: &CharacterEntity) -> Option<GuildCard> {
|
|
|
|
let guildcards = self.guildcards.lock().unwrap();
|
|
|
|
guildcards
|
|
|
|
.iter()
|
|
|
|