From a61b799c72b3bf26f3376cbc8b9a03c080314ec5 Mon Sep 17 00:00:00 2001 From: ashley Date: Fri, 29 Sep 2023 16:48:47 -0400 Subject: [PATCH] Fix off-by-one error as a blank tile is pushed before all the others --- src/reskit/level/system.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index 14bdd79..cbf25be 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -264,7 +264,7 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap ) let mut result: Vec = Vec::new(); let tiles_before = { - let mut total_tiles = 0; + let mut total_tiles = 1; for tileset in &tilemap.tileset { // do not include the sprite metadata @@ -285,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 + 1; + let tile_index_location = tiles_before + tiles_after; result.extend( ( tile_index_location as u16 ).to_be_bytes() ); tiles_after += ( sprite_metadata.width * sprite_metadata.height ) as u32; @@ -319,7 +319,7 @@ pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) - let level_label = symbol_to_pascal( level_name ); let ( width, height ) = ( tilemap.width, tilemap.height ); let num_tiles = { - let mut total_tiles = 0; + let mut total_tiles = 1; for tileset in &tilemap.tileset { total_tiles += ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 ); // --system md