Mercurial > touhou
annotate src/th06/std.rs @ 705:ed65f9412bc0
anmrenderer: split common loading functions in another module.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 23 Aug 2019 19:29:00 +0200 |
parents | ef2dbd676a91 |
children | 377c241be559 |
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, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 bytes::complete::{tag, take_while_m_n}, |
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, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 use encoding_rs::SHIFT_JIS; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 use std::collections::HashMap; |
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 /// 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
|
14 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 pub struct Position { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 /// X component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 pub x: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 /// Y component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 pub y: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 /// Z component. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 pub z: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 /// A 3D box around something. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 struct Box3D { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 width: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 height: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 depth: f32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 /// A 2D box around something. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 pub struct Box2D { |
680
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
37 /// Width. |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
38 pub width: f32, |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
39 |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
40 /// Height. |
ef2dbd676a91
Add missing quad size override to stdrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
679
diff
changeset
|
41 pub height: f32, |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 /// A quad in the 3D space. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 pub struct Quad { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 /// 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
|
48 pub anm_script: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 /// 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
|
51 pub pos: Position, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 /// The size of this quad. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 pub size_override: Box2D, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 /// 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
|
58 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 pub struct Model { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 /// TODO: find what that is. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 pub unknown: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 /// The bounding box around this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 pub bounding_box: [f32; 6], |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 /// The quads composing this model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 pub quads: Vec<Quad>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 /// An instance of a model. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 pub struct Instance { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 /// The instance identifier. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 pub id: u16, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 /// 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
|
77 pub pos: Position, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 /// 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
|
81 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 pub struct Call { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 /// 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
|
84 pub time: u32, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 /// The instruction to call. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 pub instr: Instruction, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 /// Parse a SHIFT_JIS byte string of length 128 into a String. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 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
|
92 let data = i.splitn(2, |c| *c == b'\0').nth(0).unwrap(); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 let (string, encoding, replaced) = SHIFT_JIS.decode(data); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 Ok((&i[128..], string.into_owned())) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 /// 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
|
98 #[derive(Debug, Clone)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 pub struct Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 /// The name of the stage. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 pub name: String, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 /// 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
|
104 // 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
|
105 pub musics: Vec<Option<(String, String)>>, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 /// List of models. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 pub models: Vec<Model>, |
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 instances. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 pub instances: Vec<Instance>, |
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 instructions in the script. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 pub script: Vec<Call>, |
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 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 impl Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 /// 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
|
119 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
|
120 parse_stage(data) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 macro_rules! declare_stage_instructions { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 ($($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
|
126 /// Available instructions in an `Stage`. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 #[allow(missing_docs)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 #[derive(Debug, Clone, Copy)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 pub enum Instruction { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 $name($($arg_type),*) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 ),* |
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 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 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
|
136 let mut i = &input[..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 let instr = match opcode { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 $opcode => { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 $( |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 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
|
142 i = i2; |
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 Instruction::$name($($arg),*) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 } |
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 _ => unreachable!() |
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 Ok((i, instr)) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 } |
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 } |
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 declare_stage_instructions!{ |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 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
|
156 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
|
157 2 => fn SetViewpos2(x: f32, y: f32, z: f32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 3 => fn StartInterpolatingViewpos2(frame: i32, _unused: i32, _unused: i32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 4 => fn StartInterpolatingFog(frame: i32, _unused: i32, _unused: i32), |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 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
|
161 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 fn parse_stage(input: &[u8]) -> IResult<&[u8], Stage> { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 let start_offset = 0; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 let i = &input[start_offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 let (i, (num_models, num_faces, object_instances_offset, script_offset, _)) = tuple((le_u16, le_u16, le_u32, le_u32, tag(b"\0\0\0\0")))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 let object_instances_offset = object_instances_offset as usize; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 let script_offset = script_offset as usize; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 let (i, name) = le_String(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 let (i, music_names) = map(tuple((le_String, le_String, le_String, le_String)), |(a, b, c, d)| [a, b, c, d])(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 let (mut i, music_paths) = map(tuple((le_String, le_String, le_String, le_String)), |(a, b, c, d)| [a, b, c, d])(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 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
|
174 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 let mut offsets = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 for _ in 0..num_models { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 let (i2, offset) = le_u32(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 offsets.push(offset as usize); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 // Read model definitions. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 let mut models = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 for offset in offsets { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
185 let i = &input[offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 let (mut i, (id, unknown, x, y, z, width, height, depth)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32, le_f32, le_f32, le_f32))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 let bounding_box = [x, y, z, width, height, depth]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 let mut quads = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 loop { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 let (i2, (unk1, size)) = tuple((le_u16, le_u16))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 if unk1 == 0xffff { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 break; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 assert_eq!(size, 0x1c); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 let (i2, (anm_script, _, x, y, z, width, height)) = tuple((le_u16, tag(b"\0\0"), le_f32, le_f32, le_f32, le_f32, le_f32))(i2)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 let quad = Quad { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 anm_script, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
198 pos: Position { x, y, z }, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 size_override: Box2D { width, height }, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 quads.push(quad); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 let model = Model { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 unknown, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 bounding_box, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 quads, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 models.push(model); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 // Read object usage. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 let mut instances = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 let mut i = &input[object_instances_offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 loop { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 let (i2, (id, unknown, x, y, z)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 if id == 0xffff && unknown == 0xffff { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 break; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 assert_eq!(unknown, 0x100); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 let instance = Instance { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 id, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 pos: Position { x, y, z }, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 instances.push(instance); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 i = i2; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 // Read the script. |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 let mut script = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 let mut i = &input[script_offset..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 loop { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 let (i2, (time, opcode, size)) = tuple((le_u32, le_u16, le_u16))(i)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 if time == 0xffffffff && opcode == 0xffff && size == 0xffff { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 break; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 assert_eq!(size, 12); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 let data = &i2[..12]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 let (data, instr) = parse_instruction_args(data, opcode)?; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 assert_eq!(data.len(), 0); |
679
6020e33d4fc4
Implement a .std renderer, and its associated VM.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
671
diff
changeset
|
241 println!("{} {:?}", time, instr); |
671
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 script.push(Call { time, instr }); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 i = &i2[12..]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 let stage = Stage { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 name, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 musics, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 models, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
250 instances, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 script, |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 }; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 Ok((b"", stage)) |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 #[cfg(test)] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 mod tests { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 use super::*; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 use std::io::{self, Read}; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 use std::fs::File; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 #[test] |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
263 fn std() { |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
264 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
|
265 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
|
266 let mut buf = vec![]; |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 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
|
268 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
|
269 assert_eq!(stage.name, "夢幻夜行絵巻 ~ Mystic Flier"); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 assert_eq!(stage.musics.len(), 4); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 assert_eq!(stage.models.len(), 13); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 assert_eq!(stage.instances.len(), 90); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
273 assert_eq!(stage.script.len(), 21); |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
274 } |
266911c0ccfd
Add a parser for the stage background format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
275 } |