mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Revamped asset directory search system
This commit is contained in:
parent
0ec240ea8e
commit
107f5caa34
@ -116,16 +116,47 @@ impl Asset for Value {
|
||||
|
||||
// TODO: System to load file from specifiers (e.g.: "core.ui.backgrounds.city").
|
||||
fn assets_folder() -> PathBuf {
|
||||
match std::env::current_exe() {
|
||||
Ok(mut exe_path) => {
|
||||
exe_path.pop();
|
||||
find_folder::Search::Parents(3)
|
||||
.of(exe_path)
|
||||
.for_folder("assets")
|
||||
}
|
||||
Err(_) => find_folder::Search::Parents(3).for_folder("assets"),
|
||||
let mut paths = Vec::new();
|
||||
|
||||
// VELOREN_ASSETS environment variable
|
||||
if let Ok(var) = std::env::var("VELOREN_ASSETS") {
|
||||
paths.push(var.to_string().into());
|
||||
}
|
||||
.expect("Could not find assets folder")
|
||||
|
||||
// Executable path
|
||||
if let Ok(mut path) = std::env::current_exe() {
|
||||
path.pop();
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
// Working path
|
||||
if let Ok(mut path) = std::env::current_dir() {
|
||||
path.pop();
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
// System paths
|
||||
#[cfg(target_os = "linux")]
|
||||
paths.push("/usr/share/veloren/assets".into());
|
||||
|
||||
for path in paths.clone() {
|
||||
match find_folder::Search::ParentsThenKids(3, 1)
|
||||
.of(path)
|
||||
.for_folder("assets")
|
||||
{
|
||||
Ok(assets_path) => return assets_path,
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
|
||||
panic!(
|
||||
"Could not find assets folder (tried to search... {})",
|
||||
paths.iter().fold(String::new(), |mut a, path| {
|
||||
a += path.to_str().unwrap_or("<invalid>");
|
||||
a += "\n";
|
||||
a
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: System to load file from specifiers (e.g.: "core.ui.backgrounds.city").
|
||||
|
Loading…
Reference in New Issue
Block a user