vpin 0.23.5

Rust library for working with Visual Pinball VPX files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
use super::dragpoint::DragPoint;
use crate::impl_shared_attributes;
use crate::vpx::biff::{self, BiffRead, BiffReader, BiffWrite};
use crate::vpx::gameitem::ramp_image_alignment::RampImageAlignment;
use crate::vpx::gameitem::select::{TimerData, WriteSharedAttributes};
use log::warn;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(test, derive(fake::Dummy))]
pub enum RampType {
    Flat = 0,
    FourWire = 1,
    TwoWire = 2,
    ThreeWireLeft = 3,
    ThreeWireRight = 4,
    OneWire = 5,
}

impl From<u32> for RampType {
    fn from(value: u32) -> Self {
        match value {
            0 => RampType::Flat,
            1 => RampType::FourWire,
            2 => RampType::TwoWire,
            3 => RampType::ThreeWireLeft,
            4 => RampType::ThreeWireRight,
            5 => RampType::OneWire,
            _ => panic!("Invalid RampType {value}"),
        }
    }
}

impl From<&RampType> for u32 {
    fn from(value: &RampType) -> Self {
        match value {
            RampType::Flat => 0,
            RampType::FourWire => 1,
            RampType::TwoWire => 2,
            RampType::ThreeWireLeft => 3,
            RampType::ThreeWireRight => 4,
            RampType::OneWire => 5,
        }
    }
}

/// Serializes RampType to lowercase string
impl Serialize for RampType {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self {
            RampType::Flat => serializer.serialize_str("flat"),
            RampType::FourWire => serializer.serialize_str("four_wire"),
            RampType::TwoWire => serializer.serialize_str("two_wire"),
            RampType::ThreeWireLeft => serializer.serialize_str("three_wire_left"),
            RampType::ThreeWireRight => serializer.serialize_str("three_wire_right"),
            RampType::OneWire => serializer.serialize_str("one_wire"),
        }
    }
}

/// Deserializes RampType from lowercase string
/// or number for backwards compatibility
impl<'de> Deserialize<'de> for RampType {
    fn deserialize<D>(deserializer: D) -> Result<RampType, D::Error>
    where
        D: Deserializer<'de>,
    {
        struct RampTypeVisitor;

        impl serde::de::Visitor<'_> for RampTypeVisitor {
            type Value = RampType;

            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
                formatter.write_str("a string or number representing a TargetType")
            }

            fn visit_u64<E>(self, value: u64) -> Result<RampType, E>
            where
                E: serde::de::Error,
            {
                match value {
                    0 => Ok(RampType::Flat),
                    1 => Ok(RampType::FourWire),
                    2 => Ok(RampType::TwoWire),
                    3 => Ok(RampType::ThreeWireLeft),
                    4 => Ok(RampType::ThreeWireRight),
                    5 => Ok(RampType::OneWire),
                    _ => Err(serde::de::Error::unknown_variant(
                        &value.to_string(),
                        &["0", "1", "2", "3", "4", "5"],
                    )),
                }
            }

            fn visit_str<E>(self, value: &str) -> Result<RampType, E>
            where
                E: serde::de::Error,
            {
                match value {
                    "flat" => Ok(RampType::Flat),
                    "four_wire" => Ok(RampType::FourWire),
                    "two_wire" => Ok(RampType::TwoWire),
                    "three_wire_left" => Ok(RampType::ThreeWireLeft),
                    "three_wire_right" => Ok(RampType::ThreeWireRight),
                    "one_wire" => Ok(RampType::OneWire),
                    _ => Err(serde::de::Error::unknown_variant(
                        value,
                        &[
                            "flat",
                            "four_wire",
                            "two_wire",
                            "three_wire_left",
                            "three_wire_right",
                            "one_wire",
                        ],
                    )),
                }
            }
        }

        deserializer.deserialize_any(RampTypeVisitor)
    }
}

#[derive(Debug, PartialEq)]
#[cfg_attr(test, derive(fake::Dummy))]
pub struct Ramp {
    pub height_bottom: f32,  // 1
    pub height_top: f32,     // 2
    pub width_bottom: f32,   // 3
    pub width_top: f32,      // 4
    pub material: String,    // 5
    pub ramp_type: RampType, // TYPE 8
    pub name: String,        // 9
    pub image: String,       // 10
    /// Controls how the texture is mapped onto the ramp surface.
    /// - [`World`](RampImageAlignment::World): UVs are based on table coordinates.
    /// - [`Wrap`](RampImageAlignment::Wrap): UVs are based on the ramp bounding box
    ///   (texture is stretched to fit).
    ///
    /// Also used on: [`Flasher`].
    /// BIFF tag: `ALGN`
    pub image_alignment: RampImageAlignment, // 11
    pub image_walls: bool,   // 12
    pub left_wall_height: f32, // 13
    pub right_wall_height: f32, // 14
    pub left_wall_height_visible: f32, // 15
    pub right_wall_height_visible: f32, // 16
    pub hit_event: Option<bool>, // HTEV 17 (added in 10.?)
    pub threshold: Option<f32>, // THRS 18 (added in 10.?)
    pub elasticity: f32,     // 19
    pub friction: f32,       // 20
    pub scatter: f32,        // 21
    pub is_collidable: bool, // 22
    pub is_visible: bool,    // 23
    /// Offset applied when depth-sorting transparent and overlapping objects.
    /// Higher values move the object "further away" in the sort order, causing it
    /// to render behind objects with lower bias.
    /// Also used on: [`Flasher`], [`Primitive`], [`Light`], [`HitTarget`].
    /// BIFF tag: `RADB`
    pub depth_bias: f32,
    pub wire_diameter: f32,   // 25
    pub wire_distance_x: f32, // 26
    pub wire_distance_y: f32, // 27
    /// Whether this ramp appears in playfield reflections.
    ///
    /// When `true`, the ball is rendered in the reflection pass.
    /// When `false`, the ball won't appear as a reflection on the playfield.
    ///
    /// BIFF tag: `REEN` (was missing in 10.01)
    pub is_reflection_enabled: Option<bool>,
    pub physics_material: Option<String>, // MAPH 29 (added in 10.?)
    pub overwrite_physics: Option<bool>,  // OVPH 30 (added in 10.?)

    pub drag_points: Vec<DragPoint>,

    /// Timer data for scripting (shared across all game items).
    /// See [`TimerData`] for details.
    pub timer: TimerData,

    // these are shared between all items
    pub is_locked: bool,
    pub editor_layer: Option<u32>,
    pub editor_layer_name: Option<String>,
    // default "Layer_{editor_layer + 1}"
    pub editor_layer_visibility: Option<bool>,
    /// Added in 10.8.1
    pub part_group_name: Option<String>,
}
impl_shared_attributes!(Ramp);

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct RampJson {
    height_bottom: f32,
    height_top: f32,
    width_bottom: f32,
    width_top: f32,
    material: String,
    #[serde(flatten)]
    pub timer: TimerData,
    ramp_type: RampType,
    name: String,
    image: String,
    image_alignment: RampImageAlignment,
    image_walls: bool,
    left_wall_height: f32,
    right_wall_height: f32,
    left_wall_height_visible: f32,
    right_wall_height_visible: f32,
    hit_event: Option<bool>,
    threshold: Option<f32>,
    elasticity: f32,
    friction: f32,
    scatter: f32,
    is_collidable: bool,
    is_visible: bool,
    depth_bias: f32,
    wire_diameter: f32,
    wire_distance_x: f32,
    wire_distance_y: f32,
    is_reflection_enabled: Option<bool>,
    physics_material: Option<String>,
    overwrite_physics: Option<bool>, // true;
    drag_points: Vec<DragPoint>,
    #[serde(skip_serializing_if = "Option::is_none")]
    part_group_name: Option<String>,
}

impl RampJson {
    fn from_ramp(ramp: &Ramp) -> Self {
        Self {
            height_bottom: ramp.height_bottom,
            height_top: ramp.height_top,
            width_bottom: ramp.width_bottom,
            width_top: ramp.width_top,
            material: ramp.material.clone(),
            timer: ramp.timer.clone(),
            ramp_type: ramp.ramp_type.clone(),
            name: ramp.name.clone(),
            image: ramp.image.clone(),
            image_alignment: ramp.image_alignment.clone(),
            image_walls: ramp.image_walls,
            left_wall_height: ramp.left_wall_height,
            right_wall_height: ramp.right_wall_height,
            left_wall_height_visible: ramp.left_wall_height_visible,
            right_wall_height_visible: ramp.right_wall_height_visible,
            hit_event: ramp.hit_event,
            threshold: ramp.threshold,
            elasticity: ramp.elasticity,
            friction: ramp.friction,
            scatter: ramp.scatter,
            is_collidable: ramp.is_collidable,
            is_visible: ramp.is_visible,
            depth_bias: ramp.depth_bias,
            wire_diameter: ramp.wire_diameter,
            wire_distance_x: ramp.wire_distance_x,
            wire_distance_y: ramp.wire_distance_y,
            is_reflection_enabled: ramp.is_reflection_enabled,
            physics_material: ramp.physics_material.clone(),
            overwrite_physics: ramp.overwrite_physics,
            drag_points: ramp.drag_points.clone(),
            part_group_name: ramp.part_group_name.clone(),
        }
    }

    fn to_ramp(&self) -> Ramp {
        Ramp {
            height_bottom: self.height_bottom,
            height_top: self.height_top,
            width_bottom: self.width_bottom,
            width_top: self.width_top,
            material: self.material.clone(),
            timer: self.timer.clone(),
            ramp_type: self.ramp_type.clone(),
            name: self.name.clone(),
            image: self.image.clone(),
            image_alignment: self.image_alignment.clone(),
            image_walls: self.image_walls,
            left_wall_height: self.left_wall_height,
            right_wall_height: self.right_wall_height,
            left_wall_height_visible: self.left_wall_height_visible,
            right_wall_height_visible: self.right_wall_height_visible,
            hit_event: self.hit_event,
            threshold: self.threshold,
            elasticity: self.elasticity,
            friction: self.friction,
            scatter: self.scatter,
            is_collidable: self.is_collidable,
            is_visible: self.is_visible,
            depth_bias: self.depth_bias,
            wire_diameter: self.wire_diameter,
            wire_distance_x: self.wire_distance_x,
            wire_distance_y: self.wire_distance_y,
            is_reflection_enabled: self.is_reflection_enabled,
            physics_material: self.physics_material.clone(),
            overwrite_physics: self.overwrite_physics,
            drag_points: self.drag_points.clone(),
            // this is populated from a different file
            is_locked: false,
            // this is populated from a different file
            editor_layer: None,
            // this is populated from a different file
            editor_layer_name: None,
            // this is populated from a different file
            editor_layer_visibility: None,
            part_group_name: self.part_group_name.clone(),
        }
    }
}

impl Serialize for Ramp {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        RampJson::from_ramp(self).serialize(serializer)
    }
}

impl<'de> Deserialize<'de> for Ramp {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        let ramp_json = RampJson::deserialize(deserializer)?;
        Ok(ramp_json.to_ramp())
    }
}

impl Default for Ramp {
    fn default() -> Self {
        Self {
            height_bottom: 0.0,
            height_top: 50.0,
            width_bottom: 75.0,
            width_top: 60.0,
            material: Default::default(),
            timer: TimerData::default(),
            ramp_type: RampType::Flat,
            name: Default::default(),
            image: Default::default(),
            image_alignment: RampImageAlignment::World,
            image_walls: true,
            left_wall_height: 62.0,
            right_wall_height: 62.0,
            left_wall_height_visible: 30.0,
            right_wall_height_visible: 30.0,
            hit_event: None,
            threshold: None,
            elasticity: Default::default(),
            friction: Default::default(),
            scatter: Default::default(),
            is_collidable: true,
            is_visible: true,
            depth_bias: 0.0,
            wire_diameter: 8.0,
            wire_distance_x: 38.0,
            wire_distance_y: 88.0,
            is_reflection_enabled: None, // true,
            physics_material: None,
            overwrite_physics: None, // true;
            drag_points: Default::default(),
            is_locked: false,
            editor_layer: Default::default(),
            editor_layer_name: None,
            editor_layer_visibility: None,
            part_group_name: None,
        }
    }
}

