@@ -12,13 +12,18 @@ use std::{borrow::Cow, env::set_current_dir, fs, io, path::Path, process::Comman
1212use structs:: StructBindGenerator ;
1313use zip:: ZipArchive ;
1414
15- const FLATC_BINARY : & str = if cfg ! ( windows ) { "flatc.exe" } else { "flatc" } ;
16- const OUT_FOLDER : & str = "./src/generated" ;
15+ const FLATC_DOWNLOAD_URL : & str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/" ;
16+
1717const SCHEMA_FOLDER : & str = "./flatbuffers-schema" ;
1818const SCHEMA_FOLDER_BACKUP : & str = "../flatbuffers-schema" ;
19+ const RLBOT_FBS : & str = "schema/rlbot.fbs" ;
20+ const FLATC_BINARY : & str = if cfg ! ( windows) {
21+ "binaries\\ flatc.exe"
22+ } else {
23+ "binaries/flatc"
24+ } ;
1925
20- const FLATC_DOWNLOAD_URL : & str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/" ;
21-
26+ const OUT_FOLDER : & str = "./src/generated" ;
2227pub const PYTHON_OUT_FOLDER : & str = "./src/python" ;
2328
2429pub enum PythonBindType {
@@ -29,15 +34,14 @@ pub enum PythonBindType {
2934
3035impl PythonBindType {
3136 pub const BASE_TYPES : [ & ' static str ; 6 ] = [ "bool" , "i32" , "u32" , "f32" , "String" , "u8" ] ;
32- pub const FROZEN_TYPES : [ & ' static str ; 6 ] = [
37+ pub const FROZEN_TYPES : [ & ' static str ; 26 ] = [
38+ "ControllableInfo" ,
39+ "ControllableTeamInfo" ,
40+ "PredictionSlice" ,
41+ "BallPrediction" ,
3342 "GoalInfo" ,
3443 "BoostPad" ,
3544 "FieldInfo" ,
36- "ControllableInfo" ,
37- "ControllableTeamInfo" ,
38- "PlayerClass" ,
39- ] ;
40- pub const NO_SET_TYPES : [ & ' static str ; 16 ] = [
4145 "Physics" ,
4246 "GamePacket" ,
4347 "PlayerInfo" ,
@@ -52,13 +56,25 @@ impl PythonBindType {
5256 "MatchInfo" ,
5357 "TeamInfo" ,
5458 "Vector2" ,
55- "PredictionSlice" ,
56- "BallPrediction" ,
59+ "CoreMessage" ,
60+ "InterfaceMessage" ,
61+ "CorePacket" ,
62+ "InterfacePacket" ,
63+ "PlayerInput" ,
64+ ] ;
65+ pub const NO_SET_TYPES : [ & ' static str ; 1 ] = [ "PlayerClass" ] ;
66+ pub const UNIONS : [ & ' static str ; 6 ] = [
67+ "PlayerClass" ,
68+ "CollisionShape" ,
69+ "RelativeAnchor" ,
70+ "RenderType" ,
71+ "CoreMessage" ,
72+ "InterfaceMessage" ,
5773 ] ;
58- pub const UNIONS : [ & ' static str ; 4 ] = [ "PlayerClass" , "CollisionShape" , "RelativeAnchor" , "RenderType" ] ;
5974
6075 pub const OPTIONAL_UNIONS : [ & ' static str ; 1 ] = [ "RelativeAnchor" ] ;
6176 pub const DEFAULT_OVERRIDES : [ ( & ' static str , & ' static str , & ' static str ) ; 1 ] = [ ( "Color" , "a" , "255" ) ] ;
77+ pub const FIELD_ALIASES : [ ( & ' static str , & ' static str , & ' static str ) ; 1 ] = [ ( "PlayerInfo" , "player_id" , "spawn_id" ) ] ;
6278 pub const FREELIST_TYPES : [ ( & ' static str , usize ) ; 0 ] = [ ] ;
6379
6480 fn new ( path : & Path ) -> Option < Self > {
@@ -176,15 +192,15 @@ fn mod_rs_generator(type_data: &[PythonBindType]) -> io::Result<()> {
176192 Ok ( ( ) )
177193}
178194
179- fn run_flatc ( ) -> io :: Result < ( ) > {
195+ fn run_flatc ( ) {
180196 println ! ( "cargo:rerun-if-changed=flatbuffers-schema/comms.fbs" ) ;
181197 println ! ( "cargo:rerun-if-changed=flatbuffers-schema/gamedata.fbs" ) ;
182198 println ! ( "cargo:rerun-if-changed=flatbuffers-schema/gamestatemanip.fbs" ) ;
183199 println ! ( "cargo:rerun-if-changed=flatbuffers-schema/matchconfig.fbs" ) ;
184200 println ! ( "cargo:rerun-if-changed=flatbuffers-schema/rendering.fbs" ) ;
185201 println ! ( "cargo:rerun-if-changed=flatbuffers-schema/rlbot.fbs" ) ;
186202
187- set_current_dir ( env ! ( "CARGO_MANIFEST_DIR" ) ) ? ;
203+ set_current_dir ( env ! ( "CARGO_MANIFEST_DIR" ) ) . unwrap ( ) ;
188204
189205 let mut schema_folder = Path :: new ( SCHEMA_FOLDER ) ;
190206 if !schema_folder. exists ( ) {
@@ -197,51 +213,58 @@ fn run_flatc() -> io::Result<()> {
197213 let flatc_path = Path :: new ( & flatc_str) ;
198214
199215 if !flatc_path. exists ( ) {
216+ fs:: create_dir_all ( flatc_path) . unwrap ( ) ;
217+
200218 // if the flatc binary isn't found, download it
201219 let file_name = if cfg ! ( windows) {
202220 "Windows.flatc.binary.zip"
203221 } else {
204222 "Linux.flatc.binary.g++-13.zip"
205223 } ;
206- let response = reqwest:: blocking:: get ( format ! ( "{FLATC_DOWNLOAD_URL}/{file_name}" ) ) . map_err ( |e| {
207- eprintln ! ( "Failed to download flatc binary: {e}" ) ;
208- io:: Error :: other ( "Failed to download flatc binary" )
209- } ) ?;
210- let bytes = response. bytes ( ) . map_err ( |e| {
211- eprintln ! ( "Failed to read response stream when downloading flatc binary: {e}" ) ;
212- io:: Error :: other ( "Failed to read response stream when downloading flatc binary" )
213- } ) ?;
224+ let response = reqwest:: blocking:: get ( format ! ( "{FLATC_DOWNLOAD_URL}/{file_name}" ) )
225+ . map_err ( |e| {
226+ eprintln ! ( "Failed to download flatc binary: {e}" ) ;
227+ io:: Error :: other ( "Failed to download flatc binary" )
228+ } )
229+ . unwrap ( ) ;
230+ let bytes = response
231+ . bytes ( )
232+ . map_err ( |e| {
233+ eprintln ! ( "Failed to read response stream when downloading flatc binary: {e}" ) ;
234+ io:: Error :: other ( "Failed to read response stream when downloading flatc binary" )
235+ } )
236+ . unwrap ( ) ;
214237
215238 // extract zip
216- let mut zip = ZipArchive :: new ( io:: Cursor :: new ( bytes) ) ? ;
217- zip. extract ( schema_folder) ? ;
239+ let mut zip = ZipArchive :: new ( io:: Cursor :: new ( bytes) ) . unwrap ( ) ;
240+ zip. extract ( schema_folder) . unwrap ( ) ;
218241
219242 assert ! ( flatc_path. exists( ) , "Failed to download flatc binary" ) ;
220243 }
221244
222245 let mut proc = Command :: new ( flatc_str) ;
223246
224247 proc. args ( [
225- "--rust" ,
226- "--gen-object-api" ,
227- "--gen-all" ,
228- "--filename-suffix" ,
229- "" ,
230- "--rust-module-root-file" ,
231- "-o" ,
232- OUT_FOLDER ,
233- & format ! ( "{schema_folder_str}/rlbot.fbs" ) ,
248+ "--rust" . as_ref ( ) ,
249+ "--gen-object-api" . as_ref ( ) ,
250+ "--gen-all" . as_ref ( ) ,
251+ "--filename-suffix" . as_ref ( ) ,
252+ "" . as_ref ( ) ,
253+ "--rust-module-root-file" . as_ref ( ) ,
254+ "-o" . as_ref ( ) ,
255+ OUT_FOLDER . as_ref ( ) ,
256+ schema_folder . join ( RLBOT_FBS ) . as_os_str ( ) ,
234257 ] )
235- . spawn ( ) ?
236- . wait ( ) ? ;
237-
238- assert ! ( proc . status ( ) ? . success ( ) , "flatc failed to run" ) ;
258+ . spawn ( )
259+ . unwrap ( )
260+ . wait ( )
261+ . unwrap ( ) ;
239262
240- Ok ( ( ) )
263+ assert ! ( proc . status ( ) . unwrap ( ) . success ( ) , "flatc failed to run" ) ;
241264}
242265
243- fn main ( ) -> io :: Result < ( ) > {
244- run_flatc ( ) ? ;
266+ fn main ( ) {
267+ run_flatc ( ) ;
245268
246269 let out_folder = Path :: new ( OUT_FOLDER ) . join ( "rlbot" ) . join ( "flat" ) ;
247270
@@ -252,9 +275,11 @@ fn main() -> io::Result<()> {
252275 ) ;
253276
254277 // read the current contents of the generated folder
255- let generated_files = fs:: read_dir ( out_folder) ?
278+ let generated_files = fs:: read_dir ( out_folder)
279+ . unwrap ( )
256280 . map ( |res| res. map ( |e| e. path ( ) ) )
257- . collect :: < Result < Vec < _ > , io:: Error > > ( ) ?;
281+ . collect :: < Result < Vec < _ > , io:: Error > > ( )
282+ . unwrap ( ) ;
258283
259284 let mut type_data = Vec :: new ( ) ;
260285
@@ -263,13 +288,11 @@ fn main() -> io::Result<()> {
263288 continue ;
264289 } ;
265290
266- bind_generator. generate ( & path) ? ;
291+ bind_generator. generate ( & path) . unwrap ( ) ;
267292 type_data. push ( bind_generator) ;
268293 }
269294
270- mod_rs_generator ( & type_data) ?;
271- pyi:: generator ( & type_data) ?;
272- class_inject:: classes_to_lib_rs ( & type_data) ?;
273-
274- Ok ( ( ) )
295+ mod_rs_generator ( & type_data) . unwrap ( ) ;
296+ pyi:: generator ( & type_data) . unwrap ( ) ;
297+ class_inject:: classes_to_lib_rs ( & type_data) . unwrap ( ) ;
275298}
0 commit comments