Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assets/tests/handle/handle_asset_path_when_script_loaded.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local expected_asset_path = "tests/handle/handle_asset_path_when_script_loaded.lua"
function normalize_path(path)
return string.gsub(tostring(path), "\\", "/")
if path then
return string.gsub(path, "\\", "/")
else
return nil
end
end

local normalized_gotten_asset_path = normalize_path(script_asset:asset_path())
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_mod_scripting_core/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
use bevy::{
app::{App, Last},
asset::{Asset, AssetEvent, AssetLoader, AssetPath, Assets, LoadState},
asset::{Asset, AssetEvent, AssetLoader, Assets, LoadState},
log::{error, trace, warn, warn_once},
prelude::{
AssetServer, Commands, Entity, EventReader, EventWriter, IntoScheduleConfigs, Local, Query,
Expand Down Expand Up @@ -59,16 +59,13 @@ pub struct ScriptAsset {
pub content: Box<[u8]>, // Any chance a Cow<'static, ?> could work here?
/// The language of the script
pub language: Language,
/// The asset path of the script.
pub asset_path: AssetPath<'static>,
}

impl From<String> for ScriptAsset {
fn from(s: String) -> ScriptAsset {
ScriptAsset {
content: s.into_bytes().into_boxed_slice(),
language: Language::default(),
asset_path: AssetPath::default(),
}
}
}
Expand Down Expand Up @@ -168,7 +165,6 @@ impl AssetLoader for ScriptAssetLoader {
let asset = ScriptAsset {
content: content.into_boxed_slice(),
language,
asset_path: load_context.asset_path().clone(),
};
Ok(asset)
}
Expand Down
15 changes: 7 additions & 8 deletions crates/bevy_mod_scripting_functions/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,14 @@ impl Handle<ScriptAsset> {
/// * `path`: The asset path of the script asset.
fn asset_path(ctxt: FunctionCallContext, handle: Ref<Handle<ScriptAsset>>) -> Option<String> {
profiling::function_scope!("path");
ctxt.world().ok().and_then(|w| {
w.with_resource(|assets: &Assets<ScriptAsset>| {
// debug
assets
.get(&*handle)
.map(|asset| asset.asset_path.to_string())
handle.path().map(|p| p.to_string()).or_else(|| {
ctxt.world().ok().and_then(|w| {
w.with_resource(|asset_server: &AssetServer| {
asset_server.get_path(&*handle).map(|p| p.to_string())
})
.ok()
.flatten()
})
.ok()
.flatten()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@ impl ScenarioStep {
let boxed_byte_arr = content.into_bytes().into_boxed_slice();
*existing = ScriptAsset {
content: boxed_byte_arr,
asset_path: path.into(),
language: existing.language.clone(),
};
} else {
Expand Down
Loading