From 5535ff352b7f6db711317d2928b070c6443b3a12 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Tue, 29 Oct 2024 22:38:56 -0400 Subject: [PATCH] feat: Add correct default hint for Nodes and Resource properties. The generator now checks for Node and Resource subclasses and adds the correct property hint and hintString. This also fixes an issue where property hints weren't correctly translated from Dart to C. --- src/cpp/gde_dart_converters.cpp | 10 +- src/cpp/script/dart_script.cpp | 108 +++++++++++------- src/cpp/script/dart_script.h | 10 +- src/cpp/script/dart_script_instance.cpp | 73 +++--------- src/dart/godot_dart_build/CHANGELOG.md | 4 + .../lib/src/godot_script_generator.dart | 22 ++++ src/dart/godot_dart_build/pubspec.yaml | 6 +- 7 files changed, 126 insertions(+), 107 deletions(-) diff --git a/src/cpp/gde_dart_converters.cpp b/src/cpp/gde_dart_converters.cpp index 3cd3af5..86f2eae 100644 --- a/src/cpp/gde_dart_converters.cpp +++ b/src/cpp/gde_dart_converters.cpp @@ -2,8 +2,8 @@ #include -#include "dart_helpers.h" #include "dart_bindings.h" +#include "dart_helpers.h" #include "gde_wrapper.h" #include "godot_string_wrappers.h" @@ -25,7 +25,7 @@ void *get_object_address(Dart_Handle engine_handle) { } void gde_method_info_from_dart(Dart_Handle dart_method_info, GDExtensionMethodInfo *method_info) { - DART_CHECK(dart_name, Dart_GetField(dart_method_info, Dart_NewStringFromCString("name")), "Failed to get name"); + DART_CHECK(dart_name, Dart_GetField(dart_method_info, Dart_NewStringFromCString("name")), "Failed to get name"); method_info->name = create_godot_string_name_ptr(dart_name); // TODO: id? method_info->id = 0; @@ -61,7 +61,7 @@ void gde_method_info_from_dart(Dart_Handle dart_method_info, GDExtensionMethodIn void gde_free_method_info_fields(GDExtensionMethodInfo *method_info) { if (method_info->name != nullptr) { - delete reinterpret_cast(method_info->name); + delete reinterpret_cast(method_info->name); } gde_free_property_info_fields(&method_info->return_value); @@ -89,8 +89,10 @@ void gde_property_info_from_dart(Dart_Handle dart_property_info, GDExtensionProp DART_CHECK(dart_property_hint, Dart_GetField(dart_property_info, Dart_NewStringFromCString("hint")), "Failed to get hint"); + DART_CHECK(dart_hint_value, Dart_GetField(dart_property_hint, Dart_NewStringFromCString("value")), + "Failed to get PropertyHint.value"); uint64_t hint = 0; - Dart_IntegerToUint64(dart_property_hint, &hint); + Dart_IntegerToUint64(dart_hint_value, &hint); prop_info->hint = uint32_t(hint); DART_CHECK(dart_hint_string, Dart_GetField(dart_property_info, Dart_NewStringFromCString("hintString")), diff --git a/src/cpp/script/dart_script.cpp b/src/cpp/script/dart_script.cpp index 8f4d77f..5a6400b 100644 --- a/src/cpp/script/dart_script.cpp +++ b/src/cpp/script/dart_script.cpp @@ -1,16 +1,16 @@ #include "dart_script.h" -#include -#include #include #include +#include +#include #include "../dart_bindings.h" #include "../dart_helpers.h" #include "../godot_string_wrappers.h" -#include "script/dart_script_language.h" #include "script/dart_script_instance.h" +#include "script/dart_script_language.h" using namespace godot; @@ -18,6 +18,8 @@ DartScript::DartScript() : _source_code(), _needs_refresh(false), _dart_type(nul } DartScript::~DartScript() { + clear_property_cache(); + GodotDartBindings *bindings = GodotDartBindings::instance(); if (bindings == nullptr) { return; @@ -39,7 +41,7 @@ void DartScript::_bind_methods() { } godot::Ref