Skip to content

Commit 2073ac9

Browse files
fix: @ExportObject(Node). Was only working for sub-classes.
1 parent 4bb388b commit 2073ac9

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@godot-js/editor": patch
3+
---
4+
5+
**Fix:** `@ExportObject(Node)` was only working for sub-classes, not `Node` itself.

scripts/jsb.runtime/src/godot.annotations.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as Godot from "godot";
22
import type * as GodotJsb from "godot-jsb";
33

4-
const { jsb, FloatType, IntegerType, Node, PropertyHint, PropertyUsageFlags, Resource, Variant } = require("godot.lib.api");
4+
const { jsb, FloatType, IntegerType, Node, PropertyHint, PropertyUsageFlags, ProxyTarget, Resource, Variant } = require("godot.lib.api");
55

66
function guess_type_name(type: any) {
77
if (typeof type === "function") {
@@ -146,12 +146,14 @@ function get_hint_string(clazz: any): string {
146146
}
147147
}
148148

149-
if (typeof clazz === "function" && typeof clazz.prototype !== "undefined") {
150-
if (clazz.prototype instanceof Resource) {
149+
if (typeof clazz === "function") {
150+
const prototype = clazz.prototype;
151+
152+
if (prototype instanceof Resource) {
151153
return `${Variant.Type.TYPE_OBJECT}/${PropertyHint.PROPERTY_HINT_RESOURCE_TYPE}:${clazz.name}`;
152-
} else if (clazz.prototype instanceof Node) {
154+
} else if (prototype instanceof Node || ((clazz as any)[ProxyTarget] ?? clazz) === (Node[ProxyTarget] ?? Node)) {
153155
return `${Variant.Type.TYPE_OBJECT}/${PropertyHint.PROPERTY_HINT_NODE_TYPE}:${clazz.name}`;
154-
} else {
156+
} else if (typeof prototype !== "undefined") {
155157
// other than Resource and Node, only primitive types and enum types are supported in gdscript
156158
//TODO but we barely know anything about the enum types and int/float/StringName/... in JS
157159

@@ -216,12 +218,14 @@ export function export_(type: Godot.Variant.Type, details?: { class_?: ClassDesc
216218

217219
if (type === Variant.Type.TYPE_OBJECT) {
218220
const clazz = details.class_;
219-
if (typeof clazz === "function" && typeof clazz.prototype !== "undefined") {
220-
if (clazz.prototype instanceof Resource) {
221+
if (typeof clazz === "function") {
222+
const prototype = clazz.prototype;
223+
224+
if (prototype instanceof Resource) {
221225
ebd.hint = PropertyHint.PROPERTY_HINT_RESOURCE_TYPE;
222226
ebd.hint_string = clazz.name;
223227
ebd.usage |= PropertyUsageFlags.PROPERTY_USAGE_SCRIPT_VARIABLE;
224-
} else if (clazz.prototype instanceof Node) {
228+
} else if (prototype instanceof Node || ((clazz as any)[ProxyTarget] ?? clazz) === (Node[ProxyTarget] ?? Node)) {
225229
ebd.hint = PropertyHint.PROPERTY_HINT_NODE_TYPE;
226230
ebd.hint_string = clazz.name;
227231
ebd.usage |= PropertyUsageFlags.PROPERTY_USAGE_SCRIPT_VARIABLE;

0 commit comments

Comments
 (0)