revert unresolved value patches

This commit is contained in:
Joe 2026-01-22 19:51:44 -06:00
parent fd47b8d3b1
commit 074e62951f
4 changed files with 47 additions and 100 deletions

View file

@ -40,14 +40,12 @@ impl UnresolvedValue {
/// Creates an `UnresolvedValue` from a variant, using a class and property /// Creates an `UnresolvedValue` from a variant, using a class and property
/// name to potentially allow for ambiguous Enum variants. /// 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<Self> {
let descriptor = find_descriptor(class_name, prop_name); let descriptor = find_descriptor(class_name, prop_name);
if descriptor.is_some() { if descriptor.is_some() {
// We can only use an ambiguous syntax if the property is known // We can only use an ambiguous syntax if the property is known
// to the reflection database. // to the reflection database.
Some(Self::Ambiguous(match variant { Self::Ambiguous(match variant {
Variant::Enum(rbx_enum) => { Variant::Enum(rbx_enum) => {
if let Some(property) = descriptor { if let Some(property) = descriptor {
if let DataType::Enum(enum_name) = &property.data_type { if let DataType::Enum(enum_name) = &property.data_type {
@ -55,15 +53,15 @@ impl UnresolvedValue {
if let Some(enum_descriptor) = database.enums.get(enum_name) { if let Some(enum_descriptor) = database.enums.get(enum_name) {
for (variant_name, id) in &enum_descriptor.items { for (variant_name, id) in &enum_descriptor.items {
if *id == rbx_enum.to_u32() { if *id == rbx_enum.to_u32() {
return Some(Self::Ambiguous(AmbiguousValue::String( return Self::Ambiguous(AmbiguousValue::String(
variant_name.to_string(), variant_name.to_string(),
))); ));
} }
} }
} }
} }
} }
return Some(Self::FullyQualified(variant)); return Self::FullyQualified(variant);
} }
Variant::Bool(bool) => AmbiguousValue::Bool(bool), Variant::Bool(bool) => AmbiguousValue::Bool(bool),
Variant::Float32(n) => AmbiguousValue::Number(n as f64), Variant::Float32(n) => AmbiguousValue::Number(n as f64),
@ -77,7 +75,7 @@ impl UnresolvedValue {
Variant::Content(ref content) => match content.value() { Variant::Content(ref content) => match content.value() {
ContentType::None => AmbiguousValue::String(String::new()), ContentType::None => AmbiguousValue::String(String::new()),
ContentType::Uri(uri) => AmbiguousValue::String(uri.clone()), ContentType::Uri(uri) => AmbiguousValue::String(uri.clone()),
_ => return Some(Self::FullyQualified(variant)), _ => return Self::FullyQualified(variant),
}, },
Variant::ContentId(content) => AmbiguousValue::String(content.into_string()), Variant::ContentId(content) => AmbiguousValue::String(content.into_string()),
Variant::Vector2(vector) => { Variant::Vector2(vector) => {
@ -89,42 +87,7 @@ impl UnresolvedValue {
Variant::Color3(color) => { Variant::Color3(color) => {
AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64]) AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64])
} }
Variant::CFrame(cf) => { Variant::CFrame(cf) => AmbiguousValue::Array12([
if Self::cframe_is_nan(&cf) {
return None;
}
Self::cframe_to_array12(cf)
}
Variant::OptionalCFrame(maybe_cf) => match maybe_cf {
Some(cf) => {
if Self::cframe_is_nan(&cf) {
return None;
}
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 Some(Self::FullyQualified(variant));
}
}))
} else {
// Skip OptionalCFrame(None) and CFrames with NaN values to avoid serializing null arrays
match &variant {
Variant::OptionalCFrame(None) => return None,
Variant::OptionalCFrame(Some(cf)) if Self::cframe_is_nan(cf) => return None,
Variant::CFrame(cf) if Self::cframe_is_nan(cf) => return None,
_ => {}
}
Some(Self::FullyQualified(variant))
}
}
fn cframe_to_array12(cf: CFrame) -> AmbiguousValue {
AmbiguousValue::Array12([
cf.position.x as f64, cf.position.x as f64,
cf.position.y as f64, cf.position.y as f64,
cf.position.z as f64, cf.position.z as f64,
@ -137,22 +100,17 @@ impl UnresolvedValue {
cf.orientation.z.x as f64, cf.orientation.z.x as f64,
cf.orientation.z.y as f64, cf.orientation.z.y as f64,
cf.orientation.z.z as f64, cf.orientation.z.z as f64,
]) ]),
Variant::Attributes(attr) => AmbiguousValue::Attributes(attr),
Variant::Font(font) => AmbiguousValue::Font(font),
Variant::MaterialColors(colors) => AmbiguousValue::MaterialColors(colors),
_ => {
return Self::FullyQualified(variant);
}
})
} else {
Self::FullyQualified(variant)
} }
fn cframe_is_nan(cf: &CFrame) -> bool {
cf.position.x.is_nan()
|| cf.position.y.is_nan()
|| cf.position.z.is_nan()
|| cf.orientation.x.x.is_nan()
|| cf.orientation.x.y.is_nan()
|| cf.orientation.x.z.is_nan()
|| cf.orientation.y.x.is_nan()
|| cf.orientation.y.y.is_nan()
|| cf.orientation.y.z.is_nan()
|| cf.orientation.z.x.is_nan()
|| cf.orientation.z.y.is_nan()
|| cf.orientation.z.z.is_nan()
} }
/// Creates an `UnresolvedValue` from a variant, only returning ambiguous /// Creates an `UnresolvedValue` from a variant, only returning ambiguous
@ -267,11 +225,15 @@ impl AmbiguousValue {
} }
(VariantType::CFrame, AmbiguousValue::Array12(value)) => { (VariantType::CFrame, AmbiguousValue::Array12(value)) => {
Ok(Self::array12_to_cframe(value).into()) let value = value.map(|v| v as f32);
} let pos = Vector3::new(value[0], value[1], value[2]);
let orientation = Matrix3::new(
Vector3::new(value[3], value[4], value[5]),
Vector3::new(value[6], value[7], value[8]),
Vector3::new(value[9], value[10], value[11]),
);
(VariantType::OptionalCFrame, AmbiguousValue::Array12(value)) => { Ok(CFrame::new(pos, orientation).into())
Ok(Variant::OptionalCFrame(Some(Self::array12_to_cframe(value))))
} }
(VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()), (VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()),
@ -312,17 +274,6 @@ impl AmbiguousValue {
} }
} }
fn array12_to_cframe(value: [f64; 12]) -> CFrame {
let value = value.map(|v| v as f32);
let pos = Vector3::new(value[0], value[1], value[2]);
let orientation = Matrix3::new(
Vector3::new(value[3], value[4], value[5]),
Vector3::new(value[6], value[7], value[8]),
Vector3::new(value[9], value[10], value[11]),
);
CFrame::new(pos, orientation)
}
fn describe(&self) -> &'static str { fn describe(&self) -> &'static str {
match self { match self {
AmbiguousValue::Bool(_) => "a bool", AmbiguousValue::Bool(_) => "a bool",

View file

@ -123,11 +123,10 @@ fn json_model_from_pair<'sync>(
} }
} }
_ => { _ => {
if let Some(resolved) = properties.insert(
UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name) name,
{ UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name),
properties.insert(name, resolved); );
}
} }
} }
} }

View file

@ -147,11 +147,10 @@ impl AdjacentMetadata {
} }
} }
_ => { _ => {
if let Some(resolved) = properties.insert(
UnresolvedValue::from_variant(value.clone(), class, &name) name,
{ UnresolvedValue::from_variant(value.clone(), class, &name),
properties.insert(name, resolved); );
}
} }
} }
} }
@ -376,11 +375,10 @@ impl DirectoryMetadata {
} }
} }
_ => { _ => {
if let Some(resolved) = properties.insert(
UnresolvedValue::from_variant(value.clone(), class, &name) name,
{ UnresolvedValue::from_variant(value.clone(), class, &name),
properties.insert(name, resolved); );
}
} }
} }
} }

View file

@ -573,11 +573,10 @@ fn project_node_property_syncback(
} }
} }
_ => { _ => {
if let Some(resolved) = properties.insert(
UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name) name,
{ UnresolvedValue::from_variant(value.clone(), &new_inst.class, &name),
properties.insert(name, resolved); );
}
} }
} }
} }