Skip to content

Commit

Permalink
migrate asset loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Nov 5, 2024
1 parent f41fbf7 commit 5d63890
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
28 changes: 12 additions & 16 deletions crates/languages/bevy_mod_scripting_lua/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,20 @@ impl AssetLoader for LuaLoader {
type Settings = ();
type Error = Error;

fn load<'a>(
&'a self,
reader: &'a mut Reader, //bytes: &'a [u8],
_settings: &'a (),
load_context: &'a mut bevy::asset::LoadContext,
) -> impl bevy::utils::ConditionalSendFuture<
Output = std::result::Result<
<Self as bevy::asset::AssetLoader>::Asset,
<Self as bevy::asset::AssetLoader>::Error,
>,
async fn load(
&self,
reader: &mut dyn Reader, //bytes: &'a [u8],
_settings: &(),
load_context: &mut bevy::asset::LoadContext<'_>,
) -> std::result::Result<
<Self as bevy::asset::AssetLoader>::Asset,
<Self as bevy::asset::AssetLoader>::Error,
> {
bevy::prelude::info!("lua loader invoked: {:#}", load_context.asset_path());
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let bytes = old_lua_load(bytes.as_slice(), load_context).await?;
Ok(LuaFile { bytes }) //})
})
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let bytes = old_lua_load(bytes.as_slice(), load_context).await?;
Ok(LuaFile { bytes })
}

#[cfg(feature = "teal")]
Expand Down
10 changes: 5 additions & 5 deletions crates/languages/bevy_mod_scripting_rhai/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ impl AssetLoader for RhaiLoader {
type Asset = RhaiFile;
type Settings = ();
type Error = anyhow::Error;
async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_: &'a Self::Settings,
_: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_: &Self::Settings,
_: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down
25 changes: 9 additions & 16 deletions crates/languages/bevy_mod_scripting_rune/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,15 @@ impl AssetLoader for RuneLoader {
type Settings = ();
type Error = Error;

fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a (),
_load_context: &'a mut bevy::asset::LoadContext,
) -> impl bevy::utils::ConditionalSendFuture<
Output = std::result::Result<
<Self as bevy::asset::AssetLoader>::Asset,
<Self as bevy::asset::AssetLoader>::Error,
>,
> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Ok(RuneFile { bytes })
})
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &(),
_load_context: &mut bevy::asset::LoadContext<'_>,
) -> std::result::Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Ok(RuneFile { bytes })
}

fn extensions(&self) -> &[&str] {
Expand Down

0 comments on commit 5d63890

Please sign in to comment.