From f3170b6b4bcc552342db722ff1fa92aa8b9fe3ab Mon Sep 17 00:00:00 2001 From: ashley Date: Fri, 29 Sep 2023 13:15:22 -0400 Subject: [PATCH] Fix how sprite indices are counted --- src/reskit/level/system.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index ef994a4..14bdd79 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -1,7 +1,7 @@ -use std::{error::Error, convert::TryInto, cmp::max, num::ParseIntError, collections::HashMap}; +use std::{error::Error, convert::TryInto, collections::HashMap}; use image::GenericImageView; -use crate::reskit::{tileset::image_to_tiles, utility::{symbol_to_pascal, print_info}, cli::settings::TileOrder}; -use super::{converter::{TiledTilemap, Layer, SystemPlane, TiledTileset}, ecs::Component}; +use crate::reskit::{tileset::image_to_tiles, utility::symbol_to_pascal, cli::settings::TileOrder}; +use super::converter::{TiledTilemap, Layer, SystemPlane, TiledTileset}; /** * Output the .bin and .pal file (using `tileset` tool to build it) containing each of the tiles @@ -267,7 +267,10 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap ) let mut total_tiles = 0; for tileset in &tilemap.tileset { - total_tiles += ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 ); + // do not include the sprite metadata + if tileset.sprite_metadata.is_none() { + total_tiles += ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 ); + } } total_tiles @@ -282,7 +285,7 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap ) let sprite_id = sprite_ids.get( &sprite_metadata.id ).ok_or( format!( "invalid file: undefined sprite id \"{}\"", sprite_metadata.id ) )?; result.extend( sprite_id.to_be_bytes() ); - let tile_index_location = tiles_before + tiles_after; + let tile_index_location = tiles_before + tiles_after + 1; result.extend( ( tile_index_location as u16 ).to_be_bytes() ); tiles_after += ( sprite_metadata.width * sprite_metadata.height ) as u32;