Skip to content

Commit

Permalink
feat: Add parameters to Signals.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzybinary committed Nov 15, 2024
1 parent e0e1b5f commit 598cd82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/dart/godot_dart/lib/src/annotations/godot_script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ class GodotExport {
const GodotExport({this.name});
}

@immutable
class SignalArgument {
final String name;
final Type type;

const SignalArgument(this.name, this.type);
}

/// Annotate a Godot Signal
@immutable
class GodotSignal {
final String signalName;
final List<SignalArgument> args;

const GodotSignal(this.signalName);
const GodotSignal(this.signalName, {this.args = const []});
}

/// Annotate a field that should be visible to the Godot property inspector
Expand Down
12 changes: 10 additions & 2 deletions src/dart/godot_dart_build/lib/src/godot_script_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,16 @@ class GodotScriptAnnotationGenerator
final signalName = reader.read('signalName').stringValue;
buffer.writeln(' name: \'$signalName\',');

// TODO: Signals that take parameters....
buffer.writeln(' args: [],');
final signalArguments = reader.read('args').listValue;
buffer.writeln(' args: [');
for (final arg in signalArguments) {
final argReader = ConstantReader(arg);
final argName = argReader.read('name').stringValue;
final argType = argReader.read('type').typeValue;
buffer.writeln(
' PropertyInfo(name: \'${argName}\', typeInfo: ${_typeInfoForType(argType)}),');
}
buffer.writeln(']');
buffer.write(')');

return buffer.toString();
Expand Down

0 comments on commit 598cd82

Please sign in to comment.