mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
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:
parent
69774fd546
commit
bf1d872f13
1 changed files with 15 additions and 8 deletions
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue