Packer tweaks for new sprite definitions

master
Mark 2024-01-20 09:39:27 -08:00
parent ade2a89a51
commit 70c9ec3b92
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 25 additions and 12 deletions

View File

@ -205,16 +205,19 @@ impl AtlasSet {
) )
})?; })?;
self.index.index.insert( self.index
p.to_path_buf(), .path_map
SpriteAtlasImage { .insert(p.to_path_buf(), self.index.index.len() as u32);
atlas: atlas_idx as u32,
x: (x + self.image_margin) as f32 / self.texture_width as f32, self.index.index.push(SpriteAtlasImage {
y: (y + self.image_margin) as f32 / self.texture_height as f32, true_size: image_dim,
w: image_dim.0 as f32 / self.texture_width as f32, idx: self.index.index.len() as u32,
h: image_dim.1 as f32 / self.texture_height as f32, atlas: atlas_idx as u32,
}, x: (x + self.image_margin) as f32 / self.texture_width as f32,
); y: (y + self.image_margin) as f32 / self.texture_height as f32,
w: image_dim.0 as f32 / self.texture_width as f32,
h: image_dim.1 as f32 / self.texture_height as f32,
});
return Ok(atlas_idx); return Ok(atlas_idx);
} }

View File

@ -13,6 +13,12 @@ pub struct SpriteAtlasImage {
/// This is an index in SpriteAtlas.atlas_list /// This is an index in SpriteAtlas.atlas_list
pub atlas: u32, 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 /// x-position of this image
/// (between 0 and 1, using wgpu texture coordinates) /// (between 0 and 1, using wgpu texture coordinates)
pub x: f32, pub x: f32,
@ -35,7 +41,10 @@ pub struct SpriteAtlasImage {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SpriteAtlas { pub struct SpriteAtlas {
/// The images in this atlas /// The images in this atlas
pub index: HashMap<PathBuf, SpriteAtlasImage>, 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 /// The file names of the atlas textures we've generated
pub atlas_list: Vec<String>, pub atlas_list: Vec<String>,
@ -45,7 +54,8 @@ impl SpriteAtlas {
/// Make an empty [`SpriteAtlasIndex`] /// Make an empty [`SpriteAtlasIndex`]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
index: HashMap::new(), path_map: HashMap::new(),
index: Vec::new(),
atlas_list: Vec::new(), atlas_list: Vec::new(),
} }
} }