Add get_mut_untracked to Assets (#19487)
# Objective Fixes #13104 ## Solution Add a `get_mut_untracked` method to `Assets`
This commit is contained in:
parent
c5dcef5e61
commit
6fee6fe827
@ -437,6 +437,18 @@ impl<A: Asset> Assets<A> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves a mutable reference to the [`Asset`] with the given `id`, if it exists.
|
||||||
|
///
|
||||||
|
/// This is the same as [`Assets::get_mut`] except it doesn't emit [`AssetEvent::Modified`].
|
||||||
|
#[inline]
|
||||||
|
pub fn get_mut_untracked(&mut self, id: impl Into<AssetId<A>>) -> Option<&mut A> {
|
||||||
|
let id: AssetId<A> = id.into();
|
||||||
|
match id {
|
||||||
|
AssetId::Index { index, .. } => self.dense_storage.get_mut(index),
|
||||||
|
AssetId::Uuid { uuid } => self.hash_map.get_mut(&uuid),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes (and returns) the [`Asset`] with the given `id`, if it exists.
|
/// Removes (and returns) the [`Asset`] with the given `id`, if it exists.
|
||||||
/// Note that this supports anything that implements `Into<AssetId<A>>`, which includes [`Handle`] and [`AssetId`].
|
/// Note that this supports anything that implements `Into<AssetId<A>>`, which includes [`Handle`] and [`AssetId`].
|
||||||
pub fn remove(&mut self, id: impl Into<AssetId<A>>) -> Option<A> {
|
pub fn remove(&mut self, id: impl Into<AssetId<A>>) -> Option<A> {
|
||||||
@ -450,6 +462,8 @@ impl<A: Asset> Assets<A> {
|
|||||||
|
|
||||||
/// Removes (and returns) the [`Asset`] with the given `id`, if it exists. This skips emitting [`AssetEvent::Removed`].
|
/// Removes (and returns) the [`Asset`] with the given `id`, if it exists. This skips emitting [`AssetEvent::Removed`].
|
||||||
/// Note that this supports anything that implements `Into<AssetId<A>>`, which includes [`Handle`] and [`AssetId`].
|
/// Note that this supports anything that implements `Into<AssetId<A>>`, which includes [`Handle`] and [`AssetId`].
|
||||||
|
///
|
||||||
|
/// This is the same as [`Assets::remove`] except it doesn't emit [`AssetEvent::Removed`].
|
||||||
pub fn remove_untracked(&mut self, id: impl Into<AssetId<A>>) -> Option<A> {
|
pub fn remove_untracked(&mut self, id: impl Into<AssetId<A>>) -> Option<A> {
|
||||||
let id: AssetId<A> = id.into();
|
let id: AssetId<A> = id.into();
|
||||||
self.duplicate_handles.remove(&id);
|
self.duplicate_handles.remove(&id);
|
||||||
|
Loading…
Reference in New Issue
Block a user