1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Misc improvements to the GodotPlugin API

- Add overload method for `GodotPlugin#emitSignal(...)`
- Allow passing `null` values as signal arguments
This commit is contained in:
Fredia Huya-Kouadio
2025-10-01 13:26:41 -07:00
committed by Fredia Huya-Kouadio
parent caefb0f1c1
commit b9c3b1d4c0
6 changed files with 44 additions and 45 deletions

View File

@@ -361,7 +361,7 @@ public abstract class GodotPlugin {
/**
* Emit a registered Godot signal.
* @param signalName Name of the signal to emit. It will be validated against the set of registered signals.
* @param signalArgs Arguments used to populate the emitted signal. The arguments will be validated against the {@link SignalInfo} matching the registered signalName parameter.
* @param signalArgs Arguments used to populate the emitted signal. The arguments will be validated against the registered {@link SignalInfo} matching the signalName parameter.
*/
protected void emitSignal(final String signalName, final Object... signalArgs) {
try {
@@ -380,6 +380,15 @@ public abstract class GodotPlugin {
}
}
/**
* Emit a registered Godot signal.
* @param signal Signal to emit. It will be validated against the set of registered signals.
* @param signalArgs Arguments used to populate the emitted signal. The arguments will be validated against the registered {@link SignalInfo} matching the signal parameter.
*/
protected void emitSignal(SignalInfo signal, final Object... signalArgs) {
emitSignal(signal.getName(), signalArgs);
}
/**
* Emit a Godot signal.
* @param godot Godot instance
@@ -402,7 +411,8 @@ public abstract class GodotPlugin {
// Validate the argument's types.
for (int i = 0; i < signalParamTypes.length; i++) {
if (!signalParamTypes[i].isInstance(signalArgs[i])) {
Object signalArg = signalArgs[i];
if (signalArg != null && !signalParamTypes[i].isInstance(signalArg)) {
throw new IllegalArgumentException(
"Invalid type for argument #" + i + ". Should be of type " + signalParamTypes[i].getName());
}