impl BiffRead for Ramp {
    fn biff_read(reader: &mut BiffReader<'_>) -> Self {
        let mut ramp = Ramp::default();

        loop {
            reader.next(biff::WARN);
            if reader.is_eof() {
                break;
            }
            let tag = reader.tag();
            let tag_str = tag.as_str();
            match tag_str {
                "HTBT" => {
                    ramp.height_bottom = reader.get_f32();
                }
                "HTTP" => {
                    ramp.height_top = reader.get_f32();
                }
                "WDBT" => {
                    ramp.width_bottom = reader.get_f32();
                }
                "WDTP" => {
                    ramp.width_top = reader.get_f32();
                }
                "MATR" => {
                    ramp.material = reader.get_string();
                }
                "TYPE" => {
                    ramp.ramp_type = reader.get_u32().into();
                }
                "NAME" => {
                    ramp.name = reader.get_wide_string();
                }
                "IMAG" => {
                    ramp.image = reader.get_string();
                }
                "ALGN" => {
                    ramp.image_alignment = reader.get_u32().into();
                }
                "IMGW" => {
                    ramp.image_walls = reader.get_bool();
                }
                "WLHL" => {
                    ramp.left_wall_height = reader.get_f32();
                }
                "WLHR" => {
                    ramp.right_wall_height = reader.get_f32();
                }
                "WVHL" => {
                    ramp.left_wall_height_visible = reader.get_f32();
                }
                "WVHR" => {
                    ramp.right_wall_height_visible = reader.get_f32();
                }
                "HTEV" => {
                    ramp.hit_event = Some(reader.get_bool());
                }
                "THRS" => {
                    ramp.threshold = Some(reader.get_f32());
                }
                "ELAS" => {
                    ramp.elasticity = reader.get_f32();
                }
                "RFCT" => {
                    ramp.friction = reader.get_f32();
                }
                "RSCT" => {
                    ramp.scatter = reader.get_f32();
                }
                "CLDR" => {
                    ramp.is_collidable = reader.get_bool();
                }
                "RVIS" => {
                    ramp.is_visible = reader.get_bool();
                }
                "RADB" => {
                    ramp.depth_bias = reader.get_f32();
                }
                "RADI" => {
                    ramp.wire_diameter = reader.get_f32();
                }
                "RADX" => {
                    ramp.wire_distance_x = reader.get_f32();
                }
                "RADY" => {
                    ramp.wire_distance_y = reader.get_f32();
                }
                "REEN" => {
                    ramp.is_reflection_enabled = Some(reader.get_bool());
                }
                "MAPH" => {
                    ramp.physics_material = Some(reader.get_string());
                }
                "OVPH" => {
                    ramp.overwrite_physics = Some(reader.get_bool());
                }
                "PNTS" => {
                    // this is just a tag with no data
                }
                "DPNT" => {
                    let point = DragPoint::biff_read(reader);
                    ramp.drag_points.push(point);
                }
                _ => {
                    if !ramp.timer.biff_read_tag(tag_str, reader)
                        && !ramp.read_shared_attribute(tag_str, reader)
                    {
                        warn!(
                            "Unknown tag {} for {}",
                            tag_str,
                            std::any::type_name::<Self>()
                        );
                        reader.skip_tag();
                    }
                }
            }
        }
        ramp
    }
}

impl BiffWrite for Ramp {
    fn biff_write(&self, writer: &mut biff::BiffWriter) {
        writer.write_tagged_f32("HTBT", self.height_bottom);
        writer.write_tagged_f32("HTTP", self.height_top);
        writer.write_tagged_f32("WDBT", self.width_bottom);
        writer.write_tagged_f32("WDTP", self.width_top);
        writer.write_tagged_string("MATR", &self.material);
        self.timer.biff_write(writer);
        writer.write_tagged_u32("TYPE", (&self.ramp_type).into());
        writer.write_tagged_wide_string("NAME", &self.name);
        writer.write_tagged_string("IMAG", &self.image);
        writer.write_tagged_u32("ALGN", (&self.image_alignment).into());
        writer.write_tagged_bool("IMGW", self.image_walls);
        writer.write_tagged_f32("WLHL", self.left_wall_height);
        writer.write_tagged_f32("WLHR", self.right_wall_height);
        writer.write_tagged_f32("WVHL", self.left_wall_height_visible);
        writer.write_tagged_f32("WVHR", self.right_wall_height_visible);
        if let Some(hit_event) = self.hit_event {
            writer.write_tagged_bool("HTEV", hit_event);
        }
        if let Some(threshold) = self.threshold {
            writer.write_tagged_f32("THRS", threshold);
        }
        writer.write_tagged_f32("ELAS", self.elasticity);
        writer.write_tagged_f32("RFCT", self.friction);
        writer.write_tagged_f32("RSCT", self.scatter);
        writer.write_tagged_bool("CLDR", self.is_collidable);
        writer.write_tagged_bool("RVIS", self.is_visible);
        writer.write_tagged_f32("RADB", self.depth_bias);
        writer.write_tagged_f32("RADI", self.wire_diameter);
        writer.write_tagged_f32("RADX", self.wire_distance_x);
        writer.write_tagged_f32("RADY", self.wire_distance_y);
        if let Some(is_reflection_enabled) = self.is_reflection_enabled {
            writer.write_tagged_bool("REEN", is_reflection_enabled);
        }
        if let Some(physics_material) = &self.physics_material {
            writer.write_tagged_string("MAPH", physics_material);
        }
        if let Some(overwrite_physics) = self.overwrite_physics {
            writer.write_tagged_bool("OVPH", overwrite_physics);
        }

        self.write_shared_attributes(writer);

        writer.write_marker_tag("PNTS");
        // many of these
        for point in &self.drag_points {
            writer.write_tagged("DPNT", point)
        }

        writer.close(true);
    }
}

