diff --git a/src/parse.rs b/src/parse.rs index 54d0b93..176a068 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -115,7 +115,7 @@ impl ParseInfo { })?; layer.user_data = Some(user_data); } - UserDataContext::OldPalette => { + UserDataContext::Palette => { self.sprite_user_data = Some(user_data); } UserDataContext::TagIndex(tag_index) => { @@ -299,6 +299,10 @@ fn parse_frame( parse_info.color_profile = Some(profile); } ChunkType::Palette => { + // If the next chunk is user data, it is the sprite user data. + // See 3. at https://github.com/aseprite/aseprite/blob/v1.3.8/docs/ase-file-specs.md#user-data-chunk-0x2020 + parse_info.user_data_context = Some(UserDataContext::Palette); + let palette = palette::parse_chunk(&data)?; parse_info.palette = Some(Arc::new(palette)); } @@ -335,7 +339,7 @@ fn parse_frame( ChunkType::OldPalette04 => { // An old palette chunk precedes the sprite UserData chunk. // Update the chunk context to reflect the OldPalette chunk. - parse_info.user_data_context = Some(UserDataContext::OldPalette); + parse_info.user_data_context = Some(UserDataContext::Palette); if parse_info.palette.is_none() { let palette = palette::parse_old_chunk_04(&data)?; @@ -345,7 +349,7 @@ fn parse_frame( ChunkType::OldPalette11 => { // An old palette chunk precedes the sprite UserData chunk. // Update the chunk context to reflect the OldPalette chunk. - parse_info.user_data_context = Some(UserDataContext::OldPalette); + parse_info.user_data_context = Some(UserDataContext::Palette); if parse_info.palette.is_none() { let palette = palette::parse_old_chunk_11(&data)?; @@ -369,7 +373,7 @@ fn parse_frame( enum UserDataContext { CelId(CelId), LayerIndex(u32), - OldPalette, + Palette, TagIndex(u16), SliceIndex(u32), } @@ -428,6 +432,7 @@ impl Chunk { let chunk_size = reader.dword()?; let chunk_type_code = reader.word()?; let chunk_type = parse_chunk_type(chunk_type_code)?; + // println!("Chunk type: {:?}", chunk_type); check_chunk_bytes(chunk_size, *bytes_available)?; diff --git a/src/tests.rs b/src/tests.rs index 48c4032..274a149 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -624,3 +624,17 @@ fn gen_random_pixels() { img.save(&Path::new("tests/data/random-256x256.png")).unwrap(); } // */ + + + +#[test] +fn sprite_user_data_after_old_palette04() { + let ase = load_test_file("sprite_user_data_after_old_palette04"); + assert_eq!(ase.sprite_user_data().unwrap().text.clone().unwrap(), "my custom sprite user data"); +} + +#[test] +fn sprite_user_data_after_palette() { + let ase = load_test_file("sprite_user_data_after_palette"); + assert_eq!(ase.sprite_user_data().unwrap().text.clone().unwrap(), "my custom sprite user data"); +} diff --git a/tests/data/sprite_user_data_after_old_palette04.aseprite b/tests/data/sprite_user_data_after_old_palette04.aseprite new file mode 100644 index 0000000..69ec122 Binary files /dev/null and b/tests/data/sprite_user_data_after_old_palette04.aseprite differ diff --git a/tests/data/sprite_user_data_after_palette.aseprite b/tests/data/sprite_user_data_after_palette.aseprite new file mode 100644 index 0000000..a55c342 Binary files /dev/null and b/tests/data/sprite_user_data_after_palette.aseprite differ