@@ -466,6 +466,33 @@ impl StructBindGenerator {
466466
467467 write_str ! ( self , " }" ) ;
468468 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+ }
469496 }
470497
471498 fn generate_str_method ( & mut self ) {
@@ -919,10 +946,8 @@ impl Generator for StructBindGenerator {
919946 "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all, frozen)]"
920947 } else if self . types. is_empty( ) {
921948 "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, frozen)]"
922- } else if self . is_no_set {
923- "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all)]"
924949 } else {
925- "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all, set_all )]"
950+ "#[pyclass(module = \" rlbot_flatbuffers\" , subclass, get_all)]"
926951 }
927952 ) ;
928953
@@ -933,11 +958,14 @@ impl Generator for StructBindGenerator {
933958 return ;
934959 }
935960
961+ let gen_set = !( self . is_no_set || self . is_frozen ) ;
962+
936963 write_fmt ! ( self , "pub struct {} {{" , self . struct_name) ;
937964
938965 for variable_info in & self . types {
939966 let variable_name = variable_info. name . as_str ( ) ;
940967
968+ let mut add_set = true ;
941969 let variable_type = match & variable_info. rust_type {
942970 RustType :: Vec ( InnerVecType :: U8 ) => String :: from ( "Py<PyBytes>" ) ,
943971 RustType :: Vec ( InnerVecType :: String ) => String :: from ( "Vec<String>" ) ,
@@ -952,7 +980,10 @@ impl Generator for StructBindGenerator {
952980 }
953981 RustType :: Option ( _, inner_type) => format ! ( "Option<Py<super::{inner_type}>>" ) ,
954982 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+ }
956987 _ => inner_type. clone ( ) ,
957988 } ,
958989 RustType :: String => String :: from ( "Py<PyString>" ) ,
@@ -962,6 +993,10 @@ impl Generator for StructBindGenerator {
962993 RustType :: Other ( inner_type) => format ! ( "super::{inner_type}" ) ,
963994 } ;
964995
996+ if gen_set && add_set {
997+ write_str ! ( self , " #[pyo3(set)]" ) ;
998+ }
999+
9651000 write_fmt ! ( self , " pub {variable_name}: {variable_type}," ) ;
9661001 }
9671002
0 commit comments