From 7b018966fbb8794a8c17abd66e609fef42269aae Mon Sep 17 00:00:00 2001 From: focustense Date: Sat, 14 Oct 2023 14:10:23 -0400 Subject: [PATCH] Normalize paths when converting from LDtk -> Asset path. This avoids creating duplicate assets when the LDTK project is in a subdirectory. May not be compatible with very complex asset hierarchies involving symlinks. #240 --- Cargo.toml | 1 + src/assets.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2adea6e7..4a95e861 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ hex = "0.4" anyhow = "1.0" thiserror = "1.0" paste = "1.0" +path-clean = "1.0.1" [dev-dependencies] bevy = "0.11" diff --git a/src/assets.rs b/src/assets.rs index 3a51a46c..042166da 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -8,13 +8,19 @@ use bevy::{ render::render_resource::{Extent3d, TextureDimension, TextureFormat}, utils::BoxedFuture, }; +use path_clean::PathClean; use std::{collections::HashMap, path::Path}; #[allow(unused_imports)] use crate::components::LdtkWorldBundle; fn ldtk_path_to_asset_path<'b>(ldtk_path: &Path, rel_path: &str) -> AssetPath<'b> { - ldtk_path.parent().unwrap().join(Path::new(rel_path)).into() + ldtk_path + .parent() + .unwrap() + .join(Path::new(rel_path)) + .clean() + .into() } /// Used in [LdtkAsset]. Key is the tileset definition uid.