From 69774fd546282a086f8716076733e04a0f4b92f3 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 21 Jan 2026 16:07:24 -0600 Subject: [PATCH] Update .gitmodules for rbx-dom URL and enhance UnresolvedValue handling - Changed the rbx-dom submodule URL in .gitmodules from SSH to HTTPS for easier access. - Introduced a new method to handle OptionalCFrame variants in UnresolvedValue, allowing for better serialization by returning `None` for `OptionalCFrame(None)`. - Updated various files to utilize the new handling logic, ensuring properties are only inserted when resolved values are available. --- .gitmodules | 2 +- rbx-dom | 1 + src/resolution.rs | 56 ++++++++++++++++----------- src/snapshot_middleware/json_model.rs | 9 +++-- src/snapshot_middleware/meta_file.rs | 18 +++++---- src/snapshot_middleware/project.rs | 9 +++-- 6 files changed, 55 insertions(+), 40 deletions(-) create mode 160000 rbx-dom diff --git a/.gitmodules b/.gitmodules index 18faf39c..5443ec2f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,4 +18,4 @@ url = https://github.com/boatbomber/highlighter.git [submodule "rbx-dom"] path = rbx-dom - url = git@github.com:UserGeneratedLLC/rbx-dom.git + url = https://github.com/UserGeneratedLLC/rbx-dom.git diff --git a/rbx-dom b/rbx-dom new file mode 160000 index 00000000..7ef7d448 --- /dev/null +++ b/rbx-dom @@ -0,0 +1 @@ +Subproject commit 7ef7d448ba6d30c4cb217b228d5c22c6f5ac07f3 diff --git a/src/resolution.rs b/src/resolution.rs index fe657934..59fcb592 100644 --- a/src/resolution.rs +++ b/src/resolution.rs @@ -40,12 +40,14 @@ impl UnresolvedValue { /// Creates an `UnresolvedValue` from a variant, using a class and property /// name to potentially allow for ambiguous Enum variants. - pub fn from_variant(variant: Variant, class_name: &str, prop_name: &str) -> Self { + /// + /// Returns `None` for variants that should not be serialized (e.g., `OptionalCFrame(None)`). + pub fn from_variant(variant: Variant, class_name: &str, prop_name: &str) -> Option { let descriptor = find_descriptor(class_name, prop_name); if descriptor.is_some() { // We can only use an ambiguous syntax if the property is known // to the reflection database. - Self::Ambiguous(match variant { + Some(Self::Ambiguous(match variant { Variant::Enum(rbx_enum) => { if let Some(property) = descriptor { if let DataType::Enum(enum_name) = &property.data_type { @@ -53,15 +55,15 @@ impl UnresolvedValue { if let Some(enum_descriptor) = database.enums.get(enum_name) { for (variant_name, id) in &enum_descriptor.items { if *id == rbx_enum.to_u32() { - return Self::Ambiguous(AmbiguousValue::String( + return Some(Self::Ambiguous(AmbiguousValue::String( variant_name.to_string(), - )); + ))); } } } } } - return Self::FullyQualified(variant); + return Some(Self::FullyQualified(variant)); } Variant::Bool(bool) => AmbiguousValue::Bool(bool), Variant::Float32(n) => AmbiguousValue::Number(n as f64), @@ -75,7 +77,7 @@ impl UnresolvedValue { Variant::Content(ref content) => match content.value() { ContentType::None => AmbiguousValue::String(String::new()), ContentType::Uri(uri) => AmbiguousValue::String(uri.clone()), - _ => return Self::FullyQualified(variant), + _ => return Some(Self::FullyQualified(variant)), }, Variant::ContentId(content) => AmbiguousValue::String(content.into_string()), Variant::Vector2(vector) => { @@ -87,32 +89,40 @@ impl UnresolvedValue { Variant::Color3(color) => { AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64]) } - Variant::CFrame(cf) => AmbiguousValue::Array12([ - cf.position.x as f64, - cf.position.y as f64, - cf.position.z as f64, - cf.orientation.x.x as f64, - cf.orientation.x.y as f64, - cf.orientation.x.z as f64, - cf.orientation.y.x as f64, - cf.orientation.y.y as f64, - cf.orientation.y.z as f64, - cf.orientation.z.x as f64, - cf.orientation.z.y as f64, - cf.orientation.z.z as f64, - ]), + Variant::CFrame(cf) => Self::cframe_to_array12(cf), + Variant::OptionalCFrame(maybe_cf) => match maybe_cf { + Some(cf) => Self::cframe_to_array12(cf), + None => return None, + }, Variant::Attributes(attr) => AmbiguousValue::Attributes(attr), Variant::Font(font) => AmbiguousValue::Font(font), Variant::MaterialColors(colors) => AmbiguousValue::MaterialColors(colors), _ => { - return Self::FullyQualified(variant); + return Some(Self::FullyQualified(variant)); } - }) + })) } else { - Self::FullyQualified(variant) + Some(Self::FullyQualified(variant)) } } + fn cframe_to_array12(cf: CFrame) -> AmbiguousValue { + AmbiguousValue::Array12([ + cf.position.x as f64, + cf.position.y as f64, + cf.position.z as f64, + cf.orientation.x.x as f64, + cf.orientation.x.y as f64, + cf.orientation.x.z as f64, + cf.orientation.y.x as f64, + cf.orientation.y.y as f64, + cf.orientation.y.z as f64, + cf.orientation.z.x as f64, + cf.orientation.z.y as f64, + cf.orientation.z.z as f64, + ]) + } + /// Creates an `UnresolvedValue` from a variant, only returning ambiguous /// values if they're able to be resolved in a context-free environment. pub fn from_variant_unambiguous(variant: Variant) -> Self { diff --git a/src/snapshot_middleware/json_model.rs b/src/snapshot_middleware/json_model.rs index 7ec2b8a0..cdf6b608 100644 --- a/src/snapshot_middleware/json_model.rs +++ b/src/snapshot_middleware/json_model.rs @@ -123,10 +123,11 @@ fn json_model_from_pair<'sync>( } } _ => { - properties.insert( - name, - UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name), - ); + if let Some(resolved) = + UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name) + { + properties.insert(name, resolved); + } } } } diff --git a/src/snapshot_middleware/meta_file.rs b/src/snapshot_middleware/meta_file.rs index 9ca115b2..b2b502a1 100644 --- a/src/snapshot_middleware/meta_file.rs +++ b/src/snapshot_middleware/meta_file.rs @@ -147,10 +147,11 @@ impl AdjacentMetadata { } } _ => { - properties.insert( - name, - UnresolvedValue::from_variant(value.clone(), class, &name), - ); + if let Some(resolved) = + UnresolvedValue::from_variant(value.clone(), class, &name) + { + properties.insert(name, resolved); + } } } } @@ -375,10 +376,11 @@ impl DirectoryMetadata { } } _ => { - properties.insert( - name, - UnresolvedValue::from_variant(value.clone(), class, &name), - ); + if let Some(resolved) = + UnresolvedValue::from_variant(value.clone(), class, &name) + { + properties.insert(name, resolved); + } } } } diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index 90d743a7..10a1288b 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -573,10 +573,11 @@ fn project_node_property_syncback( } } _ => { - properties.insert( - name, - UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name), - ); + if let Some(resolved) = + UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name) + { + properties.insert(name, resolved); + } } } }