From f34e61ad13f64262f4809462646a0308b06837ef Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Sat, 29 Jun 2024 01:50:04 -0700 Subject: [PATCH] Load from RTP on native too --- crates/core/src/lib.rs | 3 +-- crates/filesystem/src/project.rs | 24 ++++++++++++++++++++++-- crates/graphics/src/loaders/texture.rs | 10 ++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 7a0c4a37..d29e5b92 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -355,11 +355,10 @@ impl<'res> UpdateState<'res> { self.toasts, format!("Failed to find suitable path for the RTP {missing_rtp}") ); - // FIXME we should probably load rtps from the RTP/ paths on non-wasm targets #[cfg(not(target_arch = "wasm32"))] info!( self.toasts, - format!("You may want to set an RTP path for {missing_rtp}") + format!("You may want to set an RTP path for {missing_rtp} (you can place it in the RTP folder)") ); #[cfg(target_arch = "wasm32")] info!(self.toasts, format!("Please place the {missing_rtp} RTP in the 'RTP/{missing_rtp}' subdirectory in your project directory")); diff --git a/crates/filesystem/src/project.rs b/crates/filesystem/src/project.rs index 3945bcfd..f716163f 100644 --- a/crates/filesystem/src/project.rs +++ b/crates/filesystem/src/project.rs @@ -240,6 +240,7 @@ impl FileSystem { #[cfg(windows)] impl FileSystem { fn find_rtp_paths( + filesystem: &host::FileSystem, config: &luminol_config::project::Config, global_config: &luminol_config::global::Config, ) -> (Vec, Vec) { @@ -293,6 +294,14 @@ impl FileSystem { } } + let path = camino::Utf8PathBuf::from("RTP").join(rtp); + if let Ok(exists) = filesystem.exists(&path) { + if exists { + paths.push(path); + continue; + } + } + if let Some(path) = global_config.rtp_paths.get(rtp) { let path = camino::Utf8PathBuf::from(path); if path.exists() { @@ -312,6 +321,7 @@ impl FileSystem { #[cfg(not(any(windows, target_arch = "wasm32")))] impl FileSystem { fn find_rtp_paths( + filesystem: &host::FileSystem, config: &luminol_config::project::Config, global_config: &luminol_config::global::Config, ) -> (Vec, Vec) { @@ -337,6 +347,14 @@ impl FileSystem { } } + let path = camino::Utf8PathBuf::from("RTP").join(rtp); + if let Ok(exists) = filesystem.exists(&path) { + if exists { + paths.push(path); + continue; + } + } + missing_rtps.push(rtp.to_string()); } } @@ -380,9 +398,11 @@ impl FileSystem { .map(archiver::FileSystem::new) .transpose()?; - list.push(host); // FIXME: handle missing rtps - let (found_rtps, missing_rtps) = Self::find_rtp_paths(project_config, global_config); + let (found_rtps, missing_rtps) = Self::find_rtp_paths(&host, project_config, global_config); + + list.push(host); + for path in found_rtps { list.push(host::FileSystem::new(path)) } diff --git a/crates/graphics/src/loaders/texture.rs b/crates/graphics/src/loaders/texture.rs index b9dddaaa..0d0efefc 100644 --- a/crates/graphics/src/loaders/texture.rs +++ b/crates/graphics/src/loaders/texture.rs @@ -269,3 +269,13 @@ impl Loader { &self.placeholder_image } } + +// can't use Arc because of orphan rule, must use &instead (this does allow for for &Texture to be used in Image::new tho) +impl From<&Texture> for egui::load::SizedTexture { + fn from(val: &Texture) -> Self { + egui::load::SizedTexture { + id: val.texture_id, + size: val.size_vec2(), + } + } +}