SOURCE / PINNED RELEASE
Made of little things.
Limb Race
- Release
- 6a8ae4fc626e…
- Author-recorded commit
- 008c01ee6454…
- License
- LICENSE
- Author’s source reference
- nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-c2869f12ad8
Archive hash verified: 7be8492d1f89b891…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
//! Bevy 0.19 asset source: `napplet://<sha256>.png`, etc.
//! Register BEFORE DefaultPlugins; declare `resource` and Blossom server hints.
//! This uses the sibling `napplet` module and the ordinary host capability.
use bevy::{
asset::{
AssetApp,
io::{AssetReader, AssetReaderError, AssetSourceBuilder, PathStream, Reader, VecReader},
},
prelude::*,
};
use std::path::Path;
pub struct NappletAssets;
impl Plugin for NappletAssets {
fn build(&self, app: &mut App) {
app.register_asset_source(
"napplet",
AssetSourceBuilder::new(|| Box::new(NappletReader)),
);
}
}
struct NappletReader;
impl AssetReader for NappletReader {
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
let hash = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
if path.components().count() != 1
|| hash.len() != 64
|| !hash
.bytes()
.all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
{
return Err(AssetReaderError::NotFound(path.to_owned()));
}
let bytes = crate::napplet::resource_bytes(&format!("blossom:sha256:{hash}"))
.await
.map_err(|e| {
AssetReaderError::Io(std::io::Error::other(crate::napplet::error_message(e)).into())
})?;
Ok(VecReader::new(bytes))
}
async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
Err::<VecReader, _>(AssetReaderError::NotFound(path.to_owned()))
}
async fn read_directory<'a>(
&'a self,
_: &'a Path,
) -> Result<Box<PathStream>, AssetReaderError> {
Err(AssetReaderError::Io(
std::io::Error::new(
std::io::ErrorKind::Unsupported,
"NAP resource sources have no directory listing",
)
.into(),
))
}
async fn is_directory<'a>(&'a self, _: &'a Path) -> Result<bool, AssetReaderError> {
Ok(false)
}
}
