@@ -466,6 +466,33 @@ impl StructBindGenerator {
466
466
467
467
write_str ! ( self , " }" ) ;
468
468
write_str ! ( self , " }" ) ;
469
+
470
+ if self . is_frozen || self . is_no_set {
471
+ return ;
472
+ }
473
+
474
+ for variable_info in & self . types {
475
+ let variable_name = variable_info. name . as_str ( ) ;
476
+
477
+ match & variable_info. rust_type {
478
+ RustType :: Base ( inner_type) => match inner_type. as_str ( ) {
479
+ "f32" => {
480
+ write_str ! ( self , "\n #[setter]" ) ;
481
+ write_fmt ! (
482
+ self ,
483
+ " pub fn {variable_name}(&mut self, py: Python, value: f32) {{" ,
484
+ ) ;
485
+ write_fmt ! (
486
+ self ,
487
+ " self.{variable_name} = crate::float_to_py(py, value);"
488
+ ) ;
489
+ write_str ! ( self , " }" ) ;
490
+ }
491
+ _ => continue ,
492
+ } ,
493
+ _ => continue ,
494
+ }
495
+ }
469
496
}
470
497
471
498
fn generate_str_method ( & mut self ) {
@@ -919,10 +946,8 @@ impl Generator for StructBindGenerator {
919
946
"#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all, frozen)]"
920
947
} else if self . types. is_empty( ) {
921
948
"#[pyclass(module = \" rlbot_flatbuffers\" , subclass, frozen)]"
922
- } else if self . is_no_set {
923
- "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all)]"
924
949
} else {
925
- "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all, set_all )]"
950
+ "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all)]"
926
951
}
927
952
) ;
928
953
@@ -933,11 +958,14 @@ impl Generator for StructBindGenerator {
933
958
return ;
934
959
}
935
960
961
+ let gen_set = !( self . is_no_set || self . is_frozen ) ;
962
+
936
963
write_fmt ! ( self , "pub struct {} {{" , self . struct_name) ;
937
964
938
965
for variable_info in & self . types {
939
966
let variable_name = variable_info. name . as_str ( ) ;
940
967
968
+ let mut add_set = true ;
941
969
let variable_type = match & variable_info. rust_type {
942
970
RustType :: Vec ( InnerVecType :: U8 ) => String :: from ( "Py<PyBytes>" ) ,
943
971
RustType :: Vec ( InnerVecType :: String ) => String :: from ( "Vec<String>" ) ,
@@ -952,7 +980,10 @@ impl Generator for StructBindGenerator {
952
980
}
953
981
RustType :: Option ( _, inner_type) => format ! ( "Option<Py<super::{inner_type}>>" ) ,
954
982
RustType :: Base ( inner_type) => match inner_type. as_str ( ) {
955
- "f32" => String :: from ( "Py<PyFloat>" ) ,
983
+ "f32" => {
984
+ add_set = false ;
985
+ String :: from ( "Py<PyFloat>" )
986
+ }
956
987
_ => inner_type. clone ( ) ,
957
988
} ,
958
989
RustType :: String => String :: from ( "Py<PyString>" ) ,
@@ -962,6 +993,10 @@ impl Generator for StructBindGenerator {
962
993
RustType :: Other ( inner_type) => format ! ( "super::{inner_type}" ) ,
963
994
} ;
964
995
996
+ if gen_set && add_set {
997
+ write_str ! ( self , " #[pyo3(set)]" ) ;
998
+ }
999
+
965
1000
write_fmt ! ( self , " pub {variable_name}: {variable_type}," ) ;
966
1001
}
967
1002
0 commit comments