comparison 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
comparison
equal deleted inserted replaced
703:81232dac8136 704:84af5bedbde4
56 56
57 /// Format of this ANM. 57 /// Format of this ANM.
58 pub format: u32, 58 pub format: u32,
59 59
60 /// File name of the main image. 60 /// File name of the main image.
61 pub first_name: String, 61 pub png_filename: String,
62 62
63 /// File name of an alpha channel image. 63 /// File name of an alpha channel image.
64 pub second_name: String, 64 pub alpha_filename: Option<String>,
65 65
66 /// A list of sprites, coordinates into the attached image. 66 /// A list of sprites, coordinates into the attached image.
67 pub sprites: Vec<Sprite>, 67 pub sprites: Vec<Sprite>,
68 68
69 /// A map of scripts. 69 /// A map of scripts.
185 let num_scripts = num_scripts as usize; 185 let num_scripts = num_scripts as usize;
186 186
187 let (i, sprite_offsets) = many_m_n(num_sprites, num_sprites, le_u32)(i)?; 187 let (i, sprite_offsets) = many_m_n(num_sprites, num_sprites, le_u32)(i)?;
188 let (_, script_offsets) = many_m_n(num_scripts, num_scripts, tuple((le_u32, le_u32)))(i)?; 188 let (_, script_offsets) = many_m_n(num_scripts, num_scripts, tuple((le_u32, le_u32)))(i)?;
189 189
190 let first_name = if first_name_offset > 0 { 190 let png_filename = if first_name_offset > 0 {
191 if input.len() < start_offset + first_name_offset as usize { 191 if input.len() < start_offset + first_name_offset as usize {
192 return Err(nom::Err::Failure((input, nom::error::ErrorKind::Eof))); 192 return Err(nom::Err::Failure((input, nom::error::ErrorKind::Eof)));
193 } 193 }
194 let i = &input[start_offset + first_name_offset as usize..]; 194 let i = &input[start_offset + first_name_offset as usize..];
195 let (_, name) = parse_name(i)?; 195 let (_, name) = parse_name(i)?;
196 name 196 name
197 } else { 197 } else {
198 String::new() 198 String::new()
199 }; 199 };
200 200
201 let second_name = if second_name_offset > 0 { 201 let alpha_filename = if second_name_offset > 0 {
202 if input.len() < start_offset + second_name_offset as usize { 202 if input.len() < start_offset + second_name_offset as usize {
203 return Err(nom::Err::Failure((input, nom::error::ErrorKind::Eof))); 203 return Err(nom::Err::Failure((input, nom::error::ErrorKind::Eof)));
204 } 204 }
205 let i = &input[start_offset + second_name_offset as usize..]; 205 let i = &input[start_offset + second_name_offset as usize..];
206 let (_, name) = parse_name(i)?; 206 let (_, name) = parse_name(i)?;
207 name 207 Some(name)
208 } else { 208 } else {
209 String::new() 209 None
210 }; 210 };
211 211
212 let mut sprites = vec![]; 212 let mut sprites = vec![];
213 let mut i; 213 let mut i;
214 for offset in sprite_offsets.into_iter().map(|x| x as usize) { 214 for offset in sprite_offsets.into_iter().map(|x| x as usize) {
270 } 270 }
271 271
272 let anm0 = Anm0 { 272 let anm0 = Anm0 {
273 size: (width, height), 273 size: (width, height),
274 format, 274 format,
275 first_name, 275 png_filename,
276 second_name, 276 alpha_filename,
277 sprites, 277 sprites,
278 scripts, 278 scripts,
279 }; 279 };
280 list.push(anm0); 280 list.push(anm0);
281 break; 281 break;