bevy_rpack/
lib.rs

1#![doc = include_str!("../README.md")]
2
3#[cfg(feature = "bevy")]
4/// Contains the Bevy plugin for handling `Rpack` assets and atlases.
5mod plugin;
6
7/// Re-exports all types for working with texture atlases.
8pub mod prelude {
9    #[cfg(feature = "bevy")]
10    /// Provides easy access to `Rpack` asset-related functionality in a Bevy application.
11    pub use super::plugin::{
12        RpackAssetHelper, RpackAssetPlugin, RpackAtlasAsset, RpackAtlasAssetError,
13        RpackAtlasAssetLoader, RpackAtlasError, RpackAtlases,
14    };
15    /// Re-exports core types for working with texture atlases.
16    pub use super::{AtlasAsset, AtlasFrame, SerializableRect};
17}
18
19/// Defines a rectangle in pixels with the origin at the top-left of the texture atlas.
20#[derive(Copy, Clone, Debug, serde::Deserialize, serde::Serialize)]
21#[cfg_attr(feature = "bevy", derive(bevy::prelude::Reflect))]
22pub struct SerializableRect {
23    /// Horizontal position the rectangle begins at.
24    pub x: u32,
25    /// Vertical position the rectangle begins at.
26    pub y: u32,
27    /// Width of the rectangle.
28    pub w: u32,
29    /// Height of the rectangle.
30    pub h: u32,
31}
32
33/// Represents a single frame within a texture atlas, including its identifier and position.
34#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
35#[cfg_attr(feature = "bevy", derive(bevy::prelude::Reflect))]
36pub struct AtlasFrame {
37    /// A unique identifier for the frame.
38    pub key: String,
39    /// The rectangular area of the frame within the texture atlas.
40    pub frame: SerializableRect,
41}
42
43/// Represents an entire texture atlas asset, including its metadata and frames.
44#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
45#[cfg_attr(feature = "bevy", derive(bevy::prelude::Asset, bevy::prelude::Reflect))]
46pub struct AtlasAsset {
47    /// The overall dimensions of the texture atlas in pixels (width, height).
48    pub size: [u32; 2],
49    /// The filename associated with the atlas, typically used for loading or debugging.
50    pub filename: String,
51    /// A collection of frames contained within the texture atlas.
52    pub frames: Vec<AtlasFrame>,
53}