Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create AssetSaver implementations for each format. #31

Open
andriyDev opened this issue Mar 5, 2024 · 1 comment
Open

Create AssetSaver implementations for each format. #31

andriyDev opened this issue Mar 5, 2024 · 1 comment

Comments

@andriyDev
Copy link

Bevy now has AssetSaver. This allows a cross-platform way of saving assets by:

  1. Getting an AssetWriter from an AssetSource (from AssetServer)
  2. Calling AssetWriter::write to get an AsyncWrite object.
  3. Calling AssetSaver::save with that AsyncWrite object.

In the future this will likely be streamlined but for now we should support AssetSaver to support this "canonical" workflow.

@NiklasEi
Copy link
Owner

NiklasEi commented Aug 6, 2024

For reference: the postcard feature already includes an asset saver

impl<A: Asset + for<'de> Deserialize<'de> + Serialize> AssetSaver for PostcardAssetSaver<A> {
type Asset = A;
type Settings = ();
type OutputLoader = PostcardAssetLoader<A>;
type Error = PostcardAssetError;
async fn save<'a>(
&'a self,
writer: &'a mut bevy::asset::io::Writer,
asset: bevy::asset::saver::SavedAsset<'a, Self::Asset>,
_settings: &'a Self::Settings,
) -> Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error> {
let bytes = to_stdvec(&asset.get())?;
writer.write_all(&bytes).await?;
Ok(())
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants