annotate src/th06/anm0.rs @ 639:a8e0219162b6

Implement AnmRunner.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 04 Jul 2019 15:21:46 +0200
parents a806f28e94fc
children 01849ffd0180
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 //! ANM0 animation format support.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 use nom::{
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 IResult,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 bytes::complete::{tag, take_while_m_n},
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
6 number::complete::{le_u8, le_u16, le_u32, le_i32, le_f32},
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 use std::collections::HashMap;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 /// Coordinates of a sprite into the image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 pub struct Sprite {
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
13 /// Index inside the anm0.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
14 pub index: u32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
15
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
16 /// X coordinate in the sprite sheet.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
17 pub x: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
18
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
19 /// Y coordinate in the sprite sheet.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
20 pub y: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
21
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
22 /// Width of the sprite.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
23 pub width: f32,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
24
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
25 /// Height of the sprite.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
26 pub height: f32,
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 /// A single instruction, part of a `Script`.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 #[derive(Debug, Clone)]
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
31 pub struct Call {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
32 /// Time at which this instruction will be called.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
33 pub time: u16,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
34
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
35 /// The instruction to call.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
36 pub instr: Instruction,
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 /// Script driving an animation.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 pub struct Script {
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
42 /// List of instructions in this script.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
43 pub instructions: Vec<Call>,
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
44
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
45 /// List of interrupts in this script.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
46 pub interrupts: HashMap<i32, u8>
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 /// Main struct of the ANM0 animation format.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 pub struct Anm0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 /// Resolution of the image used by this ANM.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 pub size: (u32, u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 /// Format of this ANM.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 pub format: u32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 /// File name of the main image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 pub first_name: String,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 /// File name of an alpha channel image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 pub second_name: String,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 /// A list of sprites, coordinates into the attached image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 pub sprites: Vec<Sprite>,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 /// A map of scripts.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 pub scripts: HashMap<u8, Script>,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 impl Anm0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 /// Parse a slice of bytes into an `Anm0` struct.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 pub fn from_slice(data: &[u8]) -> Result<Anm0, ()> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 // XXX: report the exact nom error instead!
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 let (_, anm0) = parse_anm0(data).or_else(|_| Err(()))?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 assert_eq!(anm0.len(), 1);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 Ok(anm0[0].clone())
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 fn parse_name(i: &[u8], is_present: bool) -> IResult<&[u8], String> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 if !is_present {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 return Ok((i, String::new()));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 let (_, slice) = take_while_m_n(0, 32, |c| c != 0)(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 // XXX: no unwrap!
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 let string = String::from_utf8(slice.to_vec()).unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 Ok((i, string))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 fn parse_sprite(i: &[u8]) -> IResult<&[u8], Sprite> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 let (i, index) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 let (i, x) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 let (i, y) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 let (i, width) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 let (i, height) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 Ok((i, Sprite {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 index,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 x,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 y,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 width,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 height,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 }))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
106 macro_rules! declare_anm_instructions {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
107 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
108 /// Available instructions in an `Anm0`.
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
109 #[allow(missing_docs)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
110 #[derive(Debug, Clone, Copy)]
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
111 pub enum Instruction {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
112 $(
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
113 $name($($arg_type),*)
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
114 ),*
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
115 }
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
117 fn parse_instruction_args(input: &[u8], opcode: u8) -> IResult<&[u8], Instruction> {
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 let mut i = &input[..];
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
119 let instr = match opcode {
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 $(
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 $opcode => {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 $(
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
123 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?;
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 )*
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
126 Instruction::$name($($arg),*)
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 )*
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 _ => unreachable!()
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
130 };
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
131 Ok((i, instr))
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 declare_anm_instructions!{
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
137 0 => fn Delete(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
138 1 => fn LoadSprite(sprite_number: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
139 2 => fn SetScale(sx: f32, sy: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
140 3 => fn SetAlpha(alpha: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
141 4 => fn SetColor(red: u8, green: u8, blue: u8/*, XXX: x8*/),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
142 5 => fn Jump(instruction: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
143 7 => fn ToggleMirrored(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
144 9 => fn SetRotations3d(x: f32, y: f32, z: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
145 10 => fn SetRotationsSpeed3d(x: f32, y: f32, z: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
146 11 => fn SetScaleSpeed(sx: f32, sy: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
147 12 => fn Fade(alpha: u32, duration: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
148 13 => fn SetBlendmodeAdd(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
149 14 => fn SetBlendmodeAlphablend(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
150 15 => fn KeepStill(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
151 16 => fn LoadRandomSprite(min_index: u32, amplitude: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
152 17 => fn Move(x: f32, y: f32, z: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
153 18 => fn MoveToLinear(x: f32, y: f32, z: f32, duration: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
154 19 => fn MoveToDecel(x: f32, y: f32, z: f32, duration: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
155 20 => fn MoveToAccel(x: f32, y: f32, z: f32, duration: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
156 21 => fn Wait(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
157 22 => fn InterruptLabel(label: i32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
158 23 => fn SetCornerRelativePlacement(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
159 24 => fn WaitEx(),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
160 25 => fn SetAllowOffset(allow: u32), // TODO: better name
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
161 26 => fn SetAutomaticOrientation(automatic: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
162 27 => fn ShiftTextureX(dx: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
163 28 => fn ShiftTextureY(dy: f32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
164 29 => fn SetVisible(visible: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
165 30 => fn ScaleIn(sx: f32, sy: f32, duration: u32),
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
166 31 => fn Todo(todo: u32),
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 fn parse_anm0(input: &[u8]) -> IResult<&[u8], Vec<Anm0>> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 let mut list = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 let start_offset = 0;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 loop {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 let i = &input[start_offset..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 let (i, num_sprites) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 let (i, num_scripts) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 let (i, _) = tag(b"\0\0\0\0")(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 let (i, width) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 let (i, height) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 let (i, format) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 let (i, _unknown1) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 let (i, first_name_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 let (i, _unused) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 let (i, second_name_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 let (i, version) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 let (i, _unknown2) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 let (i, _texture_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 let (i, has_data) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 let (i, _next_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 let (mut i, unknown3) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 assert_eq!(version, 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 assert_eq!(unknown3, 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 assert_eq!(has_data, 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 let mut sprite_offsets = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 for _ in 0..num_sprites {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 let (i2, offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 sprite_offsets.push(offset as usize);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 let mut script_offsets = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 for _ in 0..num_scripts {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 let (i2, index) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 let (i2, offset) = le_u32(i2)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 script_offsets.push((index as u8, offset as usize));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 let i = &input[start_offset + first_name_offset as usize..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 let (_, first_name) = parse_name(i, first_name_offset > 0)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 let i = &input[start_offset + second_name_offset as usize..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 let (_, second_name) = parse_name(i, second_name_offset > 0)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 let mut sprites = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 let mut i;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 for offset in sprite_offsets {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 i = &input[start_offset + offset..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220 let (_, sprite) = parse_sprite(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 sprites.push(sprite);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 let mut scripts = HashMap::new();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 for (index, offset) in script_offsets {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 i = &input[start_offset + offset..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 let mut instruction_offsets = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 let mut instructions = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230 loop {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 let tell = input.len() - i.len();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232 instruction_offsets.push(tell - (start_offset + offset));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 let (i2, time) = le_u16(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 let (i2, opcode) = le_u8(i2)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 // TODO: maybe check against the size of parsed data?
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 let (i2, _size) = le_u8(i2)?;
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
237 let (i2, instr) = parse_instruction_args(i2, opcode)?;
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
238 instructions.push(Call { time, instr });
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 if opcode == 0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 break;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 let mut interrupts = HashMap::new();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 let mut j = 0;
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
246 for Call { time: _, instr } in &mut instructions {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
247 match instr {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
248 Instruction::Jump(ref mut offset) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
249 let result = instruction_offsets.binary_search(&(*offset as usize));
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
250 match result {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
251 Ok(ptr) => *offset = ptr as u32,
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 // TODO: make that a recoverable error instead.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 Err(ptr) => panic!("Instruction offset not found for pointer: {}", ptr),
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
254 }
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 }
639
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
256 Instruction::InterruptLabel(interrupt) => {
a8e0219162b6 Implement AnmRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 638
diff changeset
257 interrupts.insert(*interrupt, j + 1);
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 _ => ()
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 j += 1;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 scripts.insert(index, Script {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 instructions,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 interrupts,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 });
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 assert!(has_data == 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 let anm0 = Anm0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272 size: (width, height),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 format,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 first_name,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 second_name,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 sprites,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 scripts,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 list.push(anm0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 break;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
282 Ok((b"", list))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 #[cfg(test)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286 mod tests {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 use super::*;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288 use std::io::{self, Read};
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289 use std::fs::File;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
290
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291 #[test]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 fn anm0() {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293 let file = File::open("/home/linkmauve/games/pc/東方/TH06 ~ The Embodiment of Scarlet Devil/CM/player01.anm").unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294 let mut file = io::BufReader::new(file);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295 let mut buf = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 file.read_to_end(&mut buf).unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
297 let anm0 = Anm0::from_slice(&buf).unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
298 assert_eq!(anm0.size, (256, 256));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
299 assert_eq!(anm0.format, 5);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
300 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
301 }