Galactica/crates/packer/src/lib.rs

53 lines
1.3 KiB
Rust

#![warn(missing_docs)]
//! This crate creates texture atlases from an asset tree.
use std::{collections::HashMap, path::PathBuf};
use serde::{Deserialize, Serialize};
/// The location of a single image in a sprite atlas
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SpriteAtlasImage {
/// The index of the atlas this image is in
/// This is an index in SpriteAtlas.atlas_list
pub atlas: u32,
/// x-position of this image
/// (between 0 and 1, using wgpu texture coordinates)
pub x: f32,
/// y-position of this image
/// (between 0 and 1, using wgpu texture coordinates)
pub y: f32,
/// Width of this image
/// (between 0 and 1, using wgpu texture coordinates)
pub w: f32,
/// Height of this image
/// (between 0 and 1, using wgpu texture coordinates)
pub h: f32,
}
/// A map between file paths (relative to the root asset dir)
/// and [`AtlasTexture`]s.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SpriteAtlas {
/// The images in this atlas
pub index: HashMap<PathBuf, SpriteAtlasImage>,
/// The file names of the atlas textures we've generated
pub atlas_list: Vec<String>,
}
impl SpriteAtlas {
/// Make an empty [`SpriteAtlasIndex`]
pub fn new() -> Self {
Self {
index: HashMap::new(),
atlas_list: Vec::new(),
}
}
}