Skip to content

Commit 01463ea

Browse files
committed
fix: Property hints for objects in Lists
Property hints were not properly populating when lists held Objects, preventing proper assignment of in-scene nodes.
1 parent e5735a4 commit 01463ea

3 files changed

Lines changed: 32 additions & 13 deletions

File tree

src/dart/godot_dart/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- BREAKING: Change `Array` to `GDArray` to avoid collisions with `dart:ffi`'s `Array` attribute.
44
- Support `Iterable<T>` on both `Array` and `TypedArray`.
55
- Indexers on `TypedArray` are now support type safe retrieval.
6+
- Fix templates and README to correctly support hot reload.
67

78
## 0.13.1
89

src/dart/godot_dart_build/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.12.0
2+
3+
- Fix property hints for objects in lists.
4+
15
## 0.11.0
26

37
- Remove the need to specify signal names on `@GodotSignal`

src/dart/godot_dart_build/lib/src/godot_script_generator.dart

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,25 +350,24 @@ class GodotScriptAnnotationGenerator
350350
return type.element!.name!;
351351
}
352352

353-
if (element is ClassElement) {
354-
for (final supertype in element.allSupertypes) {
355-
if (supertype.element.name == 'Node') {
356-
return (
357-
hint: PropertyHint.nodeType,
358-
hintString: getScriptResourceForType(type)
359-
);
360-
} else if (supertype.element.name == 'Resource') {
361-
return (
362-
hint: PropertyHint.resourceType,
363-
hintString: getScriptResourceForType(type)
364-
);
365-
}
353+
if (element case ClassElement ce) {
354+
if (ce.isSubClassOf('Node')) {
355+
return (
356+
hint: PropertyHint.nodeType,
357+
hintString: getScriptResourceForType(type)
358+
);
359+
} else if (ce.isSubClassOf('Resource')) {
360+
return (
361+
hint: PropertyHint.resourceType,
362+
hintString: getScriptResourceForType(type)
363+
);
366364
}
367365
}
368366

369367
if (type.isDartCoreList) {
370368
final arrayElementType = (type as ParameterizedType).typeArguments.first;
371369
final arrayElementVariantType = _variantTypeForType(arrayElementType);
370+
372371
if (arrayElementVariantType != null) {
373372
final elementHint = _getPropertyHint(arrayElementType, packageName);
374373
if (elementHint != null) {
@@ -440,6 +439,10 @@ class GodotScriptAnnotationGenerator
440439
return VariantType.string;
441440
} else if (type.isDartCoreEnum) {
442441
return VariantType.integer;
442+
} else if (type.element case ClassElement ce) {
443+
if (ce.isSubClassOf('GodotObject')) {
444+
return VariantType.object;
445+
}
443446
}
444447

445448
const variantTypeMap = <String, VariantType>{
@@ -593,3 +596,14 @@ extension EnumHelper on ConstantReader {
593596
return values[index!];
594597
}
595598
}
599+
600+
extension InheritanceHelper on ClassElement {
601+
bool isSubClassOf(String superclass) {
602+
for (final supertype in allSupertypes) {
603+
if (supertype.element.name == superclass) {
604+
return true;
605+
}
606+
}
607+
return false;
608+
}
609+
}

0 commit comments

Comments
 (0)