Skip to content

Commit

Permalink
fix: make web builds load assets relative to the path the game is hos…
Browse files Browse the repository at this point in the history
…ted under.
  • Loading branch information
zicklag committed Oct 15, 2023
1 parent 2335ab6 commit c0ea70f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion framework_crates/bones_bevy_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ version = "0.11"
directories = "5.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Window", "Storage"] }
web-sys = { version = "0.3", features = ["Window", "Storage", "Location"] }
5 changes: 4 additions & 1 deletion framework_crates/bones_bevy_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ impl BonesBevyRenderer {
}
#[cfg(target_arch = "wasm32")]
{
let io = bones::WebAssetIo::new("/assets/");
let window = web_sys::window().unwrap();
let path = window.location().pathname().unwrap();
let base = path.rsplit_once('/').map(|x| x.0).unwrap_or(&path);
let io = bones::WebAssetIo::new(&format!("{base}/assets"));
asset_server.set_io(io);
}

Expand Down

0 comments on commit c0ea70f

Please sign in to comment.