MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / generate_procedure_file

Method generate_procedure_file

crates/codegen/src/unrealcpp.rs:622–786  ·  view source on GitHub ↗
(
        &self,
        module: &ModuleDef,
        procedure: &spacetimedb_schema::def::ProcedureDef,
    )

Source from the content-addressed store, hash-verified

620 }
621
622 fn generate_procedure_file(
623 &self,
624 module: &ModuleDef,
625 procedure: &spacetimedb_schema::def::ProcedureDef,
626 ) -> OutputFile {
627 let procedure_snake = procedure.name.deref();
628 let procedure_pascal = procedure_snake.to_case(Case::Pascal);
629 let pascal = format!("{}{}", self.module_prefix, procedure_pascal);
630
631 // Collect includes for parameter types
632 let mut includes = HashSet::<String>::new();
633 for (_param_name, param_type) in &procedure.params_for_generate.elements {
634 collect_includes_for_type(self.module_prefix, module, param_type, &mut includes, self.module_name);
635 }
636 collect_includes_for_type(
637 self.module_prefix,
638 module,
639 &procedure.return_type_for_generate,
640 &mut includes,
641 self.module_name,
642 );
643
644 // Convert to sorted vector
645 let mut include_vec: Vec<String> = includes.into_iter().collect();
646 include_vec.sort();
647
648 // Convert to string references
649 let include_refs: Vec<&str> = include_vec.iter().map(|s| s.as_str()).collect();
650
651 let mut header = UnrealCppAutogen::new(&include_refs, &pascal, false);
652
653 let args_struct = format!("F{pascal}Args");
654
655 // Generate procedure arguments struct
656 writeln!(header, "// Procedure arguments struct for {pascal}");
657 writeln!(header, "USTRUCT(BlueprintType)");
658 writeln!(header, "struct {} {args_struct}", self.get_api_macro());
659 writeln!(header, "{{");
660 writeln!(header, " GENERATED_BODY()");
661 writeln!(header);
662
663 // Generate properties for each parameter
664 for (param_name, param_type) in &procedure.params_for_generate.elements {
665 let param_pascal = param_name.deref().to_case(Case::Pascal);
666 let type_str = cpp_ty_fmt_with_module(self.module_prefix, module, param_type, self.module_name).to_string();
667 let init_str = cpp_ty_init_fmt_impl(self.module_prefix, module, param_type);
668 let field_decl = format!("{type_str} {param_pascal}{init_str}");
669
670 // Check if the type is blueprintable
671 if is_blueprintable(module, param_type) {
672 writeln!(header, " UPROPERTY(BlueprintReadWrite, Category=\"SpacetimeDB\")");
673 } else {
674 // Add comment explaining why the field isn't exposed as UPROPERTY
675 writeln!(
676 header,
677 " // NOTE: {type_str} field not exposed to Blueprint due to non-blueprintable elements"
678 );
679 }

Callers

nothing calls this directly

Calls 15

cpp_ty_fmt_with_moduleFunction · 0.85
cpp_ty_init_fmt_implFunction · 0.85
is_blueprintableFunction · 0.85
to_caseMethod · 0.80
iterMethod · 0.65
newFunction · 0.50
derefMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
mapMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected