2024-01-03 19:48:46 -08:00
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
|
|
|
//! This crate creates texture atlases from an asset tree.
|
|
|
|
|
2024-01-04 17:15:32 -08:00
|
|
|
use std::{collections::HashMap, path::PathBuf};
|
2024-01-03 19:48:46 -08:00
|
|
|
|
|
|
|
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
|
2024-01-04 22:17:34 -08:00
|
|
|
/// This is an index in SpriteAtlas.atlas_list
|
|
|
|
pub atlas: u32,
|
2024-01-03 19:48:46 -08:00
|
|
|
|
|
|
|
/// 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)]
|
2024-01-04 17:15:32 -08:00
|
|
|
pub struct SpriteAtlas {
|
|
|
|
/// The images in this atlas
|
|
|
|
pub index: HashMap<PathBuf, SpriteAtlasImage>,
|
2024-01-04 22:17:34 -08:00
|
|
|
|
|
|
|
/// The file names of the atlas textures we've generated
|
|
|
|
pub atlas_list: Vec<String>,
|
2024-01-03 19:48:46 -08:00
|
|
|
}
|
|
|
|
|
2024-01-04 17:15:32 -08:00
|
|
|
impl SpriteAtlas {
|
2024-01-03 19:48:46 -08:00
|
|
|
/// Make an empty [`SpriteAtlasIndex`]
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
index: HashMap::new(),
|
2024-01-04 22:17:34 -08:00
|
|
|
atlas_list: Vec::new(),
|
2024-01-03 19:48:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|