Back to Napplet Machines V8
SOURCE / PINNED RELEASE

Made of little things.

Napplet Machines V8

Release
b3f614e739f0…
Author-recorded commit
534f19acb4ba…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-b5572362d4a

Archive hash verified: 0f7feb97e2c3d336…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

docs/examples/napplet_bevy.rs
//! 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)
    }
}