Skip to content

Commit

Permalink
Merge pull request #167 from yarn-slinger/fix-asset-path
Browse files Browse the repository at this point in the history
Fix asset paths containing backslashes on Windows
  • Loading branch information
janhohenheim authored Jan 23, 2024
2 parents 43051e3 + 9535962 commit f74ebeb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ impl FileExtensionAssetProvider {
let file_name =
format!("{}.{extension}", line_id.0.trim_start_matches("line:"));
let path = dir.join(file_name);
let handle = asset_server.load_untyped(path.clone());
let asset_path = path.to_string_lossy().replace('\\', "/");
let handle = asset_server.load_untyped(asset_path);
self.loading_handles.insert(path, handle);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ impl UnderlyingTextProvider for StringsFileTextProvider {
panic!("Set language to {language}, but that language is not supported. Expected one of {languages}.");
};
let path = localization.strings_file.as_path();
let asset_path = path.to_string_lossy().replace('\\', "/");
self.strings_file_handle
.replace(self.asset_server.load(path.to_owned()));
.replace(self.asset_server.load(asset_path));
}

fn get_language(&self) -> Option<Language> {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_plugin/src/localization/strings_file/updating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fn update_all_strings_files_for_string_table(
for localization in &localizations.translations {
let language = &localization.language;
let path = localization.strings_file.as_path();
let handle = asset_server.load(path.to_owned());
let asset_path = path.to_string_lossy().replace('\\', "/");
let handle = asset_server.load(asset_path);
languages_to_handles.insert(language.clone(), handle);
}
if languages_to_handles.is_empty() {
Expand Down
12 changes: 7 additions & 5 deletions crates/bevy_plugin/src/plugin/yarn_file_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ impl YarnFileSource {
asset_root: &AssetRoot,
) -> Result<Vec<Handle<YarnFile>>> {
let path = asset_root.0.join(path);
// recursively glob
ensure!(path.is_dir(), "Failed to load Yarn file folder {path}.\nHelp: Does the folder exist under the assets directory?", path = path.display());
ensure!(
path.is_dir(),
"Failed to load Yarn file folder {path}.\nHelp: Does the folder exist?",
path = path.display()
);
let handles: Result<Vec<_>> =
glob(path.join("**/*.yarn").to_str().with_context(|| {
format!(
Expand All @@ -96,10 +99,9 @@ impl YarnFileSource {
})?)?
.map(|entry| {
let full_path = entry?;
// strip
let path = full_path.strip_prefix(&asset_root.0)?;
let path = path.to_str().unwrap();
Ok(asset_server.load(path.to_owned()))
let asset_path = path.to_string_lossy().replace('\\', "/");
Ok(asset_server.load(asset_path))
})
.collect();
let handles = handles?;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Yarn Slinger

The Rust port of Yarn Spinner, the friendly tool for writing game dialogue. The more in [the book](https://yarn-slinger.github.io/yarn-slinger/).
The Rust port of Yarn Spinner, the friendly tool for writing game dialogue. Read more in [the book](https://yarn-slinger.github.io/yarn-slinger/).

## Relationship with Yarn Spinner

Expand Down

0 comments on commit f74ebeb

Please sign in to comment.