Fix how sprite indices are counted
parent
90cee2d998
commit
f3170b6b4b
|
@ -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<String, u16> )
|
|||
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<String, u16> )
|
|||
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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue