Support ambiguous syntax for Font properties (#731)

This commit is contained in:
Micah
2023-07-20 21:30:18 -07:00
committed by GitHub
parent 94d45a2262
commit 89b6666436
2 changed files with 26 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ use std::borrow::Borrow;
use anyhow::{bail, format_err};
use rbx_dom_weak::types::{
Attributes, CFrame, Color3, Content, Enum, Matrix3, Tags, Variant, VariantType, Vector2,
Attributes, CFrame, Color3, Content, Enum, Font, Matrix3, Tags, Variant, VariantType, Vector2,
Vector3,
};
use rbx_reflection::{DataType, PropertyDescriptor};
@@ -49,6 +49,7 @@ pub enum AmbiguousValue {
Array4([f64; 4]),
Array12([f64; 12]),
Attributes(Attributes),
Font(Font),
}
impl AmbiguousValue {
@@ -139,6 +140,8 @@ impl AmbiguousValue {
(VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()),
(VariantType::Font, AmbiguousValue::Font(value)) => Ok(value.into()),
(_, unresolved) => Err(format_err!(
"Wrong type of value for property {}.{}. Expected {:?}, got {}",
class_name,
@@ -176,6 +179,7 @@ impl AmbiguousValue {
AmbiguousValue::Array4(_) => "an array of four numbers",
AmbiguousValue::Array12(_) => "an array of twelve numbers",
AmbiguousValue::Attributes(_) => "an object containing attributes",
AmbiguousValue::Font(_) => "an object describing a Font",
}
}
}
@@ -328,4 +332,23 @@ mod test {
Variant::Enum(Enum::from_u32(1)),
);
}
#[test]
fn font() {
use rbx_dom_weak::types::{FontStyle, FontWeight};
assert_eq!(
resolve(
"TextLabel",
"FontFace",
r#"{"family": "rbxasset://fonts/families/RobotoMono.json", "weight": "Thin", "style": "Normal"}"#
),
Variant::Font(Font {
family: "rbxasset://fonts/families/RobotoMono.json".into(),
weight: FontWeight::Thin,
style: FontStyle::Normal,
cached_face_id: None,
})
)
}
}