wow_dbc/wrath_tables/
spell_visual_kit.rs1use crate::{
2 DbcTable, Indexable,
3};
4use crate::header::{
5 DbcHeader, HEADER_SIZE, parse_header,
6};
7use crate::wrath_tables::animation_data::AnimationDataKey;
8use crate::wrath_tables::sound_entries::SoundEntriesKey;
9use crate::wrath_tables::spell_effect_camera_shakes::SpellEffectCameraShakesKey;
10use std::io::Write;
11
12#[derive(Debug, Clone, PartialEq, PartialOrd)]
13pub struct SpellVisualKit {
14 pub rows: Vec<SpellVisualKitRow>,
15}
16
17impl DbcTable for SpellVisualKit {
18 type Row = SpellVisualKitRow;
19
20 const FILENAME: &'static str = "SpellVisualKit.dbc";
21
22 fn rows(&self) -> &[Self::Row] { &self.rows }
23 fn rows_mut(&mut self) -> &mut [Self::Row] { &mut self.rows }
24
25 fn read(b: &mut impl std::io::Read) -> Result<Self, crate::DbcError> {
26 let mut header = [0_u8; HEADER_SIZE];
27 b.read_exact(&mut header)?;
28 let header = parse_header(&header)?;
29
30 if header.record_size != 152 {
31 return Err(crate::DbcError::InvalidHeader(
32 crate::InvalidHeaderError::RecordSize {
33 expected: 152,
34 actual: header.record_size,
35 },
36 ));
37 }
38
39 if header.field_count != 38 {
40 return Err(crate::DbcError::InvalidHeader(
41 crate::InvalidHeaderError::FieldCount {
42 expected: 38,
43 actual: header.field_count,
44 },
45 ));
46 }
47
48 let mut r = vec![0_u8; (header.record_count * header.record_size) as usize];
49 b.read_exact(&mut r)?;
50
51 let mut rows = Vec::with_capacity(header.record_count as usize);
52
53 for mut chunk in r.chunks(header.record_size as usize) {
54 let chunk = &mut chunk;
55
56 let id = SpellVisualKitKey::new(crate::util::read_i32_le(chunk)?);
58
59 let start_anim_id = AnimationDataKey::new(crate::util::read_i32_le(chunk)?.into());
61
62 let anim_id = AnimationDataKey::new(crate::util::read_i32_le(chunk)?.into());
64
65 let head_effect = crate::util::read_i32_le(chunk)?;
67
68 let chest_effect = crate::util::read_i32_le(chunk)?;
70
71 let base_effect = crate::util::read_i32_le(chunk)?;
73
74 let left_hand_effect = crate::util::read_i32_le(chunk)?;
76
77 let right_hand_effect = crate::util::read_i32_le(chunk)?;
79
80 let breath_effect = crate::util::read_i32_le(chunk)?;
82
83 let left_weapon_effect = crate::util::read_i32_le(chunk)?;
85
86 let right_weapon_effect = crate::util::read_i32_le(chunk)?;
88
89 let special_effect = crate::util::read_array_i32::<3>(chunk)?;
91
92 let world_effect = crate::util::read_i32_le(chunk)?;
94
95 let sound_id = SoundEntriesKey::new(crate::util::read_i32_le(chunk)?.into());
97
98 let shake_id = SpellEffectCameraShakesKey::new(crate::util::read_i32_le(chunk)?.into());
100
101 let char_proc = crate::util::read_array_i32::<4>(chunk)?;
103
104 let char_param_zero = crate::util::read_array_f32::<4>(chunk)?;
106
107 let char_param_one = crate::util::read_array_f32::<4>(chunk)?;
109
110 let char_param_two = crate::util::read_array_f32::<4>(chunk)?;
112
113 let char_param_three = crate::util::read_array_f32::<4>(chunk)?;
115
116 let flags = crate::util::read_i32_le(chunk)?;
118
119
120 rows.push(SpellVisualKitRow {
121 id,
122 start_anim_id,
123 anim_id,
124 head_effect,
125 chest_effect,
126 base_effect,
127 left_hand_effect,
128 right_hand_effect,
129 breath_effect,
130 left_weapon_effect,
131 right_weapon_effect,
132 special_effect,
133 world_effect,
134 sound_id,
135 shake_id,
136 char_proc,
137 char_param_zero,
138 char_param_one,
139 char_param_two,
140 char_param_three,
141 flags,
142 });
143 }
144
145 Ok(SpellVisualKit { rows, })
146 }
147
148 fn write(&self, b: &mut impl Write) -> Result<(), std::io::Error> {
149 let header = DbcHeader {
150 record_count: self.rows.len() as u32,
151 field_count: 38,
152 record_size: 152,
153 string_block_size: 1,
154 };
155
156 b.write_all(&header.write_header())?;
157
158 for row in &self.rows {
159 b.write_all(&row.id.id.to_le_bytes())?;
161
162 b.write_all(&(row.start_anim_id.id as i32).to_le_bytes())?;
164
165 b.write_all(&(row.anim_id.id as i32).to_le_bytes())?;
167
168 b.write_all(&row.head_effect.to_le_bytes())?;
170
171 b.write_all(&row.chest_effect.to_le_bytes())?;
173
174 b.write_all(&row.base_effect.to_le_bytes())?;
176
177 b.write_all(&row.left_hand_effect.to_le_bytes())?;
179
180 b.write_all(&row.right_hand_effect.to_le_bytes())?;
182
183 b.write_all(&row.breath_effect.to_le_bytes())?;
185
186 b.write_all(&row.left_weapon_effect.to_le_bytes())?;
188
189 b.write_all(&row.right_weapon_effect.to_le_bytes())?;
191
192 for i in row.special_effect {
194 b.write_all(&i.to_le_bytes())?;
195 }
196
197
198 b.write_all(&row.world_effect.to_le_bytes())?;
200
201 b.write_all(&(row.sound_id.id as i32).to_le_bytes())?;
203
204 b.write_all(&(row.shake_id.id as i32).to_le_bytes())?;
206
207 for i in row.char_proc {
209 b.write_all(&i.to_le_bytes())?;
210 }
211
212
213 for i in row.char_param_zero {
215 b.write_all(&i.to_le_bytes())?;
216 }
217
218
219 for i in row.char_param_one {
221 b.write_all(&i.to_le_bytes())?;
222 }
223
224
225 for i in row.char_param_two {
227 b.write_all(&i.to_le_bytes())?;
228 }
229
230
231 for i in row.char_param_three {
233 b.write_all(&i.to_le_bytes())?;
234 }
235
236
237 b.write_all(&row.flags.to_le_bytes())?;
239
240 }
241
242 b.write_all(&[0_u8])?;
243
244 Ok(())
245 }
246
247}
248
249impl Indexable for SpellVisualKit {
250 type PrimaryKey = SpellVisualKitKey;
251 fn get(&self, key: impl TryInto<Self::PrimaryKey>) -> Option<&Self::Row> {
252 let key = key.try_into().ok()?;
253 self.rows.iter().find(|a| a.id.id == key.id)
254 }
255
256 fn get_mut(&mut self, key: impl TryInto<Self::PrimaryKey>) -> Option<&mut Self::Row> {
257 let key = key.try_into().ok()?;
258 self.rows.iter_mut().find(|a| a.id.id == key.id)
259 }
260}
261
262#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, Default)]
263pub struct SpellVisualKitKey {
264 pub id: i32
265}
266
267impl SpellVisualKitKey {
268 pub const fn new(id: i32) -> Self {
269 Self { id }
270 }
271
272}
273
274impl From<u8> for SpellVisualKitKey {
275 fn from(v: u8) -> Self {
276 Self::new(v.into())
277 }
278}
279
280impl From<u16> for SpellVisualKitKey {
281 fn from(v: u16) -> Self {
282 Self::new(v.into())
283 }
284}
285
286impl From<i8> for SpellVisualKitKey {
287 fn from(v: i8) -> Self {
288 Self::new(v.into())
289 }
290}
291
292impl From<i16> for SpellVisualKitKey {
293 fn from(v: i16) -> Self {
294 Self::new(v.into())
295 }
296}
297
298impl From<i32> for SpellVisualKitKey {
299 fn from(v: i32) -> Self {
300 Self::new(v)
301 }
302}
303
304impl TryFrom<u32> for SpellVisualKitKey {
305 type Error = u32;
306 fn try_from(v: u32) -> Result<Self, Self::Error> {
307 Ok(TryInto::<i32>::try_into(v).ok().ok_or(v)?.into())
308 }
309}
310
311impl TryFrom<usize> for SpellVisualKitKey {
312 type Error = usize;
313 fn try_from(v: usize) -> Result<Self, Self::Error> {
314 Ok(TryInto::<i32>::try_into(v).ok().ok_or(v)?.into())
315 }
316}
317
318impl TryFrom<u64> for SpellVisualKitKey {
319 type Error = u64;
320 fn try_from(v: u64) -> Result<Self, Self::Error> {
321 Ok(TryInto::<i32>::try_into(v).ok().ok_or(v)?.into())
322 }
323}
324
325impl TryFrom<i64> for SpellVisualKitKey {
326 type Error = i64;
327 fn try_from(v: i64) -> Result<Self, Self::Error> {
328 Ok(TryInto::<i32>::try_into(v).ok().ok_or(v)?.into())
329 }
330}
331
332impl TryFrom<isize> for SpellVisualKitKey {
333 type Error = isize;
334 fn try_from(v: isize) -> Result<Self, Self::Error> {
335 Ok(TryInto::<i32>::try_into(v).ok().ok_or(v)?.into())
336 }
337}
338
339#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
340pub struct SpellVisualKitRow {
341 pub id: SpellVisualKitKey,
342 pub start_anim_id: AnimationDataKey,
343 pub anim_id: AnimationDataKey,
344 pub head_effect: i32,
345 pub chest_effect: i32,
346 pub base_effect: i32,
347 pub left_hand_effect: i32,
348 pub right_hand_effect: i32,
349 pub breath_effect: i32,
350 pub left_weapon_effect: i32,
351 pub right_weapon_effect: i32,
352 pub special_effect: [i32; 3],
353 pub world_effect: i32,
354 pub sound_id: SoundEntriesKey,
355 pub shake_id: SpellEffectCameraShakesKey,
356 pub char_proc: [i32; 4],
357 pub char_param_zero: [f32; 4],
358 pub char_param_one: [f32; 4],
359 pub char_param_two: [f32; 4],
360 pub char_param_three: [f32; 4],
361 pub flags: i32,
362}
363