WIP - New metatile converter
parent
6fe634c864
commit
15143e08cb
|
@ -143,7 +143,7 @@ pub fn get_metatile_maps( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Er
|
|||
subdefinitions.extend( metatile.width.to_be_bytes() );
|
||||
subdefinitions.extend( metatile.height.to_be_bytes() );
|
||||
|
||||
let ( tilemap_index, palettes ) = metatile_tilemap_index( &metatile.source, &tilemap.tileset )?;
|
||||
let ( tilemap_index, palettes ) = get_tilemap_prefix_palette( &metatile.source, &tilemap.tileset )?;
|
||||
for tile in &metatile.tiles {
|
||||
let palette = {
|
||||
if *tile == 0 {
|
||||
|
@ -235,7 +235,7 @@ pub fn get_metatile_maps( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Er
|
|||
Ok( result )
|
||||
}
|
||||
|
||||
fn metatile_tilemap_index( target_source: &str, tilesets: &Vec<TiledTileset> ) -> Result<(usize, Vec<Option<u8>>), Box<dyn Error>> {
|
||||
fn get_tilemap_prefix_palette( target_source: &str, tilesets: &Vec<TiledTileset> ) -> Result<(usize, Vec<Option<u8>>), Box<dyn Error>> {
|
||||
// Everything starts at 1 for the blank buffer tile
|
||||
let mut index: usize = 1;
|
||||
|
||||
|
@ -325,23 +325,12 @@ pub fn get_objs( tilemap: &TiledTilemap, symbol_ids: &HashMap<String, u16> ) ->
|
|||
pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap<String, u16> ) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
let mut result: Vec<u8> = Vec::new();
|
||||
|
||||
let tiles_before = {
|
||||
let mut total_tiles = 1;
|
||||
|
||||
for tileset in &tilemap.tileset {
|
||||
// do not include the sprite metadata
|
||||
if tileset.sprite_metadata.is_none() {
|
||||
total_tiles += ( tileset.image.width() / 8 ) * ( tileset.image.height() / 8 );
|
||||
}
|
||||
}
|
||||
|
||||
total_tiles
|
||||
};
|
||||
let mut tiles_after: u32 = 0;
|
||||
|
||||
let sprites: Vec<&TiledTileset> = tilemap.tileset.iter().filter( | tileset | matches!( tileset.tile_order, TileOrder::Sprite ) ).collect();
|
||||
result.extend( ( sprites.len() as u16 ).to_be_bytes() );
|
||||
for sprite in sprites {
|
||||
// Just find the prefix of this source (add up all the number of tiles before it)
|
||||
let ( index, _ ) = get_tilemap_prefix_palette( &sprite.source, &tilemap.tileset )?;
|
||||
|
||||
let sprite_metadata = sprite.sprite_metadata.as_ref().ok_or( "internal error: tile order is sprite but no sprite data" )?;
|
||||
|
||||
let sprite_id = sprite_ids.get( &sprite_metadata.id ).ok_or( format!( "invalid file: undefined sprite id \"{}\"", sprite_metadata.id ) )?;
|
||||
|
@ -350,9 +339,7 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap<String, u16> )
|
|||
let tiles_across = sprite.image.width() / 8;
|
||||
let frames: u16 = ( tiles_across / ( sprite_metadata.width as u32 ) ) as u16;
|
||||
|
||||
let tile_index_location = tiles_before + tiles_after;
|
||||
result.extend( ( tile_index_location as u16 ).to_be_bytes() );
|
||||
tiles_after += ( ( sprite_metadata.width as u16 * sprite_metadata.height as u16 ) * frames ) as u32;
|
||||
result.extend( ( index as u16 ).to_be_bytes() );
|
||||
|
||||
result.push( sprite_metadata.width );
|
||||
|
||||
|
|
Loading…
Reference in New Issue