From b807f7e93bd486ce7e258170439c8012ca1b88e6 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 14 Mar 2024 01:28:31 -0400 Subject: [PATCH] Flatten StructPropertyValue.value field --- src/properties/struct_property.rs | 1 + tests/common/regression.rs | 4 +- tests/common/vector2d.rs | 186 +++++++++++------------ tests/serde_tests/serde_json_template.rs | 150 ++++++++---------- 4 files changed, 152 insertions(+), 189 deletions(-) diff --git a/src/properties/struct_property.rs b/src/properties/struct_property.rs index f3b3b1f..a668f2b 100644 --- a/src/properties/struct_property.rs +++ b/src/properties/struct_property.rs @@ -43,6 +43,7 @@ pub struct StructProperty { #[cfg_attr(feature = "serde", serde(default))] pub guid: Guid, /// The value of the property. + #[cfg_attr(feature = "serde", serde(flatten))] pub value: StructPropertyValue, } diff --git a/tests/common/regression.rs b/tests/common/regression.rs index 2e1b29b..1f94031 100644 --- a/tests/common/regression.rs +++ b/tests/common/regression.rs @@ -62,9 +62,7 @@ pub const REGRESSION_01_JSON: &str = r#"{ "properties": { "Thing": { "type": "StructProperty", - "value": { - "Guid": "D49982B3-DF3D-D549-B4AE-57C71D5838E4" - } + "Guid": "D49982B3-DF3D-D549-B4AE-57C71D5838E4" } } }"#; diff --git a/tests/common/vector2d.rs b/tests/common/vector2d.rs index 55e705b..5801167 100644 --- a/tests/common/vector2d.rs +++ b/tests/common/vector2d.rs @@ -1214,112 +1214,106 @@ pub const VECTOR2D_JSON: &str = r#"{ }, "AudioSettings": { "type": "StructProperty", - "value": { - "CustomStruct": [ - "GameAudioSettings", + "CustomStruct": [ + "GameAudioSettings", + [ [ - [ - "MasterLevel", - { - "type": "FloatProperty", - "value": 0.20348908 - } - ], - [ - "MusicLevel", - { - "type": "FloatProperty", - "value": 0.1511635 - } - ], - [ - "SFXLevel", - { - "type": "FloatProperty", - "value": 0.5436054 - } - ] + "MasterLevel", + { + "type": "FloatProperty", + "value": 0.20348908 + } + ], + [ + "MusicLevel", + { + "type": "FloatProperty", + "value": 0.1511635 + } + ], + [ + "SFXLevel", + { + "type": "FloatProperty", + "value": 0.5436054 + } ] ] - } + ] }, "GameSettings": { "type": "StructProperty", - "value": { - "CustomStruct": [ - "GameSettings", + "CustomStruct": [ + "GameSettings", + [ [ - [ - "CurrentSaveSlot", - { - "type": "StrProperty", - "value": "SAVE2" - } - ], - [ - "LoadTutorial", - { - "type": "BoolProperty", - "value": false - } - ], - [ - "DisplayNewOrders", - { - "type": "BoolProperty", - "value": false - } - ], - [ - "EscapeExitsTool", - { - "type": "BoolProperty", - "value": false - } - ], - [ - "UseDarkMode", - { - "type": "BoolProperty", - "value": true - } - ], - [ - "AnimateDayCycle", - { - "type": "BoolProperty", - "value": false - } - ], - [ - "EnableTractorCollision", - { - "type": "BoolProperty", - "value": false - } - ], - [ - "ShowInventory", - { - "type": "BoolProperty", - "value": true - } - ], - [ - "CameraAngle", - { - "type": "StructProperty", - "value": { - "Vector2D": { - "x": 30.574748247861862, - "y": 60.42525175213814 - } - } + "CurrentSaveSlot", + { + "type": "StrProperty", + "value": "SAVE2" + } + ], + [ + "LoadTutorial", + { + "type": "BoolProperty", + "value": false + } + ], + [ + "DisplayNewOrders", + { + "type": "BoolProperty", + "value": false + } + ], + [ + "EscapeExitsTool", + { + "type": "BoolProperty", + "value": false + } + ], + [ + "UseDarkMode", + { + "type": "BoolProperty", + "value": true + } + ], + [ + "AnimateDayCycle", + { + "type": "BoolProperty", + "value": false + } + ], + [ + "EnableTractorCollision", + { + "type": "BoolProperty", + "value": false + } + ], + [ + "ShowInventory", + { + "type": "BoolProperty", + "value": true + } + ], + [ + "CameraAngle", + { + "type": "StructProperty", + "Vector2D": { + "x": 30.574748247861862, + "y": 60.42525175213814 } - ] + } ] ] - } + ] }, "HighScore": { "type": "IntProperty", diff --git a/tests/serde_tests/serde_json_template.rs b/tests/serde_tests/serde_json_template.rs index 114ab89..9f5c646 100644 --- a/tests/serde_tests/serde_json_template.rs +++ b/tests/serde_tests/serde_json_template.rs @@ -660,17 +660,13 @@ fn array_struct() { "structs": [ { "guid": "22222222-2222-2222-2222-222222222222", - "value": { - "DateTime": { - "ticks": 0 - } + "DateTime": { + "ticks": 0 } }, { - "value": { - "DateTime": { - "ticks": 1 - } + "DateTime": { + "ticks": 1 } } ] @@ -1158,12 +1154,10 @@ fn map_struct_float() { [ { "type": "StructProperty", - "value": { - "VectorF": { - "x": 0.0, - "y": 1.0, - "z": 2.0 - } + "VectorF": { + "x": 0.0, + "y": 1.0, + "z": 2.0 } }, { @@ -1175,10 +1169,8 @@ fn map_struct_float() { { "type": "StructProperty", "guid": "11111111-1111-1111-1111-111111111111", - "value": { - "Timespan": { - "ticks": 0 - } + "Timespan": { + "ticks": 0 } }, { @@ -1190,10 +1182,8 @@ fn map_struct_float() { { "type": "StructProperty", "guid": "22222222-2222-2222-2222-222222222222", - "value": { - "DateTime": { - "ticks": 0 - } + "DateTime": { + "ticks": 0 } }, { @@ -1439,12 +1429,10 @@ fn struct_vectorf() { )), r#"{ "type": "StructProperty", - "value": { - "VectorF": { - "x": 0.0, - "y": 1.0, - "z": 2.0 - } + "VectorF": { + "x": 0.0, + "y": 1.0, + "z": 2.0 } }"#, ) @@ -1459,12 +1447,10 @@ fn struct_vectord() { )), r#"{ "type": "StructProperty", - "value": { - "VectorD": { - "x": 0.0, - "y": 1.0, - "z": 2.0 - } + "VectorD": { + "x": 0.0, + "y": 1.0, + "z": 2.0 } }"#, ) @@ -1479,12 +1465,10 @@ fn struct_rotatorf() { )), r#"{ "type": "StructProperty", - "value": { - "RotatorF": { - "pitch": 0.0, - "yaw": 1.0, - "roll": 2.0 - } + "RotatorF": { + "pitch": 0.0, + "yaw": 1.0, + "roll": 2.0 } }"#, ) @@ -1499,12 +1483,10 @@ fn struct_rotatord() { )), r#"{ "type": "StructProperty", - "value": { - "RotatorD": { - "pitch": 0.0, - "yaw": 1.0, - "roll": 2.0 - } + "RotatorD": { + "pitch": 0.0, + "yaw": 1.0, + "roll": 2.0 } }"#, ) @@ -1519,13 +1501,11 @@ fn struct_quatf() { )), r#"{ "type": "StructProperty", - "value": { - "QuatF": { - "x": 0.0, - "y": 1.0, - "z": 2.0, - "w": 3.0 - } + "QuatF": { + "x": 0.0, + "y": 1.0, + "z": 2.0, + "w": 3.0 } }"#, ) @@ -1540,13 +1520,11 @@ fn struct_quatd() { )), r#"{ "type": "StructProperty", - "value": { - "QuatD": { - "x": 0.0, - "y": 1.0, - "z": 2.0, - "w": 3.0 - } + "QuatD": { + "x": 0.0, + "y": 1.0, + "z": 2.0, + "w": 3.0 } }"#, ) @@ -1561,13 +1539,11 @@ fn struct_datetime() { )), r#"{ "type": "StructProperty", - "value": { - "QuatD": { - "x": 0.0, - "y": 1.0, - "z": 2.0, - "w": 3.0 - } + "QuatD": { + "x": 0.0, + "y": 1.0, + "z": 2.0, + "w": 3.0 } }"#, ) @@ -1582,13 +1558,11 @@ fn struct_linearcolor() { )), r#"{ "type": "StructProperty", - "value": { - "LinearColor": { - "r": 0.0, - "g": 1.0, - "b": 2.0, - "a": 3.0 - } + "LinearColor": { + "r": 0.0, + "g": 1.0, + "b": 2.0, + "a": 3.0 } }"#, ) @@ -1603,11 +1577,9 @@ fn struct_intpoint() { )), r#"{ "type": "StructProperty", - "value": { - "IntPoint": { - "x": 0, - "y": 1 - } + "IntPoint": { + "x": 0, + "y": 1 } }"#, ) @@ -1628,20 +1600,18 @@ fn struct_custom() { )), r#"{ "type": "StructProperty", - "value": { - "CustomStruct": [ - "custom name", + "CustomStruct": [ + "custom name", + [ [ - [ - "key", - { - "type": "StrProperty", - "value": "value" - } - ] + "key", + { + "type": "StrProperty", + "value": "value" + } ] ] - } + ] }"#, ) }