assembly_data/xml/obj/store/
sink.rs1use super::super::sink::*;
2use super::*;
3
4pub type ObjectStoreDataSink<'a> = &'a mut Object;
5pub type DestructibleStoreDataSink<'a> = (&'a mut Object, Destructible);
6pub type InventoryStoreDataSink<'a> = (&'a mut Object, Inventory);
7pub type MinifigStoreDataSink<'a> = (&'a mut Object, Minifig);
8
9impl<'a> ObjectDataSink for ObjectStoreDataSink<'a> {
10 type V = Self;
11 type B = ObjectStoreDataSink<'a>;
12 type D = DestructibleStoreDataSink<'a>;
13 type I = InventoryStoreDataSink<'a>;
14 type M = MinifigStoreDataSink<'a>;
15
16 fn push_attr_v(self, v: u32) -> Self::V {
17 self.attr_v = v;
18 self
19 }
20
21 fn start_buff(self) -> Self::B {
22 self
23 }
24
25 fn start_dest(self) -> Self::D {
26 (self, Destructible::default())
27 }
28
29 fn start_inv(self) -> Self::I {
30 (self, Inventory::default())
31 }
32
33 fn start_mf(self) -> Self::M {
34 (self, Minifig::default())
35 }
36}
37
38impl<'a> BuffDataSink for ObjectStoreDataSink<'a> {
39 type E = ObjectStoreDataSink<'a>;
40
41 fn end_buff(self) -> Self::E {
42 self
43 }
44}
45
46impl<'a> DestructibleDataSink for DestructibleStoreDataSink<'a> {
47 type E = ObjectStoreDataSink<'a>;
48
49 fn end_dest(self) -> Self::E {
50 let obj = self.0;
51 obj.dest = Some(self.1);
52 obj
53 }
54
55 fn push_attr_ac(mut self, ac: u32) -> Self {
56 self.1.attr_ac = Some(ac);
57 self
58 }
59
60 fn push_attr_am(mut self, am: u32) -> Self {
61 self.1.attr_am = Some(am);
62 self
63 }
64
65 fn push_attr_d(mut self, d: bool) -> Self {
66 self.1.attr_d = Some(d);
67 self
68 }
69
70 fn push_attr_hc(mut self, hc: u32) -> Self {
71 self.1.attr_hc = Some(hc);
72 self
73 }
74
75 fn push_attr_hm(mut self, hm: u32) -> Self {
76 self.1.attr_hm = Some(hm);
77 self
78 }
79
80 fn push_attr_ic(mut self, ic: u32) -> Self {
81 self.1.attr_ic = Some(ic);
82 self
83 }
84
85 fn push_attr_im(mut self, im: u32) -> Self {
86 self.1.attr_im = Some(im);
87 self
88 }
89
90 fn push_attr_imm(mut self, imm: u32) -> Self {
91 self.1.attr_imm = Some(imm);
92 self
93 }
94
95 fn push_attr_rsh(mut self, rsh: u32) -> Self {
96 self.1.attr_rsh = Some(rsh);
97 self
98 }
99
100 fn push_attr_rsi(mut self, rsi: u32) -> Self {
101 self.1.attr_rsi = Some(rsi);
102 self
103 }
104}
105
106impl<'a> InventoryDataSink for InventoryStoreDataSink<'a> {
107 type E = ObjectStoreDataSink<'a>;
108 type IB = InventoryStoreDataSink<'a>;
109 type IG = InventoryStoreDataSink<'a>;
110 type II = InventoryStoreDataSink<'a>;
111
112 fn end_inv(self) -> Self::E {
113 let obj = self.0;
114 obj.inv = Some(self.1);
115 obj
116 }
117
118 fn push_attr_csl(mut self, csl: u32) -> Self {
119 self.1.attr_csl = Some(csl);
120 self
121 }
122
123 fn start_bag(self) -> Self::IB {
124 self
125 }
126
127 fn start_grps(self) -> Self::IG {
128 self
129 }
130
131 fn start_items(self) -> Self::II {
132 self
133 }
134}
135
136pub type InventoryBagStoreDataSink<'a> = (&'a mut Object, Inventory, Bag);
137
138impl<'a> InventoryBagsDataSink for InventoryStoreDataSink<'a> {
139 type E = InventoryStoreDataSink<'a>;
140 type B = InventoryBagStoreDataSink<'a>;
141
142 fn end_bag(self) -> Self::E {
143 self
144 }
145
146 fn start_b(self) -> Self::B {
147 (self.0, self.1, Bag::default())
148 }
149}
150
151impl<'a> InventoryBagDataSink for InventoryBagStoreDataSink<'a> {
152 type E = InventoryStoreDataSink<'a>;
153
154 fn end_b(self) -> Self::E {
155 let mut inv = self.1;
156 inv.bag.push(self.2);
157 (self.0, inv)
158 }
159
160 fn push_attr_t(mut self, v: u32) -> Self {
161 self.2.attr_t = v;
162 self
163 }
164
165 fn push_attr_m(mut self, v: u32) -> Self {
166 self.2.attr_m = v;
167 self
168 }
169}
170
171pub type InventoryGroupStoreDataSink<'a> = (&'a mut Object, Inventory, Group);
172
173impl<'a> InventoryGroupsDataSink for InventoryStoreDataSink<'a> {
174 type E = InventoryStoreDataSink<'a>;
175 type G = InventoryGroupStoreDataSink<'a>;
176
177 fn end_grps(self) -> Self::E {
178 self
179 }
180
181 fn start_grp(self) -> Self::G {
182 (self.0, self.1, Group::default())
183 }
184}
185
186impl<'a> InventoryGroupDataSink for InventoryGroupStoreDataSink<'a> {
187 type E = InventoryStoreDataSink<'a>;
188
189 fn end_grp(self) -> Self::E {
190 let mut inv = self.1;
191 inv.grps.push(self.2);
192 (self.0, inv)
193 }
194
195 fn push_attr_id(mut self, v: String) -> Self {
196 self.2.attr_id = v;
197 self
198 }
199
200 fn push_attr_l(mut self, v: String) -> Self {
201 self.2.attr_l = v;
202 self
203 }
204
205 fn push_attr_n(mut self, v: String) -> Self {
206 self.2.attr_n = v;
207 self
208 }
209
210 fn push_attr_t(mut self, v: u32) -> Self {
211 self.2.attr_t = v;
212 self
213 }
214
215 fn push_attr_u(mut self, v: String) -> Self {
216 self.2.attr_u = v;
217 self
218 }
219}
220
221pub type InventoryItemBagStoreDataSink<'a> = (&'a mut Object, Inventory, ItemBag);
222
223impl<'a> InventoryItemsDataSink for InventoryStoreDataSink<'a> {
224 type E = InventoryStoreDataSink<'a>;
225 type I = InventoryItemBagStoreDataSink<'a>;
226
227 fn push_attr_nn(mut self, v: String) -> Self {
228 self.1.items.attr_nn = v;
229 self
230 }
231
232 fn start_in(self) -> Self::I {
233 (self.0, self.1, ItemBag::default())
234 }
235
236 fn end_items(self) -> Self::E {
237 self
238 }
239}
240
241pub type InventoryItemStoreDataSink<'a> = (&'a mut Object, Inventory, ItemBag, Item);
242
243impl<'a> InventoryItemBagDataSink for InventoryItemBagStoreDataSink<'a> {
244 type E = InventoryStoreDataSink<'a>;
245 type I = InventoryItemStoreDataSink<'a>;
246
247 fn push_attr_t(mut self, v: u32) -> Self {
248 self.2.attr_t = v;
249 self
250 }
251
252 fn end_in(self) -> Self::E {
253 let mut inv = self.1;
254 inv.items.children.push(self.2);
255 (self.0, inv)
256 }
257
258 fn start_i(self) -> Self::I {
259 (self.0, self.1, self.2, Item::default())
260 }
261}
262
263pub type InventoryItemExtraStoreDataSink<'a> =
264 (&'a mut Object, Inventory, ItemBag, Item, ItemExtra);
265
266impl<'a> InventoryItemDataSink for InventoryItemStoreDataSink<'a> {
267 type E = InventoryItemBagStoreDataSink<'a>;
268 type X = InventoryItemExtraStoreDataSink<'a>;
269
270 fn end_i(self) -> Self::E {
271 let mut bag = self.2;
272 bag.children.push(self.3);
273 (self.0, self.1, bag)
274 }
275
276 fn push_attr_b(mut self, v: bool) -> Self {
277 self.3.attr_b = v;
278 self
279 }
280
281 fn push_attr_c(mut self, v: u32) -> Self {
282 self.3.attr_c = v;
283 self
284 }
285
286 fn push_attr_eq(mut self, v: bool) -> Self {
287 self.3.attr_eq = v;
288 self
289 }
290
291 fn push_attr_id(mut self, v: u64) -> Self {
292 self.3.attr_id = v;
293 self
294 }
295
296 fn push_attr_l(mut self, v: u32) -> Self {
297 self.3.attr_l = v;
298 self
299 }
300
301 fn push_attr_s(mut self, v: u32) -> Self {
302 self.3.attr_s = v;
303 self
304 }
305
306 fn push_attr_sk(mut self, v: u32) -> Self {
307 self.3.attr_sk = v;
308 self
309 }
310
311 fn start_x(self) -> Self::X {
312 (self.0, self.1, self.2, self.3, ItemExtra::default())
313 }
314}
315
316impl<'a> InventoryItemExtraDataSink for InventoryItemExtraStoreDataSink<'a> {
317 type E = InventoryItemStoreDataSink<'a>;
318
319 fn end_x(self) -> Self::E {
320 let mut item = self.3;
321 item.x = Some(self.4);
322 (self.0, self.1, self.2, item)
323 }
324
325 fn push_attr_b(mut self, v: String) -> Self {
326 self.4.attr_b = v;
327 self
328 }
329
330 fn push_attr_ma(mut self, v: String) -> Self {
331 self.4.attr_ma = v;
332 self
333 }
334
335 fn push_attr_ub(mut self, v: String) -> Self {
336 self.4.attr_ub = v;
337 self
338 }
339
340 fn push_attr_ud(mut self, v: String) -> Self {
341 self.4.attr_ud = v;
342 self
343 }
344
345 fn push_attr_ui(mut self, v: String) -> Self {
346 self.4.attr_ui = v;
347 self
348 }
349
350 fn push_attr_um(mut self, v: String) -> Self {
351 self.4.attr_um = v;
352 self
353 }
354
355 fn push_attr_un(mut self, v: String) -> Self {
356 self.4.attr_ub = v;
357 self
358 }
359
360 fn push_attr_uo(mut self, v: String) -> Self {
361 self.4.attr_uo = v;
362 self
363 }
364
365 fn push_attr_up(mut self, v: String) -> Self {
366 self.4.attr_up = v;
367 self
368 }
369}
370
371impl<'a> MinifigDataSink for MinifigStoreDataSink<'a> {
372 type E = ObjectStoreDataSink<'a>;
373
374 fn end_mf(self) -> Self::E {
375 let obj = self.0;
376 obj.mf = Some(self.1);
377 obj
378 }
379
380 fn push_attr_cd(mut self, v: u32) -> Self {
381 self.1.attr_cd = v;
382 self
383 }
384
385 fn push_attr_es(mut self, v: u32) -> Self {
386 self.1.attr_es = v;
387 self
388 }
389
390 fn push_attr_ess(mut self, v: u32) -> Self {
391 self.1.attr_ess = v;
392 self
393 }
394
395 fn push_attr_hc(mut self, v: u32) -> Self {
396 self.1.attr_hc = v;
397 self
398 }
399
400 fn push_attr_hd(mut self, v: u32) -> Self {
401 self.1.attr_hd = v;
402 self
403 }
404
405 fn push_attr_hdc(mut self, v: u32) -> Self {
406 self.1.attr_hdc = v;
407 self
408 }
409
410 fn push_attr_hs(mut self, v: u32) -> Self {
411 self.1.attr_hs = v;
412 self
413 }
414
415 fn push_attr_l(mut self, v: u32) -> Self {
416 self.1.attr_l = v;
417 self
418 }
419
420 fn push_attr_lh(mut self, v: u32) -> Self {
421 self.1.attr_lh = v;
422 self
423 }
424
425 fn push_attr_ms(mut self, v: u32) -> Self {
426 self.1.attr_ms = v;
427 self
428 }
429
430 fn push_attr_rh(mut self, v: u32) -> Self {
431 self.1.attr_rh = v;
432 self
433 }
434
435 fn push_attr_t(mut self, v: u32) -> Self {
436 self.1.attr_t = v;
437 self
438 }
439}
440
441#[cfg(test)]
442mod test {
443 use super::*;
444
445 #[test]
446 fn test() {
447 let comp_obj = Object {
448 dest: Some(Destructible {
449 attr_d: Some(true),
450 attr_im: Some(10),
451 ..Destructible::default()
452 }),
453 inv: Some(Inventory {
454 bag: vec![
455 Bag {
456 attr_t: 2,
457 attr_m: 3,
458 },
459 Bag {
460 attr_t: 4,
461 attr_m: 8,
462 },
463 ],
464 grps: vec![Group {
465 attr_n: String::from("Name"),
466 ..Group::default()
467 }],
468 items: Items {
469 children: vec![ItemBag {
470 attr_t: 2,
471 children: vec![
472 Item {
473 attr_l: 1234,
474 ..Item::default()
475 },
476 Item {
477 attr_l: 5678,
478 ..Item::default()
479 },
480 ],
481 }],
482 ..Items::default()
483 },
484 ..Inventory::default()
485 }),
486 mf: Some(Minifig {
487 attr_hs: 4,
488 attr_cd: 10,
489 ..Minifig::default()
490 }),
491 ..Object::default()
492 };
493
494 let mut test_obj = Object::default();
495 let sink = &mut test_obj;
496 sink.start_dest()
497 .push_attr_d(true)
498 .push_attr_im(10)
499 .end_dest()
500 .start_inv()
501 .start_bag()
502 .start_b()
503 .push_attr_t(2)
504 .push_attr_m(3)
505 .end_b()
506 .start_b()
507 .push_attr_t(4)
508 .push_attr_m(8)
509 .end_b()
510 .end_bag()
511 .start_grps()
512 .start_grp()
513 .push_attr_n(String::from("Name"))
514 .end_grp()
515 .end_grps()
516 .start_items()
517 .start_in()
518 .push_attr_t(2)
519 .start_i()
520 .push_attr_l(1234)
521 .end_i()
522 .start_i()
523 .push_attr_l(5678)
524 .end_i()
525 .end_in()
526 .end_items()
527 .end_inv()
528 .start_mf()
529 .push_attr_hs(4)
530 .push_attr_cd(10)
531 .end_mf();
532
533 assert_eq!(comp_obj, test_obj);
534 }
535}