mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
fix tag removing
This commit is contained in:
parent
b1718cf578
commit
114715908a
@ -47,9 +47,12 @@ impl Behavior {
|
|||||||
/// Revoke a tag to the Behavior
|
/// Revoke a tag to the Behavior
|
||||||
pub fn remove_tag(&mut self, tag: BehaviorTag) {
|
pub fn remove_tag(&mut self, tag: BehaviorTag) {
|
||||||
if self.has_tag(&tag) {
|
if self.has_tag(&tag) {
|
||||||
|
let tag = self.get_tag(&tag).cloned();
|
||||||
|
if let Some(tag) = tag {
|
||||||
self.tags.remove(&tag);
|
self.tags.remove(&tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if the Behavior possess a specific tag
|
/// Check if the Behavior possess a specific tag
|
||||||
pub fn has_tag(&self, tag: &BehaviorTag) -> bool {
|
pub fn has_tag(&self, tag: &BehaviorTag) -> bool {
|
||||||
@ -59,10 +62,10 @@ impl Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get a specific tag by variant
|
/// 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
|
self.tags
|
||||||
.iter()
|
.iter()
|
||||||
.find(|behavior_tag| mem::discriminant(*behavior_tag) == mem::discriminant(&tag))
|
.find(|behavior_tag| mem::discriminant(*behavior_tag) == mem::discriminant(tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ impl Index {
|
|||||||
pub fn colors(&self) -> AssetHandle<Arc<Colors>> { self.colors }
|
pub fn colors(&self) -> AssetHandle<Arc<Colors>> { self.colors }
|
||||||
|
|
||||||
pub fn get_site_prices(&self, behavior: &Behavior) -> Option<SitePrices> {
|
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
|
site_id
|
||||||
.map(|i| self.sites.recreate_id(i))
|
.map(|i| self.sites.recreate_id(i))
|
||||||
|
Loading…
Reference in New Issue
Block a user