diff --git a/rbx_binary/src/deserializer/state.rs b/rbx_binary/src/deserializer/state.rs index ff428cdc..e4387e17 100644 --- a/rbx_binary/src/deserializer/state.rs +++ b/rbx_binary/src/deserializer/state.rs @@ -401,7 +401,14 @@ impl<'a, R: Read> DeserializerState<'a, R> { for referent in &type_info.referents { let instance = self.instances_by_ref.get_mut(referent).unwrap(); let value = chunk.read_bool()?; - instance.builder.add_property(&canonical_name, value); + if canonical_name == "IgnoreGuiInset" { + instance.builder.add_property( + "ScreenInsets", + Enum::from_u32(if value { 1 } else { 2 }), + ) + } else { + instance.builder.add_property(&canonical_name, value); + } } } invalid_type => { @@ -802,9 +809,18 @@ impl<'a, R: Read> DeserializerState<'a, R> { for (value, referent) in values.into_iter().zip(&type_info.referents) { let instance = self.instances_by_ref.get_mut(referent).unwrap(); - instance - .builder - .add_property(&canonical_name, Enum::from_u32(value)); + if canonical_name == "Font" { + let font_value = Font::from_font_enum(value); + if let Some(font_value) = font_value { + instance.builder.add_property(&canonical_name, font_value); + } else { + log::warn!("Invalid value for Font enum {}, ignoring", value); + } + } else { + instance + .builder + .add_property(&canonical_name, Enum::from_u32(value)); + } } } invalid_type => { diff --git a/rbx_binary/src/serializer/state.rs b/rbx_binary/src/serializer/state.rs index 48a697e9..042cdce5 100644 --- a/rbx_binary/src/serializer/state.rs +++ b/rbx_binary/src/serializer/state.rs @@ -713,8 +713,8 @@ impl<'dom, W: Write> SerializerState<'dom, W> { for (i, rbx_value) in values { if let Variant::Font(value) = rbx_value.as_ref() { chunk.write_string(&value.family)?; - chunk.write_le_u16(value.weight.to_u16())?; - chunk.write_u8(value.style.to_u8())?; + chunk.write_le_u16(value.weight.as_u16())?; + chunk.write_u8(value.style.as_u8())?; chunk.write_string( &value.cached_face_id.clone().unwrap_or_default(), )?; diff --git a/rbx_types/src/font.rs b/rbx_types/src/font.rs index e742b6b2..a391ee92 100644 --- a/rbx_types/src/font.rs +++ b/rbx_types/src/font.rs @@ -33,7 +33,7 @@ impl FontWeight { _ => FontWeight::Regular, } } - pub fn to_u16(self) -> u16 { + pub fn as_u16(self) -> u16 { match self { FontWeight::Thin => 100, FontWeight::ExtraLight => 200, @@ -70,7 +70,7 @@ impl FontStyle { } } - pub fn to_u8(self) -> u8 { + pub fn as_u8(self) -> u8 { match self { FontStyle::Normal => 0, FontStyle::Italic => 1, @@ -102,3 +102,103 @@ impl Default for Font { } } } + +impl Font { + pub fn new(family: &str, weight: FontWeight, style: FontStyle) -> Self { + Self { + family: family.to_owned(), + weight, + style, + cached_face_id: None, + } + } + pub fn regular(family: &str) -> Self { + Self { + family: family.to_owned(), + ..Default::default() + } + } + pub fn from_font_enum(value: u32) -> Option { + return Some(match value { + 0 => Font::regular(&"rbxasset://fonts/families/LegacyArial.json"), + 1 => Font::regular(&"rbxasset://fonts/families/Arial.json"), + 2 => Font::new( + &"rbxasset://fonts/families/Arial.json", + FontWeight::Bold, + FontStyle::Normal, + ), + 3 => Font::regular(&"rbxasset://fonts/families/SourceSansPro.json"), + 4 => Font::new( + &"rbxasset://fonts/families/SourceSansPro.json", + FontWeight::Bold, + FontStyle::Normal, + ), + 16 => Font::new( + &"rbxasset://fonts/families/SourceSansPro.json", + FontWeight::SemiBold, + FontStyle::Normal, + ), + 5 => Font::new( + &"rbxasset://fonts/families/SourceSansPro.json", + FontWeight::Light, + FontStyle::Normal, + ), + 6 => Font::new( + &"rbxasset://fonts/families/SourceSansPro.json", + FontWeight::Regular, + FontStyle::Italic, + ), + 7 => Font::regular(&"rbxasset://fonts/families/AccanthisADFStd.json"), + 8 => Font::regular(&"rbxasset://fonts/families/Guru.json"), + 9 => Font::regular(&"rbxasset://fonts/families/ComicNeueAngular.json"), + 10 => Font::regular(&"rbxasset://fonts/families/Inconsolata.json"), + 11 => Font::regular(&"rbxasset://fonts/families/HighwayGothic.json"), + 12 => Font::regular(&"rbxasset://fonts/families/Zekton.json"), + 13 => Font::regular(&"rbxasset://fonts/families/PressStart2P.json"), + 14 => Font::regular(&"rbxasset://fonts/families/Balthazar.json"), + 15 => Font::regular(&"rbxasset://fonts/families/RomanAntique.json"), + 17 => Font::regular(&"rbxasset://fonts/families/GothamSSm.json"), + 18 => Font::new( + &"rbxasset://fonts/families/GothamSSm.json", + FontWeight::Medium, + FontStyle::Normal, + ), + 19 => Font::new( + &"rbxasset://fonts/families/GothamSSm.json", + FontWeight::Bold, + FontStyle::Normal, + ), + 20 => Font::new( + &"rbxasset://fonts/families/GothamSSm.json", + FontWeight::Heavy, + FontStyle::Normal, + ), + 21 => Font::regular(&"rbxasset://fonts/families/AmaticSC.json"), + 22 => Font::regular(&"rbxasset://fonts/families/Bangers.json"), + 23 => Font::regular(&"rbxasset://fonts/families/Creepster.json"), + 24 => Font::regular(&"rbxasset://fonts/families/DenkOne.json"), + 25 => Font::regular(&"rbxasset://fonts/families/Fondamento.json"), + 26 => Font::regular(&"rbxasset://fonts/families/FredokaOne.json"), + 27 => Font::regular(&"rbxasset://fonts/families/GrenzeGotisch.json"), + 28 => Font::regular(&"rbxasset://fonts/families/IndieFlower.json"), + 29 => Font::regular(&"rbxasset://fonts/families/JosefinSans.json"), + 30 => Font::regular(&"rbxasset://fonts/families/Jura.json"), + 31 => Font::regular(&"rbxasset://fonts/families/Kalam.json"), + 32 => Font::regular(&"rbxasset://fonts/families/LuckiestGuy.json"), + 33 => Font::regular(&"rbxasset://fonts/families/Merriweather.json"), + 34 => Font::regular(&"rbxasset://fonts/families/Michroma.json"), + 35 => Font::regular(&"rbxasset://fonts/families/Nunito.json"), + 36 => Font::regular(&"rbxasset://fonts/families/Oswald.json"), + 37 => Font::regular(&"rbxasset://fonts/families/PatrickHand.json"), + 38 => Font::regular(&"rbxasset://fonts/families/PermanentMarker.json"), + 39 => Font::regular(&"rbxasset://fonts/families/Roboto.json"), + 40 => Font::regular(&"rbxasset://fonts/families/RobotoCondensed.json"), + 41 => Font::regular(&"rbxasset://fonts/families/RobotoMono.json"), + 42 => Font::regular(&"rbxasset://fonts/families/Sarpanch.json"), + 43 => Font::regular(&"rbxasset://fonts/families/SpecialElite.json"), + 44 => Font::regular(&"rbxasset://fonts/families/TitilliumWeb.json"), + 45 => Font::regular(&"rbxasset://fonts/families/Ubuntu.json"), + _ => return None, + }); + } +} diff --git a/rbx_xml/src/deserializer.rs b/rbx_xml/src/deserializer.rs index 61f849a6..9883c5af 100644 --- a/rbx_xml/src/deserializer.rs +++ b/rbx_xml/src/deserializer.rs @@ -5,7 +5,7 @@ use std::{ use log::trace; use rbx_dom_weak::{ - types::{Ref, SharedString, Variant, VariantType}, + types::{Enum, Font, Ref, SharedString, Variant, VariantType}, InstanceBuilder, WeakDom, }; use rbx_reflection::DataType; @@ -607,7 +607,31 @@ fn deserialize_properties( } }; - props.insert(descriptor.name.to_string(), value); + match descriptor.name.as_ref() { + "Font" => match value { + Variant::Enum(value) => match Font::from_font_enum(value.to_u32()) { + Some(value) => { + props.insert(descriptor.name.to_string(), value.into()); + } + None => { + log::warn!("Invalid value for Font enum {}, ignoring", value.to_u32()) + } + }, + _ => log::warn!("Invalid type for Font enum {:?}, ignoring", value), + }, + "IgnoreGuiInset" => match value { + Variant::Bool(value) => { + props.insert( + "ScreenInsets".to_string(), + Enum::from_u32(if value { 1 } else { 2 }).into(), + ); + } + _ => log::warn!("Invalid type for IgnoreGuiInset bool {:?}, ignoring", value), + }, + _ => { + props.insert(descriptor.name.to_string(), value); + } + }; } else { match state.options.property_behavior { DecodePropertyBehavior::IgnoreUnknown => { diff --git a/rbx_xml/src/types/font.rs b/rbx_xml/src/types/font.rs index d8e28e1b..ba2f3c35 100644 --- a/rbx_xml/src/types/font.rs +++ b/rbx_xml/src/types/font.rs @@ -88,7 +88,7 @@ impl XmlType for Font { fn write_xml(&self, writer: &mut XmlEventWriter) -> Result<(), EncodeError> { write_content(writer, &self.family, "Family")?; - writer.write_value_in_tag(&self.weight.to_u16(), "Weight")?; + writer.write_value_in_tag(&self.weight.as_u16(), "Weight")?; let style = match self.style { FontStyle::Normal => "Normal",