Mercurial > touhou
annotate src/th06/std.rs @ 743:0fed350d1778
examples: Remove deprecated std::mem::uninitialized().
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 07 Jan 2020 12:34:11 +0100 |
parents | 13fd434d5d1b |
children | fc937d93a57c |
rev | line source |
---|---|
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 //! STD background format support. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 use nom::{ |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 IResult, |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
5 bytes::complete::tag, |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 number::complete::{le_u8, le_u16, le_u32, le_i32, le_f32}, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 sequence::tuple, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 combinator::map, |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
9 multi::{many0, count}, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
10 error::ErrorKind, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
11 Err, |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 use encoding_rs::SHIFT_JIS; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 /// A float position in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 pub struct Position { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 /// X component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 pub x: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 /// Y component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 pub y: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 /// Z component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 pub z: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 /// A 3D box around something. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 struct Box3D { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 width: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 height: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 depth: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 /// A 2D box around something. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 pub struct Box2D { |
680
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
39 /// Width. |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
40 pub width: f32, |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
41 |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
42 /// Height. |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
43 pub height: f32, |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 /// A quad in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 pub struct Quad { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 /// The anm script to run for this quad. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 pub anm_script: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 /// The position of this quad in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 pub pos: Position, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 /// The size of this quad. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 pub size_override: Box2D, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 /// A model formed of multiple quads in space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 pub struct Model { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 /// TODO: find what that is. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 pub unknown: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 /// The bounding box around this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 pub bounding_box: [f32; 6], |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 /// The quads composing this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 pub quads: Vec<Quad>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 /// An instance of a model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 pub struct Instance { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 /// The instance identifier. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 pub id: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 /// Where to position the instance of this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 pub pos: Position, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 /// A single instruction, part of a `Script`. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 pub struct Call { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 /// Time at which this instruction will be called. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 pub time: u32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 /// The instruction to call. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 pub instr: Instruction, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 /// Parse a SHIFT_JIS byte string of length 128 into a String. |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
93 #[allow(non_snake_case)] |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 let data = i.splitn(2, |c| *c == b'\0').nth(0).unwrap(); |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
96 let (string, _encoding, _replaced) = SHIFT_JIS.decode(data); |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 Ok((&i[128..], string.into_owned())) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 /// Main struct of the STD stage format. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 pub struct Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 /// The name of the stage. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 pub name: String, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 /// A list of (name, path) of background music. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 // TODO: there are maximum four of them, and in practice never more than 2. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 pub musics: Vec<Option<(String, String)>>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 /// List of models. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 pub models: Vec<Model>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 /// List of instances. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 pub instances: Vec<Instance>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 /// List of instructions in the script. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 pub script: Vec<Call>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 impl Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 /// Parse a slice of bytes into an `Stage` struct. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 pub fn from_slice(data: &[u8]) -> IResult<&[u8], Stage> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 parse_stage(data) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 macro_rules! declare_stage_instructions { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 /// Available instructions in an `Stage`. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 #[allow(missing_docs)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 #[derive(Debug, Clone, Copy)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 pub enum Instruction { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 $name($($arg_type),*) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 ),* |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 fn parse_instruction_args(input: &[u8], opcode: u16) -> IResult<&[u8], Instruction> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 let mut i = &input[..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 let instr = match opcode { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 $opcode => { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 )* |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 Instruction::$name($($arg),*) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 )* |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 _ => unreachable!() |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 Ok((i, instr)) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 declare_stage_instructions!{ |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 0 => fn SetViewpos(x: f32, y: f32, z: f32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 1 => fn SetFog(r: u8, g: u8, b: u8, a: u8, near: f32, far: f32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 2 => fn SetViewpos2(x: f32, y: f32, z: f32), |
710
377c241be559
std_vm: Implement SetViewpos, SetViewpos2 and StartInterpolatinvViewpos2.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
680
diff
changeset
|
161 3 => fn StartInterpolatingViewpos2(frame: u32, _unused: i32, _unused: i32), |
377c241be559
std_vm: Implement SetViewpos, SetViewpos2 and StartInterpolatinvViewpos2.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
680
diff
changeset
|
162 4 => fn StartInterpolatingFog(frame: u32, _unused: i32, _unused: i32), |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 5 => fn Unknown(_unused: i32, _unused: i32, _unused: i32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
166 fn parse_quad(i: &[u8]) -> IResult<&[u8], Quad> { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
167 let (i, (unk1, size)) = tuple((le_u16, le_u16))(i)?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
168 if unk1 == 0xffff { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
169 return Err(Err::Error((i, ErrorKind::Eof))); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
170 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
171 // TODO: replace this assert with a custom error. |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
172 assert_eq!(size, 0x1c); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
173 let (i, (anm_script, _, x, y, z, width, height)) = tuple((le_u16, tag(b"\0\0"), le_f32, le_f32, le_f32, le_f32, le_f32))(i)?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
174 let quad = Quad { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
175 anm_script, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
176 pos: Position { x, y, z }, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
177 size_override: Box2D { width, height }, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
178 }; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
179 Ok((i, quad)) |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
180 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
181 |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
182 fn parse_model(i: &[u8]) -> IResult<&[u8], Model> { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
183 let (i, (_id, unknown, x, y, z, width, height, depth, quads)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32, le_f32, le_f32, le_f32, many0(parse_quad)))(i)?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
184 let bounding_box = [x, y, z, width, height, depth]; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
185 let model = Model { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
186 unknown, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
187 bounding_box, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
188 quads, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
189 }; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
190 Ok((i, model)) |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
191 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
192 |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
193 fn parse_instance(i: &[u8]) -> IResult<&[u8], Instance> { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
194 let (i, (id, unknown, x, y, z)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32))(i)?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
195 if id == 0xffff && unknown == 0xffff { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
196 return Err(Err::Error((i, ErrorKind::Eof))); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
197 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
198 // TODO: replace this assert with a custom error. |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
199 assert_eq!(unknown, 0x100); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
200 let instance = Instance { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
201 id, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
202 pos: Position { x, y, z }, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
203 }; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
204 Ok((i, instance)) |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
205 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
206 |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
207 fn parse_instruction(i: &[u8]) -> IResult<&[u8], Call> { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
208 let (i, (time, opcode, size)) = tuple((le_u32, le_u16, le_u16))(i)?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
209 if time == 0xffffffff && opcode == 0xffff && size == 0xffff { |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
210 return Err(Err::Error((i, ErrorKind::Eof))); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
211 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
212 // TODO: replace this assert with a custom error. |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
213 assert_eq!(size, 12); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
214 let (i, instr) = parse_instruction_args(i, opcode)?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
215 println!("{} {:?}", time, instr); |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
216 let call = Call { time, instr }; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
217 Ok((i, call)) |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
218 } |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
219 |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 fn parse_stage(input: &[u8]) -> IResult<&[u8], Stage> { |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
221 let i = &input[..]; |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
223 let (i, (num_models, _num_faces, object_instances_offset, script_offset, _, name, music_names, music_paths)) = tuple(( |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
224 le_u16, le_u16, le_u32, le_u32, tag(b"\0\0\0\0"), |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
225 le_String, |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
226 map(tuple((le_String, le_String, le_String, le_String)), |(a, b, c, d)| [a, b, c, d]), |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
227 map(tuple((le_String, le_String, le_String, le_String)), |(a, b, c, d)| [a, b, c, d]) |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
228 ))(i)?; |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 let musics = music_names.iter().zip(&music_paths).map(|(name, path)| if name == " " { None } else { Some((name.clone(), path.clone())) }).collect(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
231 let (_, offsets) = count(le_u32, num_models as usize)(i)?; |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 let mut models = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 for offset in offsets { |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
235 let (_, model) = parse_model(&input[offset as usize..])?; |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 models.push(model); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 |
712
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
239 let (_, instances) = many0(parse_instance)(&input[object_instances_offset as usize..])?; |
13fd434d5d1b
std: Split parser to simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
710
diff
changeset
|
240 let (_, script) = many0(parse_instruction)(&input[script_offset as usize..])?; |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 let stage = Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 name, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 musics, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 models, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 instances, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 script, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 Ok((b"", stage)) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
250 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 #[cfg(test)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 mod tests { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 use super::*; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 use std::io::{self, Read}; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 use std::fs::File; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 #[test] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 fn std() { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 let file = File::open("EoSD/ST/stage1.std").unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 let mut file = io::BufReader::new(file); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 let mut buf = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
263 file.read_to_end(&mut buf).unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
264 let (_, stage) = Stage::from_slice(&buf).unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
265 assert_eq!(stage.name, "夢幻夜行絵巻 ~ Mystic Flier"); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
266 assert_eq!(stage.musics.len(), 4); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 assert_eq!(stage.models.len(), 13); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
268 assert_eq!(stage.instances.len(), 90); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 assert_eq!(stage.script.len(), 21); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 } |