Refactor AmbiguousValue handling for CFrame conversion

- Introduced a new method `array12_to_cframe` to streamline the conversion of Array12 values to CFrame, improving code clarity and reducing redundancy.
- Updated handling for both CFrame and OptionalCFrame variants to utilize the new conversion method, enhancing maintainability and consistency in value processing.
This commit is contained in:
Joe 2026-01-21 16:13:46 -06:00
parent 69774fd546
commit bf1d872f13

View file

@ -235,15 +235,11 @@ impl AmbiguousValue {
}
(VariantType::CFrame, AmbiguousValue::Array12(value)) => {
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]),
);
Ok(Self::array12_to_cframe(value).into())
}
Ok(CFrame::new(pos, orientation).into())
(VariantType::OptionalCFrame, AmbiguousValue::Array12(value)) => {
Ok(Variant::OptionalCFrame(Some(Self::array12_to_cframe(value))))
}
(VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()),
@ -284,6 +280,17 @@ 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 {
match self {
AmbiguousValue::Bool(_) => "a bool",