mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'sam/remove-unwraps' into 'master'
Removed unwraps in buffs See merge request veloren/veloren!2196
This commit is contained in:
commit
3cfc94af45
@ -340,7 +340,8 @@ impl Buffs {
|
|||||||
let buffs = &self.buffs;
|
let buffs = &self.buffs;
|
||||||
// Intentionally sorted in reverse so that the strongest buffs are earlier in
|
// Intentionally sorted in reverse so that the strongest buffs are earlier in
|
||||||
// the vector
|
// the vector
|
||||||
buff_order.sort_by(|a, b| buffs[&b].partial_cmp(&buffs[&a]).unwrap());
|
buff_order
|
||||||
|
.sort_by(|a, b| buffs[&b].partial_cmp(&buffs[&a]).unwrap_or(Ordering::Equal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,19 +383,19 @@ impl Buffs {
|
|||||||
pub fn iter_active(&self) -> impl Iterator<Item = &Buff> + '_ {
|
pub fn iter_active(&self) -> impl Iterator<Item = &Buff> + '_ {
|
||||||
self.kinds
|
self.kinds
|
||||||
.values()
|
.values()
|
||||||
.map(move |ids| self.buffs.get(&ids[0]))
|
.filter_map(move |ids| self.buffs.get(&ids[0]))
|
||||||
.filter(|buff| buff.is_some())
|
|
||||||
.map(|buff| buff.unwrap())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets most powerful buff of a given kind
|
// Gets most powerful buff of a given kind
|
||||||
// pub fn get_active_kind(&self, kind: BuffKind) -> Buff
|
// pub fn get_active_kind(&self, kind: BuffKind) -> Buff
|
||||||
pub fn remove(&mut self, buff_id: BuffId) {
|
pub fn remove(&mut self, buff_id: BuffId) {
|
||||||
let kind = self.buffs.remove(&buff_id).unwrap().kind;
|
if let Some(kind) = self.buffs.remove(&buff_id) {
|
||||||
self.kinds
|
let kind = kind.kind;
|
||||||
.get_mut(&kind)
|
self.kinds
|
||||||
.map(|ids| ids.retain(|id| *id != buff_id));
|
.get_mut(&kind)
|
||||||
self.sort_kind(kind);
|
.map(|ids| ids.retain(|id| *id != buff_id));
|
||||||
|
self.sort_kind(kind);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an immutable reference to the buff kinds on an entity, and a
|
/// Returns an immutable reference to the buff kinds on an entity, and a
|
||||||
|
Loading…
Reference in New Issue
Block a user