fix tag removing

This commit is contained in:
Vincent Foulon 2021-03-30 19:01:38 +02:00 committed by Marcel Märtens
parent b1718cf578
commit 114715908a
2 changed files with 7 additions and 4 deletions

View File

@ -47,7 +47,10 @@ impl Behavior {
/// Revoke a tag to the Behavior
pub fn remove_tag(&mut self, tag: BehaviorTag) {
if self.has_tag(&tag) {
self.tags.remove(&tag);
let tag = self.get_tag(&tag).cloned();
if let Some(tag) = tag {
self.tags.remove(&tag);
}
}
}
@ -59,10 +62,10 @@ impl Behavior {
}
/// Get a specific tag by variant
pub fn get_tag(&self, tag: BehaviorTag) -> Option<&BehaviorTag> {
pub fn get_tag(&self, tag: &BehaviorTag) -> Option<&BehaviorTag> {
self.tags
.iter()
.find(|behavior_tag| mem::discriminant(*behavior_tag) == mem::discriminant(&tag))
.find(|behavior_tag| mem::discriminant(*behavior_tag) == mem::discriminant(tag))
}
}

View File

@ -73,7 +73,7 @@ impl Index {
pub fn colors(&self) -> AssetHandle<Arc<Colors>> { self.colors }
pub fn get_site_prices(&self, behavior: &Behavior) -> Option<SitePrices> {
if let Some(BehaviorTag::CanTrade(site_id)) = behavior.get_tag(BehaviorTag::CanTrade(None))
if let Some(BehaviorTag::CanTrade(site_id)) = behavior.get_tag(&BehaviorTag::CanTrade(None))
{
site_id
.map(|i| self.sites.recreate_id(i))