(
module_prefix: &str,
module: &ModuleDef,
name: &str, // Changed to &str
product_type: &ProductTypeDef,
api_macro: &str,
module_name: &str,
)
| 6051 | } |
| 6052 | |
| 6053 | fn autogen_cpp_struct( |
| 6054 | module_prefix: &str, |
| 6055 | module: &ModuleDef, |
| 6056 | name: &str, // Changed to &str |
| 6057 | product_type: &ProductTypeDef, |
| 6058 | api_macro: &str, |
| 6059 | module_name: &str, |
| 6060 | ) -> String { |
| 6061 | let mut headers = HashSet::<String>::new(); |
| 6062 | |
| 6063 | for (_, field_ty) in product_type { |
| 6064 | collect_includes_for_type(module_prefix, module, field_ty, &mut headers, module_name); |
| 6065 | } |
| 6066 | |
| 6067 | // Convert to `Vec<&str>` so UnrealCppAutogen::new works |
| 6068 | let mut slices: Vec<&str> = headers.iter().map(|s| s.as_str()).collect(); |
| 6069 | slices.sort(); // make output deterministic |
| 6070 | |
| 6071 | // --------- start writing file --------- |
| 6072 | let type_name = format!("{name}Type"); |
| 6073 | let mut output = UnrealCppAutogen::new(&slices, &type_name, false); |
| 6074 | |
| 6075 | writeln!(output, "USTRUCT(BlueprintType)"); |
| 6076 | writeln!(output, "struct {api_macro} F{name}Type"); |
| 6077 | writeln!(output, "{{"); |
| 6078 | output.indent(1); |
| 6079 | writeln!(output, "GENERATED_BODY()"); |
| 6080 | writeln!(output); |
| 6081 | |
| 6082 | for (orig_name, ty) in product_type.into_iter() { |
| 6083 | let field_name = orig_name.deref().to_case(Case::Pascal); |
| 6084 | let ty_str = cpp_ty_fmt_with_module(module_prefix, module, ty, module_name).to_string(); |
| 6085 | let init_str = cpp_ty_init_fmt_impl(module_prefix, module, ty); |
| 6086 | let field_decl = format!("{ty_str} {field_name}{init_str}"); |
| 6087 | |
| 6088 | // Check if the type is blueprintable |
| 6089 | if is_blueprintable(module, ty) { |
| 6090 | writeln!( |
| 6091 | output, |
| 6092 | "UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"SpacetimeDB\")" |
| 6093 | ); |
| 6094 | } else { |
| 6095 | // Add comment explaining why the field isn't exposed as UPROPERTY |
| 6096 | writeln!( |
| 6097 | output, |
| 6098 | "// NOTE: {ty_str} field not exposed to Blueprint due to non-blueprintable elements" |
| 6099 | ); |
| 6100 | } |
| 6101 | writeln!(output, "{field_decl};"); |
| 6102 | writeln!(output); |
| 6103 | } |
| 6104 | |
| 6105 | // Generate operator== and operator!= |
| 6106 | writeln!(output, "FORCEINLINE bool operator==(const F{name}Type& Other) const"); |
| 6107 | writeln!(output, "{{"); |
| 6108 | output.indent(1); |
| 6109 | |
| 6110 | // Generate comparison for each field |
no test coverage detected
searching dependent graphs…