#[cfg(test)]
mod tests {
    use crate::vpx::biff::BiffWriter;

    use super::*;
    use crate::vpx::gameitem::tests::RandomOption;
    use fake::{Fake, Faker};
    use pretty_assertions::assert_eq;
    use rand::RngExt;

    #[test]
    fn test_write_read() {
        let mut rng = rand::rng();
        let ramp = Ramp {
            height_bottom: 1.0,
            height_top: 2.0,
            width_bottom: 3.0,
            width_top: 4.0,
            material: "material".to_string(),
            timer: TimerData {
                is_enabled: rng.random(),
                interval: rng.random(),
            },
            ramp_type: Faker.fake(),
            name: "name".to_string(),
            image: "image".to_string(),
            image_alignment: Faker.fake(),
            image_walls: rng.random(),
            left_wall_height: 8.0,
            right_wall_height: 9.0,
            left_wall_height_visible: 10.0,
            right_wall_height_visible: 11.0,
            hit_event: rng.random_option(),
            threshold: rng.random_option(),
            elasticity: 13.0,
            friction: 14.0,
            scatter: 15.0,
            is_collidable: rng.random(),
            is_visible: rng.random(),
            depth_bias: 16.0,
            wire_diameter: 17.0,
            wire_distance_x: 18.0,
            wire_distance_y: 19.0,
            is_reflection_enabled: rng.random_option(),
            physics_material: Some("physics_material".to_string()),
            overwrite_physics: rng.random_option(),
            drag_points: vec![DragPoint::default()],
            is_locked: true,
            editor_layer: Some(22),
            editor_layer_name: Some("editor_layer_name".to_string()),
            editor_layer_visibility: Some(true),
            part_group_name: Some("part_group_name".to_string()),
        };
        let mut writer = BiffWriter::new();
        Ramp::biff_write(&ramp, &mut writer);
        let ramp_read = Ramp::biff_read(&mut BiffReader::new(writer.get_data()));
        assert_eq!(ramp, ramp_read);
    }

    #[test]
    fn test_ramp_type_json() {
        let sizing_type = RampType::FourWire;
        let json = serde_json::to_string(&sizing_type).unwrap();
        assert_eq!(json, "\"four_wire\"");
        let sizing_type_read: RampType = serde_json::from_str(&json).unwrap();
        assert_eq!(sizing_type, sizing_type_read);
        let json = serde_json::Value::from(0);
        let sizing_type_read: RampType = serde_json::from_value(json).unwrap();
        assert_eq!(RampType::Flat, sizing_type_read);
    }

    #[test]
    #[should_panic = "Error(\"unknown variant `foo`, expected one of `flat`, `four_wire`, `two_wire`, `three_wire_left`, `three_wire_right`, `one_wire`\", line: 0, column: 0)"]
    fn test_shadow_mode_json_fail_string() {
        let json = serde_json::Value::from("foo");
        let _: RampType = serde_json::from_value(json).unwrap();
    }

    #[test]
    fn test_image_alignment_json() {
        let sizing_type = RampImageAlignment::Wrap;
        let json = serde_json::to_string(&sizing_type).unwrap();
        assert_eq!(json, "\"wrap\"");
        let sizing_type_read: RampImageAlignment = serde_json::from_str(&json).unwrap();
        assert_eq!(sizing_type, sizing_type_read);
        let json = serde_json::Value::from(0);
        let sizing_type_read: RampImageAlignment = serde_json::from_value(json).unwrap();
        assert_eq!(RampImageAlignment::World, sizing_type_read);
    }

    #[test]
    #[should_panic = "Error(\"unknown variant `foo`, expected `world` or `wrap`\", line: 0, column: 0)"]
    fn test_image_alignment_json_fail_string() {
        let json = serde_json::Value::from("foo");
        let _: RampImageAlignment = serde_json::from_value(json).unwrap();
    }
}