Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ambiguous syntax for Font properties #731

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Rework patch visualizer with many fixes and improvements ([#726])
* Added support for syncing in `.toml` files ([#633])
* 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
[#674]: https://github.com/rojo-rbx/rojo/pull/674
Expand All @@ -36,6 +37,7 @@
[#726]: https://github.com/rojo-rbx/rojo/pull/726
[#633]: https://github.com/rojo-rbx/rojo/pull/633
[#735]: https://github.com/rojo-rbx/rojo/pull/735
[#731]: https://github.com/rojo-rbx/rojo/pull/731

## [7.3.0] - April 22, 2023
* Added `$attributes` to project format. ([#574])
Expand Down
25 changes: 24 additions & 1 deletion src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -49,6 +49,7 @@ pub enum AmbiguousValue {
Array4([f64; 4]),
Array12([f64; 12]),
Attributes(Attributes),
Font(Font),
}

impl AmbiguousValue {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
}
}
}
Expand Down Expand Up @@ -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,
})
)
}
}