diff src/th06/anm0.rs @ 704:84af5bedbde4

anmrenderer: also load the alpha PNG.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 23 Aug 2019 19:09:37 +0200
parents 718348c7608e
children 258f4aebf3fc
line wrap: on
line diff
--- a/src/th06/anm0.rs
+++ b/src/th06/anm0.rs
@@ -58,10 +58,10 @@ pub struct Anm0 {
     pub format: u32,
 
     /// File name of the main image.
-    pub first_name: String,
+    pub png_filename: String,
 
     /// File name of an alpha channel image.
-    pub second_name: String,
+    pub alpha_filename: Option<String>,
 
     /// A list of sprites, coordinates into the attached image.
     pub sprites: Vec<Sprite>,
@@ -187,7 +187,7 @@ fn parse_anm0(input: &[u8]) -> IResult<&
         let (i, sprite_offsets) = many_m_n(num_sprites, num_sprites, le_u32)(i)?;
         let (_, script_offsets) = many_m_n(num_scripts, num_scripts, tuple((le_u32, le_u32)))(i)?;
 
-        let first_name = if first_name_offset > 0 {
+        let png_filename = if first_name_offset > 0 {
             if input.len() < start_offset + first_name_offset as usize {
                 return Err(nom::Err::Failure((input, nom::error::ErrorKind::Eof)));
             }
@@ -198,15 +198,15 @@ fn parse_anm0(input: &[u8]) -> IResult<&
             String::new()
         };
 
-        let second_name = if second_name_offset > 0 {
+        let alpha_filename = if second_name_offset > 0 {
             if input.len() < start_offset + second_name_offset as usize {
                 return Err(nom::Err::Failure((input, nom::error::ErrorKind::Eof)));
             }
             let i = &input[start_offset + second_name_offset as usize..];
             let (_, name) = parse_name(i)?;
-            name
+            Some(name)
         } else {
-            String::new()
+            None
         };
 
         let mut sprites = vec![];
@@ -272,8 +272,8 @@ fn parse_anm0(input: &[u8]) -> IResult<&
         let anm0 = Anm0 {
             size: (width, height),
             format,
-            first_name,
-            second_name,
+            png_filename,
+            alpha_filename,
             sprites,
             scripts,
         };