Skip to content

Commit 735af5c

Browse files
setCorecii
authored andcommitted
to_x -> as_x
1 parent bf6b91e commit 735af5c

File tree

5 files changed

+151
-11
lines changed

5 files changed

+151
-11
lines changed

rbx_binary/src/deserializer/state.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,14 @@ impl<'a, R: Read> DeserializerState<'a, R> {
401401
for referent in &type_info.referents {
402402
let instance = self.instances_by_ref.get_mut(referent).unwrap();
403403
let value = chunk.read_bool()?;
404-
instance.builder.add_property(&canonical_name, value);
404+
if canonical_name == "IgnoreGuiInset" {
405+
instance.builder.add_property(
406+
"ScreenInsets",
407+
Enum::from_u32(if value { 1 } else { 2 }),
408+
)
409+
} else {
410+
instance.builder.add_property(&canonical_name, value);
411+
}
405412
}
406413
}
407414
invalid_type => {
@@ -802,9 +809,18 @@ impl<'a, R: Read> DeserializerState<'a, R> {
802809

803810
for (value, referent) in values.into_iter().zip(&type_info.referents) {
804811
let instance = self.instances_by_ref.get_mut(referent).unwrap();
805-
instance
806-
.builder
807-
.add_property(&canonical_name, Enum::from_u32(value));
812+
if canonical_name == "Font" {
813+
let font_value = Font::from_font_enum(value);
814+
if let Some(font_value) = font_value {
815+
instance.builder.add_property(&canonical_name, font_value);
816+
} else {
817+
log::warn!("Invalid value for Font enum {}, ignoring", value);
818+
}
819+
} else {
820+
instance
821+
.builder
822+
.add_property(&canonical_name, Enum::from_u32(value));
823+
}
808824
}
809825
}
810826
invalid_type => {

rbx_binary/src/serializer/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@ impl<'dom, W: Write> SerializerState<'dom, W> {
713713
for (i, rbx_value) in values {
714714
if let Variant::Font(value) = rbx_value.as_ref() {
715715
chunk.write_string(&value.family)?;
716-
chunk.write_le_u16(value.weight.to_u16())?;
717-
chunk.write_u8(value.style.to_u8())?;
716+
chunk.write_le_u16(value.weight.as_u16())?;
717+
chunk.write_u8(value.style.as_u8())?;
718718
chunk.write_string(
719719
&value.cached_face_id.clone().unwrap_or_default(),
720720
)?;

rbx_types/src/font.rs

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl FontWeight {
3333
_ => FontWeight::Regular,
3434
}
3535
}
36-
pub fn to_u16(self) -> u16 {
36+
pub fn as_u16(self) -> u16 {
3737
match self {
3838
FontWeight::Thin => 100,
3939
FontWeight::ExtraLight => 200,
@@ -70,7 +70,7 @@ impl FontStyle {
7070
}
7171
}
7272

73-
pub fn to_u8(self) -> u8 {
73+
pub fn as_u8(self) -> u8 {
7474
match self {
7575
FontStyle::Normal => 0,
7676
FontStyle::Italic => 1,
@@ -102,3 +102,103 @@ impl Default for Font {
102102
}
103103
}
104104
}
105+
106+
impl Font {
107+
pub fn new(family: &str, weight: FontWeight, style: FontStyle) -> Self {
108+
Self {
109+
family: family.to_owned(),
110+
weight,
111+
style,
112+
cached_face_id: None,
113+
}
114+
}
115+
pub fn regular(family: &str) -> Self {
116+
Self {
117+
family: family.to_owned(),
118+
..Default::default()
119+
}
120+
}
121+
pub fn from_font_enum(value: u32) -> Option<Font> {
122+
return Some(match value {
123+
0 => Font::regular(&"rbxasset://fonts/families/LegacyArial.json"),
124+
1 => Font::regular(&"rbxasset://fonts/families/Arial.json"),
125+
2 => Font::new(
126+
&"rbxasset://fonts/families/Arial.json",
127+
FontWeight::Bold,
128+
FontStyle::Normal,
129+
),
130+
3 => Font::regular(&"rbxasset://fonts/families/SourceSansPro.json"),
131+
4 => Font::new(
132+
&"rbxasset://fonts/families/SourceSansPro.json",
133+
FontWeight::Bold,
134+
FontStyle::Normal,
135+
),
136+
16 => Font::new(
137+
&"rbxasset://fonts/families/SourceSansPro.json",
138+
FontWeight::SemiBold,
139+
FontStyle::Normal,
140+
),
141+
5 => Font::new(
142+
&"rbxasset://fonts/families/SourceSansPro.json",
143+
FontWeight::Light,
144+
FontStyle::Normal,
145+
),
146+
6 => Font::new(
147+
&"rbxasset://fonts/families/SourceSansPro.json",
148+
FontWeight::Regular,
149+
FontStyle::Italic,
150+
),
151+
7 => Font::regular(&"rbxasset://fonts/families/AccanthisADFStd.json"),
152+
8 => Font::regular(&"rbxasset://fonts/families/Guru.json"),
153+
9 => Font::regular(&"rbxasset://fonts/families/ComicNeueAngular.json"),
154+
10 => Font::regular(&"rbxasset://fonts/families/Inconsolata.json"),
155+
11 => Font::regular(&"rbxasset://fonts/families/HighwayGothic.json"),
156+
12 => Font::regular(&"rbxasset://fonts/families/Zekton.json"),
157+
13 => Font::regular(&"rbxasset://fonts/families/PressStart2P.json"),
158+
14 => Font::regular(&"rbxasset://fonts/families/Balthazar.json"),
159+
15 => Font::regular(&"rbxasset://fonts/families/RomanAntique.json"),
160+
17 => Font::regular(&"rbxasset://fonts/families/GothamSSm.json"),
161+
18 => Font::new(
162+
&"rbxasset://fonts/families/GothamSSm.json",
163+
FontWeight::Medium,
164+
FontStyle::Normal,
165+
),
166+
19 => Font::new(
167+
&"rbxasset://fonts/families/GothamSSm.json",
168+
FontWeight::Bold,
169+
FontStyle::Normal,
170+
),
171+
20 => Font::new(
172+
&"rbxasset://fonts/families/GothamSSm.json",
173+
FontWeight::Heavy,
174+
FontStyle::Normal,
175+
),
176+
21 => Font::regular(&"rbxasset://fonts/families/AmaticSC.json"),
177+
22 => Font::regular(&"rbxasset://fonts/families/Bangers.json"),
178+
23 => Font::regular(&"rbxasset://fonts/families/Creepster.json"),
179+
24 => Font::regular(&"rbxasset://fonts/families/DenkOne.json"),
180+
25 => Font::regular(&"rbxasset://fonts/families/Fondamento.json"),
181+
26 => Font::regular(&"rbxasset://fonts/families/FredokaOne.json"),
182+
27 => Font::regular(&"rbxasset://fonts/families/GrenzeGotisch.json"),
183+
28 => Font::regular(&"rbxasset://fonts/families/IndieFlower.json"),
184+
29 => Font::regular(&"rbxasset://fonts/families/JosefinSans.json"),
185+
30 => Font::regular(&"rbxasset://fonts/families/Jura.json"),
186+
31 => Font::regular(&"rbxasset://fonts/families/Kalam.json"),
187+
32 => Font::regular(&"rbxasset://fonts/families/LuckiestGuy.json"),
188+
33 => Font::regular(&"rbxasset://fonts/families/Merriweather.json"),
189+
34 => Font::regular(&"rbxasset://fonts/families/Michroma.json"),
190+
35 => Font::regular(&"rbxasset://fonts/families/Nunito.json"),
191+
36 => Font::regular(&"rbxasset://fonts/families/Oswald.json"),
192+
37 => Font::regular(&"rbxasset://fonts/families/PatrickHand.json"),
193+
38 => Font::regular(&"rbxasset://fonts/families/PermanentMarker.json"),
194+
39 => Font::regular(&"rbxasset://fonts/families/Roboto.json"),
195+
40 => Font::regular(&"rbxasset://fonts/families/RobotoCondensed.json"),
196+
41 => Font::regular(&"rbxasset://fonts/families/RobotoMono.json"),
197+
42 => Font::regular(&"rbxasset://fonts/families/Sarpanch.json"),
198+
43 => Font::regular(&"rbxasset://fonts/families/SpecialElite.json"),
199+
44 => Font::regular(&"rbxasset://fonts/families/TitilliumWeb.json"),
200+
45 => Font::regular(&"rbxasset://fonts/families/Ubuntu.json"),
201+
_ => return None,
202+
});
203+
}
204+
}

rbx_xml/src/deserializer.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use log::trace;
77
use rbx_dom_weak::{
8-
types::{Ref, SharedString, Variant, VariantType},
8+
types::{Enum, Font, Ref, SharedString, Variant, VariantType},
99
InstanceBuilder, WeakDom,
1010
};
1111
use rbx_reflection::DataType;
@@ -607,7 +607,31 @@ fn deserialize_properties<R: Read>(
607607
}
608608
};
609609

610-
props.insert(descriptor.name.to_string(), value);
610+
match descriptor.name.as_ref() {
611+
"Font" => match value {
612+
Variant::Enum(value) => match Font::from_font_enum(value.to_u32()) {
613+
Some(value) => {
614+
props.insert(descriptor.name.to_string(), value.into());
615+
}
616+
None => {
617+
log::warn!("Invalid value for Font enum {}, ignoring", value.to_u32())
618+
}
619+
},
620+
_ => log::warn!("Invalid type for Font enum {:?}, ignoring", value),
621+
},
622+
"IgnoreGuiInset" => match value {
623+
Variant::Bool(value) => {
624+
props.insert(
625+
"ScreenInsets".to_string(),
626+
Enum::from_u32(if value { 1 } else { 2 }).into(),
627+
);
628+
}
629+
_ => log::warn!("Invalid type for IgnoreGuiInset bool {:?}, ignoring", value),
630+
},
631+
_ => {
632+
props.insert(descriptor.name.to_string(), value);
633+
}
634+
};
611635
} else {
612636
match state.options.property_behavior {
613637
DecodePropertyBehavior::IgnoreUnknown => {

rbx_xml/src/types/font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl XmlType for Font {
8888
fn write_xml<W: Write>(&self, writer: &mut XmlEventWriter<W>) -> Result<(), EncodeError> {
8989
write_content(writer, &self.family, "Family")?;
9090

91-
writer.write_value_in_tag(&self.weight.to_u16(), "Weight")?;
91+
writer.write_value_in_tag(&self.weight.as_u16(), "Weight")?;
9292

9393
let style = match self.style {
9494
FontStyle::Normal => "Normal",

0 commit comments

Comments
 (0)