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

@@ -18,6 +18,7 @@
* Rework patch visualizer with many fixes and improvements ([#726]) * Rework patch visualizer with many fixes and improvements ([#726])
* Added support for syncing in `.toml` files ([#633]) * Added support for syncing in `.toml` files ([#633])
* Add `plugin` flag to the `build` command that outputs to the local plugins folder ([#735]) * Add `plugin` flag to the `build` command that outputs to the local plugins folder ([#735])
* Added better support for `Font` properties ([#731])
[#668]: https://github.com/rojo-rbx/rojo/pull/668 [#668]: https://github.com/rojo-rbx/rojo/pull/668
[#674]: https://github.com/rojo-rbx/rojo/pull/674 [#674]: https://github.com/rojo-rbx/rojo/pull/674
@@ -36,6 +37,7 @@
[#726]: https://github.com/rojo-rbx/rojo/pull/726 [#726]: https://github.com/rojo-rbx/rojo/pull/726
[#633]: https://github.com/rojo-rbx/rojo/pull/633 [#633]: https://github.com/rojo-rbx/rojo/pull/633
[#735]: https://github.com/rojo-rbx/rojo/pull/735 [#735]: https://github.com/rojo-rbx/rojo/pull/735
[#731]: https://github.com/rojo-rbx/rojo/pull/731
## [7.3.0] - April 22, 2023 ## [7.3.0] - April 22, 2023
* Added `$attributes` to project format. ([#574]) * Added `$attributes` to project format. ([#574])

View File

@@ -2,7 +2,7 @@ use std::borrow::Borrow;
use anyhow::{bail, format_err}; use anyhow::{bail, format_err};
use rbx_dom_weak::types::{ 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, Vector3,
}; };
use rbx_reflection::{DataType, PropertyDescriptor}; use rbx_reflection::{DataType, PropertyDescriptor};
@@ -49,6 +49,7 @@ pub enum AmbiguousValue {
Array4([f64; 4]), Array4([f64; 4]),
Array12([f64; 12]), Array12([f64; 12]),
Attributes(Attributes), Attributes(Attributes),
Font(Font),
} }
impl AmbiguousValue { impl AmbiguousValue {
@@ -139,6 +140,8 @@ impl AmbiguousValue {
(VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()), (VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()),
(VariantType::Font, AmbiguousValue::Font(value)) => Ok(value.into()),
(_, unresolved) => Err(format_err!( (_, unresolved) => Err(format_err!(
"Wrong type of value for property {}.{}. Expected {:?}, got {}", "Wrong type of value for property {}.{}. Expected {:?}, got {}",
class_name, class_name,
@@ -176,6 +179,7 @@ impl AmbiguousValue {
AmbiguousValue::Array4(_) => "an array of four numbers", AmbiguousValue::Array4(_) => "an array of four numbers",
AmbiguousValue::Array12(_) => "an array of twelve numbers", AmbiguousValue::Array12(_) => "an array of twelve numbers",
AmbiguousValue::Attributes(_) => "an object containing attributes", 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)), 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,
})
)
}
} }