Skip to content

Commit 6ccd3aa

Browse files
committed
Let RelativeAnchor be None for RenderAnchor
1 parent fb747fe commit 6ccd3aa

File tree

9 files changed

+196
-432
lines changed

9 files changed

+196
-432
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot_flatbuffers"
3-
version = "0.14.5"
3+
version = "0.14.6"
44
edition = "2024"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"

codegen/enums.rs

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ fn camel_to_snake_case(variable_name: &str) -> String {
1616
for c in variable_name.chars() {
1717
if c.is_uppercase() {
1818
if last_was_uppercase {
19-
snake_case_parts
20-
.last_mut()
21-
.unwrap()
22-
.push(c.to_lowercase().next().unwrap());
19+
snake_case_parts.last_mut().unwrap().push(c.to_lowercase().next().unwrap());
2320
} else {
2421
snake_case_parts.push(c.to_lowercase().to_string());
2522
}
@@ -80,9 +77,7 @@ impl EnumBindGenerator {
8077
})
8178
}
8279

83-
pub fn raw_types_to_custom(
84-
raw_types: Vec<(&str, &str, Option<Vec<String>>)>,
85-
) -> Vec<CustomEnumType> {
80+
pub fn raw_types_to_custom(raw_types: Vec<(&str, &str, Option<Vec<String>>)>) -> Vec<CustomEnumType> {
8681
raw_types
8782
.into_iter()
8883
.map(|(name, raw_type, doc_str)| CustomEnumType {
@@ -129,17 +124,12 @@ impl EnumBindGenerator {
129124
continue;
130125
}
131126

132-
let definition = line_trim
133-
.trim_start_matches("pub const ")
134-
.trim_end_matches(';');
127+
let definition = line_trim.trim_start_matches("pub const ").trim_end_matches(';');
135128

136129
let mut parts = definition.split(": Self = ");
137130

138131
let variable_name = parts.next()?;
139-
let variable_value = parts
140-
.next()?
141-
.trim_start_matches("Self(")
142-
.trim_end_matches(')');
132+
let variable_value = parts.next()?.trim_start_matches("Self(").trim_end_matches(')');
143133

144134
let docs = if docs.is_empty() {
145135
None
@@ -169,14 +159,11 @@ impl EnumBindGenerator {
169159
let union_end_definition = "}\n";
170160
let union_end = contents[union_start..].find(union_end_definition).unwrap();
171161

172-
let union_definition = &contents[union_start + union_definition.len()
173-
..union_start + union_end - union_end_definition.len()];
162+
let union_definition =
163+
&contents[union_start + union_definition.len()..union_start + union_end - union_end_definition.len()];
174164

175165
for (line, variable) in union_definition.split('\n').zip(&mut custom_types) {
176-
let line_trim = line
177-
.trim()
178-
.trim_start_matches(&variable.name)
179-
.trim_end_matches(',');
166+
let line_trim = line.trim().trim_start_matches(&variable.name).trim_end_matches(',');
180167

181168
if line_trim.is_empty() {
182169
variable.value = None;
@@ -185,9 +172,7 @@ impl EnumBindGenerator {
185172

186173
variable.snake_case_name = camel_to_snake_case(variable.name.as_str());
187174

188-
let new_type = line_trim
189-
.trim_start_matches("(Box<")
190-
.trim_end_matches("T>)");
175+
let new_type = line_trim.trim_start_matches("(Box<").trim_end_matches("T>)");
191176
variable.value = Some(new_type.to_string());
192177
}
193178

@@ -204,11 +189,7 @@ impl EnumBindGenerator {
204189

205190
for variable_info in &self.types {
206191
let variable_name = variable_info.name.as_str();
207-
write_fmt!(
208-
self,
209-
" {} => Ok(Self::{variable_name}),",
210-
variable_info.raw_type
211-
);
192+
write_fmt!(self, " {} => Ok(Self::{variable_name}),", variable_info.raw_type);
212193
}
213194

214195
if self.types.len() != usize::from(u8::MAX) {
@@ -256,10 +237,7 @@ impl Generator for EnumBindGenerator {
256237
contents = contents.replace("\r\n", "\n");
257238
}
258239

259-
contents = contents.replace(
260-
"use self::flatbuffers",
261-
"use get_size::GetSize;\nuse self::flatbuffers",
262-
);
240+
contents = contents.replace("use self::flatbuffers", "use get_size::GetSize;\nuse self::flatbuffers");
263241

264242
contents = contents.replace(
265243
"#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]\n",
@@ -288,14 +266,8 @@ impl Generator for EnumBindGenerator {
288266

289267
fn generate_definition(&mut self) {
290268
write_str!(self, "#[allow(non_camel_case_types)]");
291-
write_str!(
292-
self,
293-
"#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]"
294-
);
295-
write_str!(
296-
self,
297-
"#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]"
298-
);
269+
write_str!(self, "#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]");
270+
write_str!(self, "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]");
299271
write_fmt!(self, "pub enum {} {{", self.struct_name);
300272
write_str!(self, " #[default]");
301273

@@ -309,17 +281,8 @@ impl Generator for EnumBindGenerator {
309281
}
310282

311283
fn generate_from_flat_impls(&mut self) {
312-
write_fmt!(
313-
self,
314-
"impl From<flat::{}> for {} {{",
315-
self.struct_name,
316-
self.struct_name
317-
);
318-
write_fmt!(
319-
self,
320-
" fn from(flat_t: flat::{}) -> Self {{",
321-
self.struct_name
322-
);
284+
write_fmt!(self, "impl From<flat::{}> for {} {{", self.struct_name, self.struct_name);
285+
write_fmt!(self, " fn from(flat_t: flat::{}) -> Self {{", self.struct_name);
323286
write_str!(self, " match flat_t {");
324287

325288
for variable_info in &self.types {
@@ -332,11 +295,7 @@ impl Generator for EnumBindGenerator {
332295
);
333296
}
334297

335-
write_fmt!(
336-
self,
337-
" _ => Self::{},",
338-
self.types.last().unwrap().name.as_str()
339-
);
298+
write_fmt!(self, " _ => Self::{},", self.types.last().unwrap().name.as_str());
340299

341300
write_str!(self, " }");
342301
write_str!(self, " }");
@@ -345,17 +304,8 @@ impl Generator for EnumBindGenerator {
345304
}
346305

347306
fn generate_to_flat_impls(&mut self) {
348-
write_fmt!(
349-
self,
350-
"impl From<&{}> for flat::{} {{",
351-
self.struct_name,
352-
self.struct_name
353-
);
354-
write_fmt!(
355-
self,
356-
" fn from(py_type: &{}) -> Self {{",
357-
self.struct_name
358-
);
307+
write_fmt!(self, "impl From<&{}> for flat::{} {{", self.struct_name, self.struct_name);
308+
write_fmt!(self, " fn from(py_type: &{}) -> Self {{", self.struct_name);
359309
write_str!(self, " match *py_type {");
360310

361311
for variable_info in &self.types {

codegen/main.rs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,10 @@ impl PythonBindType {
5353
"PredictionSlice",
5454
"BallPrediction",
5555
];
56-
pub const UNIONS: [&'static str; 4] = [
57-
"PlayerClass",
58-
"CollisionShape",
59-
"RelativeAnchor",
60-
"RenderType",
61-
];
56+
pub const UNIONS: [&'static str; 4] = ["PlayerClass", "CollisionShape", "RelativeAnchor", "RenderType"];
6257

63-
pub const DEFAULT_OVERRIDES: [(&'static str, &'static str, &'static str); 1] =
64-
[("Color", "a", "255")];
58+
pub const OPTIONAL_UNIONS: [&'static str; 1] = ["RelativeAnchor"];
59+
pub const DEFAULT_OVERRIDES: [(&'static str, &'static str, &'static str); 1] = [("Color", "a", "255")];
6560
pub const FREELIST_TYPES: [(&'static str, usize); 0] = [];
6661

6762
fn new(path: &Path) -> Option<Self> {
@@ -106,12 +101,7 @@ impl PythonBindType {
106101
let struct_doc_str = if docs.is_empty() {
107102
None
108103
} else {
109-
Some(
110-
docs.into_iter()
111-
.map(|s| s.to_string())
112-
.rev()
113-
.collect::<Vec<_>>(),
114-
)
104+
Some(docs.into_iter().map(|s| s.to_string()).rev().collect::<Vec<_>>())
115105
};
116106

117107
if let Some(types) = StructBindGenerator::get_types(&contents, &struct_t_name) {
@@ -125,15 +115,11 @@ impl PythonBindType {
125115
)?));
126116
}
127117

128-
if let Some((types, enum_type)) =
129-
enums::EnumBindGenerator::get_types(&contents, &struct_name)
130-
{
118+
if let Some((types, enum_type)) = enums::EnumBindGenerator::get_types(&contents, &struct_name) {
131119
return Some(match enum_type {
132-
enums::EnumType::Enum => Self::Enum(enums::EnumBindGenerator::new(
133-
filename.to_string(),
134-
struct_name,
135-
types,
136-
)?),
120+
enums::EnumType::Enum => {
121+
Self::Enum(enums::EnumBindGenerator::new(filename.to_string(), struct_name, types)?)
122+
}
137123
enums::EnumType::Union => Self::Union(unions::UnionBindGenerator::new(
138124
filename.to_string(),
139125
struct_name,
@@ -183,10 +169,7 @@ fn mod_rs_generator(type_data: &[PythonBindType]) -> io::Result<()> {
183169

184170
file_contents.push(Cow::Borrowed(""));
185171

186-
fs::write(
187-
format!("{PYTHON_OUT_FOLDER}/mod.rs"),
188-
file_contents.join("\n"),
189-
)?;
172+
fs::write(format!("{PYTHON_OUT_FOLDER}/mod.rs"), file_contents.join("\n"))?;
190173

191174
Ok(())
192175
}
@@ -204,10 +187,7 @@ fn run_flatc() -> io::Result<()> {
204187
let mut schema_folder = Path::new(SCHEMA_FOLDER);
205188
if !schema_folder.exists() {
206189
schema_folder = Path::new(SCHEMA_FOLDER_BACKUP);
207-
assert!(
208-
schema_folder.exists(),
209-
"Could not find flatbuffers schema folder"
210-
);
190+
assert!(schema_folder.exists(), "Could not find flatbuffers schema folder");
211191
}
212192

213193
let schema_folder_str = schema_folder.display();

0 commit comments

Comments
 (0)