From 2e15416a4ad6f6212eeac62260c9bcf5139a6271 Mon Sep 17 00:00:00 2001 From: Treer Date: Wed, 1 Feb 2023 02:06:12 +1100 Subject: [PATCH 1/5] Godot 4 Beta 16, .net6 compatibility --- .../console-csharp/src/Command/CommandBuilder.cs | 8 ++++---- .../quentincaffeino/console-csharp/src/Console.cs | 13 ++++++++++--- .../console/src/Misc/BaseCommands.gd | 2 +- addons/quentincaffeino/console/src/Type/IntType.gd | 2 +- demo-csharp/CSharpDemoScene.cs | 2 +- demo-csharp/Demo-csharp.csproj | 4 ++-- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/addons/quentincaffeino/console-csharp/src/Command/CommandBuilder.cs b/addons/quentincaffeino/console-csharp/src/Command/CommandBuilder.cs index f14ae6c..3cf795e 100644 --- a/addons/quentincaffeino/console-csharp/src/Command/CommandBuilder.cs +++ b/addons/quentincaffeino/console-csharp/src/Command/CommandBuilder.cs @@ -1,10 +1,10 @@ using Godot; -public class CommandBuilder : Godot.Object +public partial class CommandBuilder : GodotObject { - private Godot.Object _commandObject; + private GodotObject _commandObject; - public CommandBuilder(Godot.Object commandObject) + public CommandBuilder(GodotObject commandObject) { _commandObject = commandObject; } @@ -17,7 +17,7 @@ public CommandBuilder SetDescription(string description) public CommandBuilder AddArgument(string argumentName, Variant.Type argumentType) { - _commandObject.Call("add_argument", argumentName, argumentType); + _commandObject.Call("add_argument", argumentName, (long)argumentType); return this; } diff --git a/addons/quentincaffeino/console-csharp/src/Console.cs b/addons/quentincaffeino/console-csharp/src/Console.cs index c36f839..51ee002 100644 --- a/addons/quentincaffeino/console-csharp/src/Console.cs +++ b/addons/quentincaffeino/console-csharp/src/Console.cs @@ -1,6 +1,7 @@ using Godot; +using System.IO; -public class Console : Node +public partial class Console : Node { CanvasLayer _console; @@ -9,9 +10,15 @@ public override void _Ready() _console = GetTree().Root.GetNode("Console"); } - public CommandBuilder AddCommand(string name, Godot.Object target, string targetMethodName) + /// + /// This is a hack until we can fix the code generated by GodotPluginsInitializerGenerator to specify it means System.Console not this Console + /// https://github.com/godotengine/godot/pull/72434 + /// + public static TextWriter Error => System.Console.Error; + + public CommandBuilder AddCommand(string name, GodotObject target, string targetMethodName) { - Godot.Object consoleCommand = _console.Call("add_command", name, target, targetMethodName) as Godot.Object; + GodotObject consoleCommand = _console.Call("add_command", name, target, targetMethodName).Obj as GodotObject; return new CommandBuilder(consoleCommand); } } diff --git a/addons/quentincaffeino/console/src/Misc/BaseCommands.gd b/addons/quentincaffeino/console/src/Misc/BaseCommands.gd index b943dbb..aab23e8 100644 --- a/addons/quentincaffeino/console/src/Misc/BaseCommands.gd +++ b/addons/quentincaffeino/console/src/Misc/BaseCommands.gd @@ -40,7 +40,7 @@ func _init(console): .set_description('Shows engine version.')\ .register() - self._console.add_command('fps_max', Engine, 'set_target_fps')\ + self._console.add_command('max_fps', Engine)\ .set_description('The maximal framerate at which the application can run.')\ .add_argument('fps', self._console.IntRangeType.new(10, 1000))\ .register() diff --git a/addons/quentincaffeino/console/src/Type/IntType.gd b/addons/quentincaffeino/console/src/Type/IntType.gd index f829cba..68a37c8 100644 --- a/addons/quentincaffeino/console/src/Type/IntType.gd +++ b/addons/quentincaffeino/console/src/Type/IntType.gd @@ -9,4 +9,4 @@ func _init(): # @param Variant value # @returns int func normalize(value): - return int(self._reextract(value)) + return self._reextract(value).to_int(); diff --git a/demo-csharp/CSharpDemoScene.cs b/demo-csharp/CSharpDemoScene.cs index 1a74812..3850752 100644 --- a/demo-csharp/CSharpDemoScene.cs +++ b/demo-csharp/CSharpDemoScene.cs @@ -1,6 +1,6 @@ using Godot; -public class CSharpDemoScene : CanvasLayer +public partial class CSharpDemoScene : CanvasLayer { Console _wrapper; Label _label; diff --git a/demo-csharp/Demo-csharp.csproj b/demo-csharp/Demo-csharp.csproj index 7a948bb..5e59797 100644 --- a/demo-csharp/Demo-csharp.csproj +++ b/demo-csharp/Demo-csharp.csproj @@ -1,6 +1,6 @@ - + - net472 + net6.0 Democsharp \ No newline at end of file From c879863616ffd31a4491662af5d4ab0e2d7fe2de Mon Sep 17 00:00:00 2001 From: Treer Date: Thu, 2 Mar 2023 23:16:40 +1100 Subject: [PATCH 2/5] Godot 4.0 compatibility FuncRefs are replaced by Callables, and there's a change to array syntax The demo projects will still need attention, but the console works in Godot 4. --- .../src/{FuncRefCallback.gd => CallableCallback.gd} | 6 +++--- addons/quentincaffeino/callback/src/CallbackBuilder.gd | 8 ++++---- addons/quentincaffeino/console/src/ConsoleLine.gd | 2 +- demo-csharp/Demo-csharp.csproj | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) rename addons/quentincaffeino/callback/src/{FuncRefCallback.gd => CallableCallback.gd} (77%) diff --git a/addons/quentincaffeino/callback/src/FuncRefCallback.gd b/addons/quentincaffeino/callback/src/CallableCallback.gd similarity index 77% rename from addons/quentincaffeino/callback/src/FuncRefCallback.gd rename to addons/quentincaffeino/callback/src/CallableCallback.gd index c78c557..3d08bf4 100644 --- a/addons/quentincaffeino/callback/src/FuncRefCallback.gd +++ b/addons/quentincaffeino/callback/src/CallableCallback.gd @@ -1,8 +1,8 @@ - +# Wraps a Callable inside a Callback instance extends "./AbstractCallback.gd" -# @param FuncRef target +# @param Callable target func _init(target): super(target, Utils.Type.METHOD) @@ -22,4 +22,4 @@ func call(argv = []): return # Execute call - return self._target.call_funcv(self._get_args(argv)) + return self._target.call(self._get_args(argv)) diff --git a/addons/quentincaffeino/callback/src/CallbackBuilder.gd b/addons/quentincaffeino/callback/src/CallbackBuilder.gd index 5324dd8..81dd49f 100644 --- a/addons/quentincaffeino/callback/src/CallbackBuilder.gd +++ b/addons/quentincaffeino/callback/src/CallbackBuilder.gd @@ -3,7 +3,7 @@ extends RefCounted const Utils = preload("./Utils.gd") const Callback = preload("./Callback.gd") -const FuncRefCallback = preload("./FuncRefCallback.gd") +const CallableCallback = preload("./CallableCallback.gd") const errors = preload("../assets/translations/errors.en.gd").messages @@ -72,13 +72,13 @@ func bind(argv = []): # @returns Callback|null func build(): + if self._target is Callable: + return CallableCallback.new(self._target) + if typeof(self._target) != TYPE_OBJECT: print(errors["qc.callback.canCreate.first_arg"] % str(typeof(self._target))) return null - if Utils.is_funcref(self._target): - return FuncRefCallback.new(self._target) - if typeof(self._name) != TYPE_STRING: print(errors["qc.callback.canCreate.second_arg"] % str(typeof(self._name))) return null diff --git a/addons/quentincaffeino/console/src/ConsoleLine.gd b/addons/quentincaffeino/console/src/ConsoleLine.gd index 3ab68b4..77392b6 100644 --- a/addons/quentincaffeino/console/src/ConsoleLine.gd +++ b/addons/quentincaffeino/console/src/ConsoleLine.gd @@ -143,7 +143,7 @@ static func _parse_commands(input): # @returns Dictionary static func _parse_command(rawCommand): var name = '' - var arguments: Array[String] = Array() + var arguments: Array[String] = [] var beginning = 0 # int var openQuote # String|null diff --git a/demo-csharp/Demo-csharp.csproj b/demo-csharp/Demo-csharp.csproj index 5e59797..61080e4 100644 --- a/demo-csharp/Demo-csharp.csproj +++ b/demo-csharp/Demo-csharp.csproj @@ -1,6 +1,6 @@ - - - net6.0 - Democsharp - + + + net6.0 + Democsharp + \ No newline at end of file From a7d92329ec3957c5734a58b9f851b4af36b91c48 Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 21 Jan 2024 13:16:50 +1100 Subject: [PATCH 3/5] Godot 4.2 compatibility Renames call() to invoke_call() to avoid "The function signature doesn't match the parent" errors. Since gdscript doesn't support function overloading, classes can no longer have a method named "call" because the Object class has one. --- addons/quentincaffeino/array-utils/src/Collection.gd | 4 ++-- addons/quentincaffeino/callback/README.md | 10 +++++----- .../quentincaffeino/callback/src/AbstractCallback.gd | 2 +- .../quentincaffeino/callback/src/CallableCallback.gd | 2 +- addons/quentincaffeino/callback/src/Callback.gd | 3 +-- .../console/docs/generated/AbstractCallback.md | 2 +- .../quentincaffeino/console/docs/generated/Callback.md | 2 +- addons/quentincaffeino/console/src/Command/Command.gd | 2 +- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/quentincaffeino/array-utils/src/Collection.gd b/addons/quentincaffeino/array-utils/src/Collection.gd index 3049d94..8692e85 100644 --- a/addons/quentincaffeino/array-utils/src/Collection.gd +++ b/addons/quentincaffeino/array-utils/src/Collection.gd @@ -195,7 +195,7 @@ func fill(value = null, startIndex = 0, length = null): # @returns Collection func map(callback): for key in self: - self._collection[key] = callback.call([self._collection[key], key, self._collection]) + self._collection[key] = callback.invoke_call([self._collection[key], key, self._collection]) self.first() return self @@ -214,7 +214,7 @@ func filter(callback = null): var key = new_collection.get_keys()[i] var value = new_collection.get(key) - call = callback.call([key, value, i, new_collection]) + call = callback.invoke_call([key, value, i, new_collection]) if !call: new_collection.remove_by_index(i) diff --git a/addons/quentincaffeino/callback/README.md b/addons/quentincaffeino/callback/README.md index dd574b0..1bcd019 100644 --- a/addons/quentincaffeino/callback/README.md +++ b/addons/quentincaffeino/callback/README.md @@ -22,13 +22,13 @@ func _ready(): # void var func_cb = CallbackBuilder.new(self).set_name("callable_function").build() var funcref_cb = CallbackBuilder.new(funcref(self, "callable_function")).build() - print(prop_cb.call()) # Prints: Hello world! + print(prop_cb.invoke_call()) # Prints: Hello world! - print(func_cb.call(["Hello, sam!"])) # Prints: [Reference...] - print(prop_cb.call()) # Prints: Hello, sam! + print(func_cb.invoke_call(["Hello, sam!"])) # Prints: [Reference...] + print(prop_cb.invoke_call()) # Prints: Hello, sam! - print(funcref_cb.call(["Hello, peter!"])) # Prints: [Reference...] - print(prop_cb.call()) # Prints: Hello, peter! + print(funcref_cb.invoke_call(["Hello, peter!"])) # Prints: [Reference...] + print(prop_cb.invoke_call()) # Prints: Hello, peter! ``` ## License diff --git a/addons/quentincaffeino/callback/src/AbstractCallback.gd b/addons/quentincaffeino/callback/src/AbstractCallback.gd index 649e35a..f71096e 100755 --- a/addons/quentincaffeino/callback/src/AbstractCallback.gd +++ b/addons/quentincaffeino/callback/src/AbstractCallback.gd @@ -48,7 +48,7 @@ func bind(argv = []): # @param Variant[] argv # @returns Variant -func call(argv = []): +func invoke_call(argv = []): pass diff --git a/addons/quentincaffeino/callback/src/CallableCallback.gd b/addons/quentincaffeino/callback/src/CallableCallback.gd index 3d08bf4..397685f 100644 --- a/addons/quentincaffeino/callback/src/CallableCallback.gd +++ b/addons/quentincaffeino/callback/src/CallableCallback.gd @@ -15,7 +15,7 @@ func ensure(): # @param Variant[] argv # @returns Variant -func call(argv = []): +func invoke_call(argv = []): # Ensure callback target still exists if !ensure(): print(errors["qc.callback.call.ensure_failed"] % [ self._target ]) diff --git a/addons/quentincaffeino/callback/src/Callback.gd b/addons/quentincaffeino/callback/src/Callback.gd index 2adb1f1..2601273 100644 --- a/addons/quentincaffeino/callback/src/Callback.gd +++ b/addons/quentincaffeino/callback/src/Callback.gd @@ -1,4 +1,3 @@ - extends "./AbstractCallback.gd" @@ -40,7 +39,7 @@ func ensure(): # @param Variant[] argv # @returns Variant -func call(argv = []): +func invoke_call(argv = []): # Ensure callback target still exists if !ensure(): print(errors["qc.callback.call.ensure_failed"] % [ self._target, self._name ]) diff --git a/addons/quentincaffeino/console/docs/generated/AbstractCallback.md b/addons/quentincaffeino/console/docs/generated/AbstractCallback.md index d837f03..2e303b3 100644 --- a/addons/quentincaffeino/console/docs/generated/AbstractCallback.md +++ b/addons/quentincaffeino/console/docs/generated/AbstractCallback.md @@ -58,7 +58,7 @@ void ### call ```gdscript -func call(argv: Variant[]) +func invoke_call(argv: Variant[]) ``` Variant \ No newline at end of file diff --git a/addons/quentincaffeino/console/docs/generated/Callback.md b/addons/quentincaffeino/console/docs/generated/Callback.md index 2ae8eb5..0a457d6 100644 --- a/addons/quentincaffeino/console/docs/generated/Callback.md +++ b/addons/quentincaffeino/console/docs/generated/Callback.md @@ -34,7 +34,7 @@ boolean ### call ```gdscript -func call(argv: Variant[]) +func invoke_call(argv: Variant[]) ``` Variant \ No newline at end of file diff --git a/addons/quentincaffeino/console/src/Command/Command.gd b/addons/quentincaffeino/console/src/Command/Command.gd index f007806..cdab8c7 100644 --- a/addons/quentincaffeino/console/src/Command/Command.gd +++ b/addons/quentincaffeino/console/src/Command/Command.gd @@ -69,7 +69,7 @@ func execute(inArgs = []): i += 1 # Execute command - return self._target.call(args) + return self._target.invoke_call(args) # @returns void From ab3252f67eb4081b8f0a68220773ebdfb4ffd8fa Mon Sep 17 00:00:00 2001 From: Treer Date: Wed, 26 Mar 2025 23:54:18 +1100 Subject: [PATCH 4/5] part of last commit commit missing changes that were supposed to be part of a7d92329e --- addons/quentincaffeino/iterator/src/Iterator.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/quentincaffeino/iterator/src/Iterator.gd b/addons/quentincaffeino/iterator/src/Iterator.gd index 0bc52d9..6bc48f2 100644 --- a/addons/quentincaffeino/iterator/src/Iterator.gd +++ b/addons/quentincaffeino/iterator/src/Iterator.gd @@ -31,13 +31,13 @@ func _init(target, get_value_field = "get", get_length_field = "size"): # @returns int func _length(): - return self._object_get_length_cb.call() + return self._object_get_length_cb.invoke_call() # @param int index # @returns Variant func _get(index): - return self._object_get_value_cb.call([index]) + return self._object_get_value_cb.invoke_call([index]) # Sets the internal iterator to the first element in the collection and returns this element. From 6db2394573eed3918a211d81906fcbd13e977554 Mon Sep 17 00:00:00 2001 From: Treer Date: Sat, 29 Mar 2025 20:32:41 +1100 Subject: [PATCH 5/5] Fix commandline focus issues I'm not sure whether it's due to changes in Godot version, but the console text edit field kept failing to have focus unless you clicked in it. These changes seem to be sufficient to fix that. --- addons/quentincaffeino/console/src/Console.gd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/quentincaffeino/console/src/Console.gd b/addons/quentincaffeino/console/src/Console.gd index 6277c98..543a125 100644 --- a/addons/quentincaffeino/console/src/Console.gd +++ b/addons/quentincaffeino/console/src/Console.gd @@ -78,6 +78,10 @@ func _ready(): # React to clicks on console urls self.Text.connect("meta_clicked", self.Line.set_text) + self.Text.focus_entered.connect(func(): + self.Line.grab_focus() + ) + # Hide console by default self._console_box.hide() self._animation_player.connect("animation_finished", _toggle_animation_finished) @@ -188,7 +192,7 @@ func open(): previous_focus_owner = self.Line.get_viewport().gui_get_focus_owner() self._console_box.show() self.Line.clear() - self.Line.grab_focus() + self.Line.grab_focus.call_deferred() self._animation_player.play_backwards('fade') is_console_shown = true emit_signal("toggled", is_console_shown)