1pub const SEED_MAGIC: i32 = 7573;
2pub const LIFE_EXTEND_SCALE: i32 = 8;
3pub const LIFE_EXTEND_MIN: i32 = 64;
4
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub struct Vector2 {
7 pub x: f32,
8 pub y: f32,
9}
10
11impl Vector2 {
12 pub fn new(x: f32, y: f32) -> Self {
13 Self { x, y }
14 }
15}
16
17#[derive(Clone, Copy, Debug, Default, PartialEq)]
18pub struct Vector3 {
19 pub x: f32,
20 pub y: f32,
21 pub z: f32,
22}
23
24#[derive(Clone, Copy, Debug, Default, PartialEq)]
25pub struct Color {
26 pub a: u8,
27 pub r: u8,
28 pub g: u8,
29 pub b: u8,
30}
31
32impl Color {
33 pub fn new(a: u8, r: u8, g: u8, b: u8) -> Self {
34 Self { a, r, g, b }
35 }
36}
37
38#[derive(Clone, Debug, PartialEq)]
39pub struct EmitterParameter {
40 pub life: i32,
41 pub interval: i32,
42 pub emitnum: i32,
43 pub emitmax: i32,
44 pub particle_life: i32,
45 pub particle_life2: i32,
46 pub is_infinite: bool,
47 pub loop_start: i32,
48 pub loop_end: i32,
49 pub loop_len: i32,
50 pub loop_gen: i32,
51}
52
53impl Default for EmitterParameter {
54 fn default() -> Self {
55 Self { life: 15, interval: 1, emitnum: 2, emitmax: 32, particle_life: 15, particle_life2: 15, is_infinite: false, loop_start: 0, loop_end: 0, loop_len: 0, loop_gen: 0 }
56 }
57}
58
59#[derive(Clone, Debug, PartialEq)]
60pub struct ParticleParameter {
61 pub scale: Vector2,
62 pub startcolor: Color,
63 pub endcolor: Color,
64 pub speed: f32,
65 pub speed2: f32,
66 pub angle: f32,
67 pub angle_variance: f32,
68 pub use_gravity: bool,
69 pub gravity: Vector2,
70 pub use_offset: bool,
71 pub offset: Vector2,
72 pub offset2: Vector2,
73 pub use_rotation: bool,
74 pub rotation: f32,
75 pub rotation2: f32,
76 pub rotation_add: f32,
77 pub rotation_add2: f32,
78 pub use_rotation_trans: bool,
79 pub rotation_factor: f32,
80 pub end_life_time_per: f32,
81 pub use_tan_accel: bool,
82 pub tangential_accel: f32,
83 pub tangential_accel2: f32,
84 pub use_color: bool,
85 pub init_color: Color,
86 pub init_color2: Color,
87 pub use_trans_color: bool,
88 pub trans_color: Color,
89 pub trans_color2: Color,
90 pub use_init_scale: bool,
91 pub scale_range: Vector2,
92 pub scale_factor: f32,
93 pub scale_factor2: f32,
94 pub use_trans_scale: bool,
95 pub transscale: Vector2,
96 pub scale_range2: Vector2,
97 pub transscale_factor: f32,
98 pub transscale_factor2: f32,
99 pub delay: f32,
100 pub use_p_gravity: bool,
101 pub gravity_pos: Vector2,
102 pub gravity_power: f32,
103 pub use_alpha_fade: bool,
104 pub alpha_fade: f32,
105 pub alpha_fade2: f32,
106 pub use_trans_speed: bool,
107 pub trans_speed: f32,
108 pub trans_speed2: f32,
109 pub use_turn_direc: bool,
110 pub direc_rot_add: f32,
111 pub user_override_r_seed: bool,
112 pub override_r_seed: i32,
113}
114
115impl Default for ParticleParameter {
116 fn default() -> Self {
117 Self {
118 scale: Vector2::new(1.0, 1.0),
119 startcolor: Color::new(255, 255, 255, 255),
120 endcolor: Color::new(255, 255, 255, 255),
121 speed: 0.0,
122 speed2: 0.0,
123 angle: 0.0,
124 angle_variance: 0.0,
125 use_gravity: false,
126 gravity: Vector2::default(),
127 use_offset: false,
128 offset: Vector2::default(),
129 offset2: Vector2::default(),
130 use_rotation: false,
131 rotation: 0.0,
132 rotation2: 0.0,
133 rotation_add: 0.0,
134 rotation_add2: 0.0,
135 use_rotation_trans: false,
136 rotation_factor: 0.0,
137 end_life_time_per: 0.0,
138 use_tan_accel: false,
139 tangential_accel: 0.0,
140 tangential_accel2: 0.0,
141 use_color: false,
142 init_color: Color::default(),
143 init_color2: Color::default(),
144 use_trans_color: false,
145 trans_color: Color::default(),
146 trans_color2: Color::default(),
147 use_init_scale: false,
148 scale_range: Vector2::default(),
149 scale_factor: 1.0,
150 scale_factor2: 0.0,
151 use_trans_scale: false,
152 transscale: Vector2::new(1.0, 1.0),
153 scale_range2: Vector2::default(),
154 transscale_factor: 1.0,
155 transscale_factor2: 0.0,
156 delay: 0.0,
157 use_p_gravity: false,
158 gravity_pos: Vector2::default(),
159 gravity_power: 0.0,
160 use_alpha_fade: false,
161 alpha_fade: 0.0,
162 alpha_fade2: 0.0,
163 use_trans_speed: false,
164 trans_speed: 0.0,
165 trans_speed2: 0.0,
166 use_turn_direc: false,
167 direc_rot_add: 0.0,
168 user_override_r_seed: false,
169 override_r_seed: 0,
170 }
171 }
172}
173
174#[derive(Clone, Copy, Debug, PartialEq, Default)]
175pub struct EmitPattern {
176 pub uid: i32,
177 pub life: i32,
178 pub cycle: i32,
179}
180
181#[derive(Clone, Copy, Debug, PartialEq)]
182pub struct ParticleDrawState {
183 pub x: f32,
184 pub y: f32,
185 pub scale_x: f32,
186 pub scale_y: f32,
187 pub rotation: f32,
188 pub direction: f32,
189 pub color: Color,
190}
191
192impl Default for ParticleDrawState {
193 fn default() -> Self {
194 Self { x: 0.0, y: 0.0, scale_x: 1.0, scale_y: 1.0, rotation: 0.0, direction: 0.0, color: Color::new(255, 255, 255, 255) }
195 }
196}
197
198#[cfg(test)]
199mod tests {
200 use super::*;
201
202 #[test]
203 fn test_vector2_new() {
204 let v = Vector2::new(1.5, -2.0);
205 assert_eq!(v.x, 1.5);
206 assert_eq!(v.y, -2.0);
207 }
208
209 #[test]
210 fn test_color_new() {
211 let c = Color::new(255, 128, 64, 32);
212 assert_eq!(c.a, 255);
213 assert_eq!(c.r, 128);
214 assert_eq!(c.g, 64);
215 assert_eq!(c.b, 32);
216 }
217
218 #[test]
219 fn test_emitter_parameter_default() {
220 let ep = EmitterParameter::default();
221 assert_eq!(ep.life, 15);
222 assert_eq!(ep.emitnum, 2);
223 assert_eq!(ep.emitmax, 32);
224 assert!(!ep.is_infinite);
225 }
226
227 #[test]
228 fn test_particle_parameter_default() {
229 let pp = ParticleParameter::default();
230 assert_eq!(pp.scale.x, 1.0);
231 assert_eq!(pp.scale.y, 1.0);
232 assert_eq!(pp.startcolor.a, 255);
233 assert_eq!(pp.speed, 0.0);
234 assert!(!pp.use_gravity);
235 }
236
237 #[test]
238 fn test_particle_draw_state_default() {
239 let pds = ParticleDrawState::default();
240 assert_eq!(pds.x, 0.0);
241 assert_eq!(pds.y, 0.0);
242 assert_eq!(pds.scale_x, 1.0);
243 assert_eq!(pds.color.a, 255);
244 }
245}