From d2dfeea6c21225c67dd127a0511fe40acab055d1 Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Mon, 27 Jan 2025 17:30:52 +0100 Subject: [PATCH] RpackAtlases system param --- crates/bevy_rpack/CHANGELOG.md | 17 +++++++++++++++++ crates/bevy_rpack/Cargo.toml | 2 +- crates/bevy_rpack/examples/simple.rs | 10 +++++----- crates/bevy_rpack/src/lib.rs | 2 +- crates/bevy_rpack/src/plugin.rs | 5 +++++ crates/rpack_cli/Cargo.toml | 2 +- 6 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 crates/bevy_rpack/CHANGELOG.md diff --git a/crates/bevy_rpack/CHANGELOG.md b/crates/bevy_rpack/CHANGELOG.md new file mode 100644 index 0000000..201512d --- /dev/null +++ b/crates/bevy_rpack/CHANGELOG.md @@ -0,0 +1,17 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + +## [0.1.1] - 2025-01-27 + +### Added + +- `RpackAtlases` system param. + +## [0.1.0] - 2025-01-14 + +- initial version \ No newline at end of file diff --git a/crates/bevy_rpack/Cargo.toml b/crates/bevy_rpack/Cargo.toml index 410e4cf..01403a5 100644 --- a/crates/bevy_rpack/Cargo.toml +++ b/crates/bevy_rpack/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_rpack" description = "Bevy plugin with rpack atlas support" -version = "0.1.0" +version = "0.1.1" edition = "2021" repository = "https://github.com/Leinnan/rpack.git" homepage = "https://github.com/Leinnan/rpack" diff --git a/crates/bevy_rpack/examples/simple.rs b/crates/bevy_rpack/examples/simple.rs index f5de204..7cfa318 100644 --- a/crates/bevy_rpack/examples/simple.rs +++ b/crates/bevy_rpack/examples/simple.rs @@ -22,21 +22,21 @@ fn setup(mut commands: Commands, asset_server: Res) { fn on_loaded( mut ev_asset: EventReader>, - assets: Res>, + atlases: RpackAtlases, mut commands: Commands, ) { for ev in ev_asset.read() { - let AssetEvent::LoadedWithDependencies { id: _ } = ev else { + if !matches!(ev, AssetEvent::LoadedWithDependencies { id: _ }) { continue; - }; + } - if let Ok(sprite) = assets.try_make_sprite("agents/spaceAstronauts_005") { + if let Ok(sprite) = atlases.try_make_sprite("agents/spaceAstronauts_005") { commands.spawn(Sprite { color: Color::linear_rgb(1.0, 0.0, 0.0), ..sprite }); }; - if let Ok(image_node) = assets.try_make_image_node("agents/spaceShips_006") { + if let Ok(image_node) = atlases.try_make_image_node("agents/spaceShips_006") { commands.spawn(image_node); } } diff --git a/crates/bevy_rpack/src/lib.rs b/crates/bevy_rpack/src/lib.rs index d2a3822..e5b1d2d 100644 --- a/crates/bevy_rpack/src/lib.rs +++ b/crates/bevy_rpack/src/lib.rs @@ -10,7 +10,7 @@ pub mod prelude { /// Provides easy access to `Rpack` asset-related functionality in a Bevy application. pub use super::plugin::{ RpackAssetHelper, RpackAssetPlugin, RpackAtlasAsset, RpackAtlasAssetError, - RpackAtlasAssetLoader, RpackAtlasError, + RpackAtlasAssetLoader, RpackAtlasError, RpackAtlases, }; /// Re-exports core types for working with texture atlases. pub use super::{AtlasAsset, AtlasFrame, SerializableRect}; diff --git a/crates/bevy_rpack/src/plugin.rs b/crates/bevy_rpack/src/plugin.rs index 0c3f7bc..0e3fdc3 100644 --- a/crates/bevy_rpack/src/plugin.rs +++ b/crates/bevy_rpack/src/plugin.rs @@ -1,5 +1,6 @@ use crate::{AtlasAsset, SerializableRect}; use bevy::asset::{AssetLoader, AsyncReadExt}; +use bevy::ecs::system::SystemParam; use bevy::image::ImageSampler; use bevy::{prelude::*, utils::HashMap}; use thiserror::Error; @@ -38,6 +39,10 @@ impl From for URect { } } +/// SystemParam helper for accessing and creating components from `Rpack` atlas data. +#[derive(SystemParam, DerefMut, Deref)] +pub struct RpackAtlases<'w>(pub Res<'w, Assets>); + /// A helper trait for accessing and creating components from `Rpack` atlas data. #[allow(dead_code)] pub trait RpackAssetHelper { diff --git a/crates/rpack_cli/Cargo.toml b/crates/rpack_cli/Cargo.toml index 557e43b..24557c3 100644 --- a/crates/rpack_cli/Cargo.toml +++ b/crates/rpack_cli/Cargo.toml @@ -27,4 +27,4 @@ clap = { version = "4", features = ["derive"], optional = true } glob = { version = "0.3", optional = true } basis-universal = { version = "0.3.1", optional = true } image_dds = { version = "0.7", optional = true } -anyhow = "1" \ No newline at end of file +anyhow = "1"