From 8ae402d037cd72400cd0c7485d4a2ceaf6adfb02 Mon Sep 17 00:00:00 2001 From: ashley Date: Thu, 28 Sep 2023 20:31:38 -0400 Subject: [PATCH] Export palette with sprite --- src/reskit/level/converter.rs | 6 +++++- src/reskit/level/system.rs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/reskit/level/converter.rs b/src/reskit/level/converter.rs index 3e481c9..754999f 100644 --- a/src/reskit/level/converter.rs +++ b/src/reskit/level/converter.rs @@ -24,6 +24,7 @@ pub struct SpriteMetadata { pub id: String, pub width: u8, pub height: u8, + pub palette: u16, pub anim_interval: Option } @@ -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 }, diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index 09b258d..ef994a4 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -290,6 +290,8 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap ) 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;