Export palette with sprite

stinkhead7ds
Ashley N. 2023-09-28 20:31:38 -04:00
parent 27a6e09560
commit 8ae402d037
2 changed files with 7 additions and 1 deletions

View File

@ -24,6 +24,7 @@ pub struct SpriteMetadata {
pub id: String,
pub width: u8,
pub height: u8,
pub palette: u16,
pub anim_interval: Option<u16>
}
@ -165,14 +166,17 @@ fn get_tiles( tileset: Node, first_gid: usize, working_directory: &str ) -> Resu
let reskit_sprite_height = properties.descendants().find( | node | node.attribute( "name" ) == Some( "reskit-sprite-height" ) ).ok_or( "invalid file: for reskit-tile-order \"sprite\", reskit-sprite-height and reskit-sprite-width must be defined." )?;
let reskit_sprite_width = properties.descendants().find( | node | node.attribute( "name" ) == Some( "reskit-sprite-width" ) ).ok_or( "invalid file: for reskit-tile-order \"sprite\", reskit-sprite-height and reskit-sprite-width must be defined." )?;
let reskit_sprite_id = properties.descendants().find( | node | node.attribute( "name" ) == Some( "reskit-sprite-id" ) ).ok_or( "invalid file: for reskit-tile-order \"sprite\", reskit-sprite-id must be defined." )?;
let reskit_palette = properties.descendants().find( | node | node.attribute( "name" ) == Some( "reskit-palette" ) ).ok_or( "invalid file: for reskit-tile-order \"sprite\", reskit-palette must be defined." )?;
let reskit_anim_interval = properties.descendants().find( | node | node.attribute( "name" ) == Some( "reskit-anim-interval" ) );
let reskit_sprite_height = reskit_sprite_height.attribute( "value" ).ok_or( "invalid file: no reskit-sprite-height value" )?;
let reskit_sprite_width = reskit_sprite_width.attribute( "value" ).ok_or( "invalid file: no reskit-sprite-width value" )?;
let reskit_palette = reskit_palette.attribute( "value" ).ok_or( "invalid file: no reskit-palette value" )?;
let id: String = reskit_sprite_id.attribute( "value" ).ok_or( "invalid file: no reskit-sprite-id value" )?.to_owned();
let width: u8 = reskit_sprite_width.parse()?;
let height: u8 = reskit_sprite_height.parse()?;
let palette: u16 = reskit_palette.parse()?;
let anim_interval = if let Some( property ) = reskit_anim_interval {
let value = property.attribute( "value" ).ok_or( "invalid file: no reskit-anim-interval value" )?;
@ -181,7 +185,7 @@ fn get_tiles( tileset: Node, first_gid: usize, working_directory: &str ) -> Resu
None
};
sprite_metadata = Some( SpriteMetadata { id, width, height, anim_interval } );
sprite_metadata = Some( SpriteMetadata { id, width, height, palette, anim_interval } );
TileOrder::Sprite
},

View File

@ -290,6 +290,8 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap<String, u16> )
result.push( sprite_metadata.height );
result.extend( sprite_metadata.palette.to_be_bytes() );
// One animation per .tsx file
// Animations run like a filmstrip across, never down
let tiles_across = sprite.image.width() / 8;