63 lines
1.5 KiB
Rust
63 lines
1.5 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,
|
|
|
|
/// A globally unique, consecutively numbered index for this sprite
|
|
pub idx: u32,
|
|
|
|
/// The size of this image, in pixels
|
|
pub true_size: (u32, 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: Vec<SpriteAtlasImage>,
|
|
|
|
/// Map paths to image indices
|
|
pub path_map: HashMap<PathBuf, u32>,
|
|
|
|
/// 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 {
|
|
path_map: HashMap::new(),
|
|
index: Vec::new(),
|
|
atlas_list: Vec::new(),
|
|
}
|
|
}
|
|
}
|