comparison src/th06/anm0.rs @ 701:b6c351ca0a35

anm0: return the nom IResult and the list of Anm0s.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 23 Aug 2019 15:34:03 +0200
parents 3ff1af76e413
children 718348c7608e
comparison
equal deleted inserted replaced
700:ccb739c5b66c 701:b6c351ca0a35
68 pub scripts: HashMap<u8, Script>, 68 pub scripts: HashMap<u8, Script>,
69 } 69 }
70 70
71 impl Anm0 { 71 impl Anm0 {
72 /// Parse a slice of bytes into an `Anm0` struct. 72 /// Parse a slice of bytes into an `Anm0` struct.
73 pub fn from_slice(data: &[u8]) -> Result<Anm0, ()> { 73 pub fn from_slice(data: &[u8]) -> IResult<&[u8], Vec<Anm0>> {
74 // XXX: report the exact nom error instead! 74 parse_anm0(data)
75 let (_, anm0) = parse_anm0(data).or_else(|_| Err(()))?;
76 assert_eq!(anm0.len(), 1);
77 Ok(anm0[0].clone())
78 } 75 }
79 76
80 /// TODO 77 /// TODO
81 pub fn inv_size(&self) -> (f32, f32) { 78 pub fn inv_size(&self) -> (f32, f32) {
82 let (x, y) = self.size; 79 let (x, y) = self.size;
316 fn anm0() { 313 fn anm0() {
317 let file = File::open("EoSD/CM/player01.anm").unwrap(); 314 let file = File::open("EoSD/CM/player01.anm").unwrap();
318 let mut file = io::BufReader::new(file); 315 let mut file = io::BufReader::new(file);
319 let mut buf = vec![]; 316 let mut buf = vec![];
320 file.read_to_end(&mut buf).unwrap(); 317 file.read_to_end(&mut buf).unwrap();
321 let anm0 = Anm0::from_slice(&buf).unwrap(); 318 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
319 assert_eq!(anms.len(), 1);
320 let anm0 = anms.pop().unwrap();
322 assert_eq!(anm0.size, (256, 256)); 321 assert_eq!(anm0.size, (256, 256));
323 assert_eq!(anm0.format, 5); 322 assert_eq!(anm0.format, 5);
324 } 323 }
325 } 324 }