Skip to content

Commit

Permalink
Marking asset paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kuviman committed Nov 14, 2024
1 parent 7735ce1 commit 46b8ea1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/geng-asset/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use batbox_file as file;
use futures::prelude::*;
use geng_shader as shader;
use std::borrow::BorrowMut;
use std::cell::RefCell;
use std::future::Future as StdFuture;
use std::path::{Path, PathBuf};
Expand All @@ -25,6 +26,7 @@ struct ManagerImpl {
audio: geng_audio::Audio,
shader_lib: shader::Library,
hot_reload_enabled: bool,
marked_paths: RefCell<Vec<PathBuf>>,
}

#[derive(Clone)]
Expand All @@ -46,9 +48,13 @@ impl Manager {
audio: audio.clone(),
shader_lib: shader::Library::new(window.ugli(), true, None),
hot_reload_enabled: hot_reload,
marked_paths: Default::default(),
}),
}
}
pub fn marked_paths(&self) -> Vec<PathBuf> {
self.inner.marked_paths.borrow().clone()
}
pub async fn yield_now(&self) {
self.inner.window.yield_now().await
}
Expand All @@ -65,24 +71,35 @@ impl Manager {
pub fn hot_reload_enabled(&self) -> bool {
self.inner.hot_reload_enabled
}
pub fn mark_path(&self, path: impl AsRef<Path>) {
self.inner
.marked_paths
.borrow_mut()
.push(path.as_ref().to_owned());
}
pub fn load<T: Load>(&self, path: impl AsRef<Path>) -> Future<T> {
self.mark_path(path.as_ref());
T::load(self, path.as_ref(), &Default::default())
}
pub fn load_with<T: Load>(&self, path: impl AsRef<Path>, options: &T::Options) -> Future<T> {
self.mark_path(path.as_ref());
T::load(self, path.as_ref(), options)
}
pub fn load_string(&self, path: impl AsRef<Path>) -> Future<String> {
self.mark_path(path.as_ref());
let path = path.as_ref().to_owned();
file::load_string(path).boxed_local()
}
pub fn load_bytes(&self, path: impl AsRef<Path>) -> Future<Vec<u8>> {
self.mark_path(path.as_ref());
let path = path.as_ref().to_owned();
file::load_bytes(path).boxed_local()
}
pub fn load_serde<T: 'static + serde::de::DeserializeOwned>(
&self,
path: impl AsRef<Path>,
) -> Future<T> {
self.mark_path(path.as_ref());
let path = path.as_ref().to_owned();
file::load_detect(path).boxed_local()
}
Expand All @@ -93,6 +110,7 @@ impl Manager {
options: &T::Options,
ext: Option<impl AsRef<str>>,
) -> Future<T> {
self.mark_path(path.as_ref());
let path = path.as_ref();
let path_buf_tmp;
let path = match ext.as_ref().map(|s| s.as_ref()).or(T::DEFAULT_EXT) {
Expand Down

0 comments on commit 46b8ea1

Please sign in to comment.