|
@ -13,6 +13,7 @@ pub struct InMemoryGateway { |
|
|
user_settings: Arc<Mutex<BTreeMap<UserSettingsId, UserSettingsEntity>>>,
|
|
|
user_settings: Arc<Mutex<BTreeMap<UserSettingsId, UserSettingsEntity>>>,
|
|
|
characters: Arc<Mutex<BTreeMap<CharacterEntityId, CharacterEntity>>>,
|
|
|
characters: Arc<Mutex<BTreeMap<CharacterEntityId, CharacterEntity>>>,
|
|
|
items: Arc<Mutex<BTreeMap<ItemEntityId, ItemEntity>>>,
|
|
|
items: Arc<Mutex<BTreeMap<ItemEntityId, ItemEntity>>>,
|
|
|
|
|
|
mag_feedings: Arc<Mutex<BTreeMap<ItemEntityId, Vec<ItemEntityId>>>>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl InMemoryGateway {
|
|
|
impl InMemoryGateway {
|
|
@ -22,6 +23,7 @@ impl InMemoryGateway { |
|
|
user_settings: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
user_settings: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
characters: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
characters: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
items: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
items: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
|
|
|
mag_feedings: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -165,6 +167,13 @@ impl EntityGateway for InMemoryGateway { |
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) {
|
|
|
|
|
|
self.mag_feedings.lock().unwrap()
|
|
|
|
|
|
.entry(*mag_item_id)
|
|
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
|
|
.push(*tool_item_id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> {
|
|
|
async fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> {
|
|
|
let items = self.items.lock().unwrap();
|
|
|
let items = self.items.lock().unwrap();
|
|
|
items
|
|
|
items
|
|
@ -179,6 +188,25 @@ impl EntityGateway for InMemoryGateway { |
|
|
.map(|(_, k)| {
|
|
|
.map(|(_, k)| {
|
|
|
k.clone()
|
|
|
k.clone()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
.map(|mut item| {
|
|
|
|
|
|
item.item = match item.item {
|
|
|
|
|
|
ItemDetail::Mag(mut mag) => {
|
|
|
|
|
|
self.mag_feedings.lock().unwrap().get(&item.id).map(|mag_feedings| {
|
|
|
|
|
|
for mag_feed_id in mag_feedings.iter() {
|
|
|
|
|
|
items.get(&mag_feed_id).map(|mag_feed| {
|
|
|
|
|
|
match mag_feed.item {
|
|
|
|
|
|
ItemDetail::Tool(mag_feed) => mag.feed(mag_feed.tool),
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
ItemDetail::Mag(mag)
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => item.item
|
|
|
|
|
|
};
|
|
|
|
|
|
item
|
|
|
|
|
|
})
|
|
|
.collect()
|
|
|
.collect()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|