Skip to content

Godot 4.2 / .net6 port #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: godot4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/quentincaffeino/array-utils/src/Collection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions addons/quentincaffeino/callback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion addons/quentincaffeino/callback/src/AbstractCallback.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func bind(argv = []):

# @param Variant[] argv
# @returns Variant
func call(argv = []):
func invoke_call(argv = []):
pass


Expand Down
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -15,11 +15,11 @@ 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 ])
return

# Execute call
return self._target.call_funcv(self._get_args(argv))
return self._target.call(self._get_args(argv))
3 changes: 1 addition & 2 deletions addons/quentincaffeino/callback/src/Callback.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

extends "./AbstractCallback.gd"


Expand Down Expand Up @@ -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 ])
Expand Down
8 changes: 4 additions & 4 deletions addons/quentincaffeino/callback/src/CallbackBuilder.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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;
}

Expand Down
13 changes: 10 additions & 3 deletions addons/quentincaffeino/console-csharp/src/Console.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Godot;
using System.IO;

public class Console : Node
public partial class Console : Node
{
CanvasLayer _console;

Expand All @@ -9,9 +10,15 @@ public override void _Ready()
_console = GetTree().Root.GetNode<CanvasLayer>("Console");
}

public CommandBuilder AddCommand(string name, Godot.Object target, string targetMethodName)
/// <summary>
/// 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
/// </summary>
public static TextWriter Error => System.Console.Error;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn that was quick, the Godot devs have fixed it already!


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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void
### call

```gdscript
func call(argv: Variant[])
func invoke_call(argv: Variant[])
```

Variant
2 changes: 1 addition & 1 deletion addons/quentincaffeino/console/docs/generated/Callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ boolean
### call

```gdscript
func call(argv: Variant[])
func invoke_call(argv: Variant[])
```

Variant
2 changes: 1 addition & 1 deletion addons/quentincaffeino/console/src/Command/Command.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func execute(inArgs = []):
i += 1

# Execute command
return self._target.call(args)
return self._target.invoke_call(args)


# @returns void
Expand Down
6 changes: 5 additions & 1 deletion addons/quentincaffeino/console/src/Console.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion addons/quentincaffeino/console/src/ConsoleLine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion addons/quentincaffeino/console/src/Misc/BaseCommands.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion addons/quentincaffeino/console/src/Type/IntType.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 2 additions & 2 deletions addons/quentincaffeino/iterator/src/Iterator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion demo-csharp/CSharpDemoScene.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Godot;

public class CSharpDemoScene : CanvasLayer
public partial class CSharpDemoScene : CanvasLayer
{
Console _wrapper;
Label _label;
Expand Down
10 changes: 5 additions & 5 deletions demo-csharp/Demo-csharp.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Godot.NET.Sdk/3.3.0">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<RootNamespace>Democsharp</RootNamespace>
</PropertyGroup>
<Project Sdk="Godot.NET.Sdk/4.0.0">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Democsharp</RootNamespace>
</PropertyGroup>
</Project>