From a582f3590e30b6735851d684492b93e685bf42b0 Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Mon, 21 Nov 2022 19:35:20 +0100 Subject: [PATCH 01/10] Extend ScriptSignalsGenerator --- .../ScriptSignalsGenerator.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index 50196b84f04c..289ea12e6d7e 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -218,6 +218,63 @@ INamedTypeSymbol symbol source.Append(" }\n"); } + // Generate the SignalEmit class + + var @base = symbol.BaseType; + bool hasBase = @base != null; + + if (hasBase) + hasBase = SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, @base!.ContainingAssembly); + + source.AppendLine($" public new class SignalEmit{(hasBase ? ($" : {@base!.FullQualifiedName()}.SignalEmit") : "")}") + .AppendLine(" {"); + + if (!hasBase) + { + // Create bound field and ctor + source.AppendLine($" protected {GodotClasses.Object} bound;"); + + source.AppendLine($" public SignalEmit({GodotClasses.Object} bound)") + .AppendLine(" {") + .AppendLine(" this.bound = bound;") + .AppendLine(" }"); + + } + else + { + source.AppendLine($" public SignalEmit({GodotClasses.Object} bound) : base(bound) {{ }}"); + } + + foreach (var signalDelegate in godotSignalDelegates) + { + string signalName = signalDelegate.Name; + + var paramsSb = new StringBuilder(""); + var parameters = signalDelegate.InvokeMethodData.Method.Parameters; + + for (int i = 0; i < parameters.Length; i++) + { + paramsSb.Append(parameters[i].ToString()) + .Append(" ") + .Append(parameters[i].Name.ToString()); + + if (i != parameters.Length - 1) + paramsSb.Append(", "); + } + + source.AppendLine($" public void {signalName}({paramsSb.ToString()})") + .AppendLine(" {") + .AppendLine($" bound.EmitSignal({symbol.NameWithTypeParameters()}.SignalName.{signalName});") + .AppendLine(" }"); + } + + source.AppendLine(" }"); + + // Generate the Emit property + source.AppendLine(" private new SignalEmit _emit;") + .AppendLine("/// <summary>A helper to quickly and safely emit signals.</summary>") + .AppendLine(" public new SignalEmit Emit => _emit ??= new(this);"); + source.Append("#pragma warning restore CS0109\n"); // Generate signal event From 23357aa7faf495c0ecc7aef39a115161e5ef096e Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Thu, 24 Nov 2022 21:25:01 +0100 Subject: [PATCH 02/10] Make bindings generator generate everything --- modules/mono/editor/bindings_generator.cpp | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index b90321b58695..f273d0658ca9 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1541,6 +1541,11 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str output.append(itype.name); output.append("\";\n"); + // Add Emit property + output << MEMBER_BEGIN "private new SignalEmit _emit;\n" + << MEMBER_BEGIN "/// <summary>A helper to quickly and safely emit signals.</summary>\n" + << MEMBER_BEGIN "public new SignalEmit Emit => new(this);\n"; + if (itype.is_instantiable) { // Add native constructor static field @@ -1762,6 +1767,59 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str } output << INDENT1 "}\n"; + //SignalEmit + if (!itype.is_singleton) { + if (is_inherit) { + output << MEMBER_BEGIN "public new class SignalEmit : " << obj_types[itype.base_name].proxy_name << ".SignalEmit\n" + << INDENT1 "{\n"; + // Generate ctor + output << INDENT2 "public SignalEmit(Godot.Object bound) : base(bound) { }\n"; + } else { + output << MEMBER_BEGIN "public class SignalEmit\n" + << INDENT1 "{\n"; + // Generate bound field and ctor + output << INDENT2 "protected Godot.Object bound;\n" + << INDENT2 "public SignalEmit(Godot.Object bound)\n" + << INDENT2 "{\n" + << INDENT3 "this.bound = bound;\n" + << INDENT2 "}\n"; + } + // Generate SignalEmit's methods + for (const SignalInterface &isignal : itype.signals_) { + String arg_sig; + String arg_call_sig; + + // Get arguments + const ArgumentInterface &first_arg = isignal.arguments.front()->get(); + for (const ArgumentInterface &iarg : isignal.arguments) { + const TypeInterface *arg_type = _get_type_or_null(iarg.type); + + // No need to Add ERR_FAIL_COND's because there already in _generate_cs_signal + + if (&iarg != &first_arg) { + arg_sig += ", "; + } + arg_call_sig += ", "; + + arg_sig += arg_type->cs_type; + arg_sig += " "; + arg_sig += iarg.name; + arg_call_sig += iarg.name; + } + + output << MEMBER_BEGIN INDENT1 "/// <summary>\n" + << INDENT2 "/// " + << "Fires the" + << "<see cref=\"" BINDINGS_NAMESPACE "." + itype.proxy_name + "." + isignal.proxy_name + "\"/>" + << " signal.\n" + << INDENT2 "/// </summary>\n"; + + output << INDENT2 "public void " << isignal.proxy_name << "(" << arg_sig << ")" + << " => bound.EmitSignal(\"" << isignal.name << "\"" << arg_call_sig << ");\n"; + } + output << INDENT1 "}\n"; + } + output.append(CLOSE_BLOCK /* class */); output.append("\n" From e6ae20e703452a600a30764764dc2948143c143a Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Thu, 24 Nov 2022 21:26:21 +0100 Subject: [PATCH 03/10] Update ScriptSignalsGenerator - Add inherited xml - Remove has base stuff --- .../ScriptSignalsGenerator.cs | 34 ++++--------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index 289ea12e6d7e..43e61746258a 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -219,31 +219,10 @@ INamedTypeSymbol symbol } // Generate the SignalEmit class - - var @base = symbol.BaseType; - bool hasBase = @base != null; - - if (hasBase) - hasBase = SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, @base!.ContainingAssembly); - - source.AppendLine($" public new class SignalEmit{(hasBase ? ($" : {@base!.FullQualifiedName()}.SignalEmit") : "")}") + source.AppendLine($" public new class SignalEmit : {symbol.BaseType.FullQualifiedName()}.SignalEmit") .AppendLine(" {"); - if (!hasBase) - { - // Create bound field and ctor - source.AppendLine($" protected {GodotClasses.Object} bound;"); - - source.AppendLine($" public SignalEmit({GodotClasses.Object} bound)") - .AppendLine(" {") - .AppendLine(" this.bound = bound;") - .AppendLine(" }"); - - } - else - { - source.AppendLine($" public SignalEmit({GodotClasses.Object} bound) : base(bound) {{ }}"); - } + source.AppendLine($" public SignalEmit({GodotClasses.Object} bound) : base(bound) {{ }}"); foreach (var signalDelegate in godotSignalDelegates) { @@ -261,18 +240,17 @@ INamedTypeSymbol symbol if (i != parameters.Length - 1) paramsSb.Append(", "); } + source.AppendLine($" /// <inheritdoc cref=\"{signalDelegate.DelegateSymbol.FullQualifiedName()}\"/>"); - source.AppendLine($" public void {signalName}({paramsSb.ToString()})") - .AppendLine(" {") - .AppendLine($" bound.EmitSignal({symbol.NameWithTypeParameters()}.SignalName.{signalName});") - .AppendLine(" }"); + source.Append($" public void {signalName}({paramsSb.ToString()})") + .AppendLine($" => bound.EmitSignal({symbol.NameWithTypeParameters()}.SignalName.{signalName});"); } source.AppendLine(" }"); // Generate the Emit property source.AppendLine(" private new SignalEmit _emit;") - .AppendLine("/// <summary>A helper to quickly and safely emit signals.</summary>") + .AppendLine(" /// <summary>A helper to quickly and safely emit signals.</summary>") .AppendLine(" public new SignalEmit Emit => _emit ??= new(this);"); source.Append("#pragma warning restore CS0109\n"); From 8a61f7b7e40393a4044567cbcf4d169023352055 Mon Sep 17 00:00:00 2001 From: OlliO6 <104021024+OlliO6@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:07:07 +0100 Subject: [PATCH 04/10] Update ScriptSignalsGenerator Co-authored-by: Raul Santos <raulsntos@gmail.com> --- .../Godot.SourceGenerators/ScriptSignalsGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index 43e61746258a..1fe6840c6b43 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -228,7 +228,7 @@ INamedTypeSymbol symbol { string signalName = signalDelegate.Name; - var paramsSb = new StringBuilder(""); + var paramsSb = new StringBuilder(); var parameters = signalDelegate.InvokeMethodData.Method.Parameters; for (int i = 0; i < parameters.Length; i++) From 81af440288c24ec828ae29fb4bbacf61f5aad000 Mon Sep 17 00:00:00 2001 From: OlliO6 <104021024+OlliO6@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:14:27 +0100 Subject: [PATCH 05/10] Update bindings_generator.cpp Co-authored-by: Raul Santos <raulsntos@gmail.com> --- modules/mono/editor/bindings_generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index f273d0658ca9..979ed72002bd 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1809,7 +1809,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str output << MEMBER_BEGIN INDENT1 "/// <summary>\n" << INDENT2 "/// " - << "Fires the" + << "Raises the" << "<see cref=\"" BINDINGS_NAMESPACE "." + itype.proxy_name + "." + isignal.proxy_name + "\"/>" << " signal.\n" << INDENT2 "/// </summary>\n"; From 8f44adf4ecf1da0c538cd831fef10e323ba2ba2b Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Fri, 25 Nov 2022 16:18:13 +0100 Subject: [PATCH 06/10] Make bindings use lazy getter --- modules/mono/editor/bindings_generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index f273d0658ca9..c2ea06d121db 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1544,7 +1544,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str // Add Emit property output << MEMBER_BEGIN "private new SignalEmit _emit;\n" << MEMBER_BEGIN "/// <summary>A helper to quickly and safely emit signals.</summary>\n" - << MEMBER_BEGIN "public new SignalEmit Emit => new(this);\n"; + << MEMBER_BEGIN "public new SignalEmit Emit => _emit ??= new(this);\n"; if (itype.is_instantiable) { // Add native constructor static field From 73dce3106455bf037ab19abc95baf819b3ca1b8c Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Fri, 25 Nov 2022 16:28:21 +0100 Subject: [PATCH 07/10] Fix ScriptSignalsGenerator not calling with params --- .../ScriptSignalsGenerator.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index 1fe6840c6b43..895c7bd62b00 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -227,23 +227,32 @@ INamedTypeSymbol symbol foreach (var signalDelegate in godotSignalDelegates) { string signalName = signalDelegate.Name; - - var paramsSb = new StringBuilder(); var parameters = signalDelegate.InvokeMethodData.Method.Parameters; + string @params = ""; + string paramsCall = ""; - for (int i = 0; i < parameters.Length; i++) + if (parameters.Length > 0) { - paramsSb.Append(parameters[i].ToString()) - .Append(" ") - .Append(parameters[i].Name.ToString()); + paramsCall += ", "; + + for (int i = 0; i < parameters.Length; i++) + { + @params += parameters[i].ToString() + + " " + + parameters[i].Name.ToString(); - if (i != parameters.Length - 1) - paramsSb.Append(", "); + paramsCall += parameters[i].Name.ToString(); + + if (i != parameters.Length - 1) + @params += ", "; + paramsCall += ", "; + } } + source.AppendLine($" /// <inheritdoc cref=\"{signalDelegate.DelegateSymbol.FullQualifiedName()}\"/>"); - source.Append($" public void {signalName}({paramsSb.ToString()})") - .AppendLine($" => bound.EmitSignal({symbol.NameWithTypeParameters()}.SignalName.{signalName});"); + source.Append($" public void {signalName}({@params})") + .AppendLine($" => bound.EmitSignal({symbol.NameWithTypeParameters()}.SignalName.{signalName}{paramsCall});"); } source.AppendLine(" }"); From 64bfebcddd44ecccad38c1fdbf561aeeaf9d5216 Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Fri, 25 Nov 2022 19:53:59 +0100 Subject: [PATCH 08/10] Update ScriptSignalsGenerator --- .../Godot.SourceGenerators/ScriptSignalsGenerator.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index 895c7bd62b00..ff70c80916d5 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -244,8 +244,10 @@ INamedTypeSymbol symbol paramsCall += parameters[i].Name.ToString(); if (i != parameters.Length - 1) + { @params += ", "; - paramsCall += ", "; + paramsCall += ", "; + } } } From bfb9c28ba31488089bfb37af5407f1df0d7a59fc Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Fri, 25 Nov 2022 20:41:17 +0100 Subject: [PATCH 09/10] =?UTF-8?q?Fix=20not=20passed=20test=20Seams=20like?= =?UTF-8?q?=20i=20accidently=20made=20something=20called=20Trigraph.=20?= =?UTF-8?q?=F0=9F=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mono/editor/bindings_generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 46c348e2c42b..8c98de7e3423 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1544,7 +1544,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str // Add Emit property output << MEMBER_BEGIN "private new SignalEmit _emit;\n" << MEMBER_BEGIN "/// <summary>A helper to quickly and safely emit signals.</summary>\n" - << MEMBER_BEGIN "public new SignalEmit Emit => _emit ??= new(this);\n"; + << MEMBER_BEGIN "public new SignalEmit Emit => _emit \?\?= new(this);\n"; if (itype.is_instantiable) { // Add native constructor static field From ffbd5187e29ee4085729c8b13e888af11ab751ba Mon Sep 17 00:00:00 2001 From: OlliDev <oliver.koenig.bi@gmail.com> Date: Fri, 25 Nov 2022 20:42:02 +0100 Subject: [PATCH 10/10] Remove new from _emit --- .../Godot.SourceGenerators/ScriptSignalsGenerator.cs | 2 +- modules/mono/editor/bindings_generator.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index ff70c80916d5..bec39e9f50bf 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -260,7 +260,7 @@ INamedTypeSymbol symbol source.AppendLine(" }"); // Generate the Emit property - source.AppendLine(" private new SignalEmit _emit;") + source.AppendLine(" private SignalEmit _emit;") .AppendLine(" /// <summary>A helper to quickly and safely emit signals.</summary>") .AppendLine(" public new SignalEmit Emit => _emit ??= new(this);"); diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 8c98de7e3423..e50d7f425c46 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1542,7 +1542,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str output.append("\";\n"); // Add Emit property - output << MEMBER_BEGIN "private new SignalEmit _emit;\n" + output << MEMBER_BEGIN "private SignalEmit _emit;\n" << MEMBER_BEGIN "/// <summary>A helper to quickly and safely emit signals.</summary>\n" << MEMBER_BEGIN "public new SignalEmit Emit => _emit \?\?= new(this);\n";