diff options
| author | HampusM <hampus@hampusmat.com> | 2025-11-06 19:04:02 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2025-11-06 19:04:02 +0100 |
| commit | 3e19baab36762b4816301dab591405d3f1561287 (patch) | |
| tree | 70e07a4cbd67386984d168d631cc1de3ca714ab0 | |
| parent | 72cf01d464c9f5b192c0254c7dab17ffcaf69e44 (diff) | |
feat(engine): add fn Assets::store_with_name_with
| -rw-r--r-- | engine/src/asset.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/engine/src/asset.rs b/engine/src/asset.rs index db4d23c..e78b6d8 100644 --- a/engine/src/asset.rs +++ b/engine/src/asset.rs @@ -1,4 +1,4 @@ -use std::any::{type_name, Any}; +use std::any::{Any, type_name}; use std::borrow::Cow; use std::cell::RefCell; use std::collections::HashMap; @@ -8,16 +8,16 @@ use std::fmt::{Debug, Display}; use std::hash::{DefaultHasher, Hash, Hasher}; use std::marker::PhantomData; use std::path::{Path, PathBuf}; +use std::sync::Arc; use std::sync::mpsc::{ - channel as mpsc_channel, Receiver as MpscReceiver, Sender as MpscSender, + channel as mpsc_channel, }; -use std::sync::Arc; +use ecs::Sole; use ecs::phase::PRE_UPDATE as PRE_UPDATE_PHASE; use ecs::sole::Single; -use ecs::Sole; use crate::work_queue::{Work, WorkQueue}; @@ -293,6 +293,23 @@ impl Assets ) } + pub fn store_with_name_with<'name, Asset: 'static + Send + Sync>( + &mut self, + name: impl Into<Cow<'name, str>>, + func: impl FnOnce(&mut Self) -> Asset, + ) -> Handle<Asset> + { + let asset = func(self); + + self.store_with_label( + Label { + path: Path::new("").into(), + name: Some(name.into()), + }, + asset, + ) + } + #[tracing::instrument(skip(self, asset), fields(asset_type=type_name::<Asset>()))] pub fn store_with_label<'i, Asset: 'static + Send + Sync>( &mut self, |
