Fix off-by-one error as a blank tile is pushed before all the others

stinkhead7ds
Ashley N. 2023-09-29 16:48:47 -04:00
parent f3170b6b4b
commit a61b799c72
1 changed files with 3 additions and 3 deletions

View File

@ -264,7 +264,7 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap<String, u16> )
let mut result: Vec<u8> = Vec::new(); let mut result: Vec<u8> = Vec::new();
let tiles_before = { let tiles_before = {
let mut total_tiles = 0; let mut total_tiles = 1;
for tileset in &tilemap.tileset { for tileset in &tilemap.tileset {
// do not include the sprite metadata // do not include the sprite metadata
@ -285,7 +285,7 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap<String, u16> )
let sprite_id = sprite_ids.get( &sprite_metadata.id ).ok_or( format!( "invalid file: undefined sprite id \"{}\"", sprite_metadata.id ) )?; 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() ); 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() ); result.extend( ( tile_index_location as u16 ).to_be_bytes() );
tiles_after += ( sprite_metadata.width * sprite_metadata.height ) as u32; 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 level_label = symbol_to_pascal( level_name );
let ( width, height ) = ( tilemap.width, tilemap.height ); let ( width, height ) = ( tilemap.width, tilemap.height );
let num_tiles = { let num_tiles = {
let mut total_tiles = 0; let mut total_tiles = 1;
for tileset in &tilemap.tileset { for tileset in &tilemap.tileset {
total_tiles += ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 ); // --system md total_tiles += ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 ); // --system md