Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-hoops-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@godot-js/editor": patch
---

fix: issues for annotations (@icon, @help, @deprecated, @experimental)
10 changes: 9 additions & 1 deletion bridge/jsb_class_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,15 @@ namespace jsb
v8::Local<v8::Value> signal_name_js = collection->Get(p_context, index).ToLocalChecked();
jsb_check(signal_name_js->IsString());
const StringName signal_name = environment->get_string_name_cache().get_string_name(isolate, signal_name_js.As<v8::String>());
p_class_info->signals.insert(signal_name, {});

ScriptSignalInfo signal_info = {};
#ifdef TOOLS_ENABLED
if (v8::Local<v8::Value> val; !doc_map.IsEmpty() && doc_map->Get(p_context, signal_name_js).ToLocal(&val) && val->IsObject())
{
_parse_script_doc(isolate, p_context, val, signal_info.doc);
}
#endif // TOOLS_ENABLED
p_class_info->signals.insert(signal_name, signal_info);

// instantiate a fake Signal property
//NOTE: we use JS string representation of signal name for info.Data() to avoid persistent StringNameID requirement.
Expand Down
4 changes: 4 additions & 0 deletions bridge/jsb_class_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ namespace jsb
struct ScriptClassDoc : ScriptBaseDoc {};
struct ScriptMethodDoc : ScriptBaseDoc {};
struct ScriptPropertyDoc : ScriptBaseDoc {};
struct ScriptSignalDoc : ScriptBaseDoc {};
#else
struct ScriptClassDoc {};
struct ScriptMethodDoc {};
struct ScriptPropertyDoc {};
struct ScriptSignalDoc {};
#endif

namespace ScriptMethodFlags
Expand All @@ -126,6 +128,8 @@ namespace jsb

struct ScriptSignalInfo
{
// only valid with TOOLS_ENABLED
ScriptSignalDoc doc;
};

struct ScriptMethodInfo
Expand Down
158 changes: 109 additions & 49 deletions scripts/jsb.editor/src/jsb.editor.codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ const annotation_types = {
type: DescriptorType.Godot,
name: "string",
},
{ type: DescriptorType.Godot, name: "ClassMethodDecoratorContext" },
{ type: DescriptorType.Godot, name: "ClassFieldDecoratorContext" },
],
},
},
Expand All @@ -1895,23 +1895,43 @@ const annotation_types = {
{ name: "message", type: { type: DescriptorType.Godot, name: "string" }, optional: true },
],
returns: {
type: DescriptorType.Godot,
name: "Decorator",
arguments: [
type: DescriptorType.FunctionLiteral,
parameters: [
{
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "ClassDecoratorContext",
arguments: [{ type: DescriptorType.Godot, name: "GObjectConstructor" }],
},
{
type: DescriptorType.Godot,
name: "ClassValueMemberDecoratorContext",
arguments: [{ type: DescriptorType.Godot, name: "GObjectConstructor" }],
},
],
name: "target",
type: {
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "GObject",
},
{
type: DescriptorType.Godot,
name: "GObjectConstructor",
},
],
},
},
{
name: "context",
type: {
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "ClassDecoratorContext",
},
{
type: DescriptorType.Godot,
name: "ClassValueMemberDecoratorContext",
},
{
type: DescriptorType.Godot,
name: "ClassMethodDecoratorContext",
},
],
},
},
],
},
Expand All @@ -1922,23 +1942,43 @@ const annotation_types = {
{ name: "message", type: { type: DescriptorType.Godot, name: "string" }, optional: true },
],
returns: {
type: DescriptorType.Godot,
name: "Decorator",
arguments: [
type: DescriptorType.FunctionLiteral,
parameters: [
{
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "ClassDecoratorContext",
arguments: [{ type: DescriptorType.Godot, name: "GObjectConstructor" }],
},
{
type: DescriptorType.Godot,
name: "ClassValueMemberDecoratorContext",
arguments: [{ type: DescriptorType.Godot, name: "GObjectConstructor" }],
},
],
name: "target",
type: {
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "GObject",
},
{
type: DescriptorType.Godot,
name: "GObjectConstructor",
},
],
},
},
{
name: "context",
type: {
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "ClassDecoratorContext",
},
{
type: DescriptorType.Godot,
name: "ClassValueMemberDecoratorContext",
},
{
type: DescriptorType.Godot,
name: "ClassMethodDecoratorContext",
},
],
},
},
],
},
Expand All @@ -1949,23 +1989,43 @@ const annotation_types = {
{ name: "message", type: { type: DescriptorType.Godot, name: "string" }, optional: true },
],
returns: {
type: DescriptorType.Godot,
name: "Decorator",
arguments: [
type: DescriptorType.FunctionLiteral,
parameters: [
{
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "ClassDecoratorContext",
arguments: [{ type: DescriptorType.Godot, name: "GObjectConstructor" }],
},
{
type: DescriptorType.Godot,
name: "ClassValueMemberDecoratorContext",
arguments: [{ type: DescriptorType.Godot, name: "GObjectConstructor" }],
},
],
name: "target",
type: {
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "GObject",
},
{
type: DescriptorType.Godot,
name: "GObjectConstructor",
},
],
},
},
{
name: "context",
type: {
type: DescriptorType.Union,
types: [
{
type: DescriptorType.Godot,
name: "ClassDecoratorContext",
},
{
type: DescriptorType.Godot,
name: "ClassValueMemberDecoratorContext",
},
{
type: DescriptorType.Godot,
name: "ClassMethodDecoratorContext",
},
],
},
},
],
},
Expand Down
12 changes: 6 additions & 6 deletions scripts/jsb.runtime/src/godot.annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,8 @@ export function createClassBinder(): ClassBinder {

deprecated(message?: string) {
return function (
target: GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext,
target: Godot.Object | GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext | ClassMethodDecoratorContext,
) {
if (typeof context !== "object") {
throw new Error(
Expand All @@ -1132,8 +1132,8 @@ export function createClassBinder(): ClassBinder {
},
experimental(message?: string) {
return function (
target: GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext,
target: Godot.Object | GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext | ClassMethodDecoratorContext,
) {
if (typeof context !== "object") {
throw new Error(
Expand All @@ -1157,8 +1157,8 @@ export function createClassBinder(): ClassBinder {
},
help(message?: string) {
return function (
target: GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext,
target: Godot.Object | GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext | ClassMethodDecoratorContext,
) {
if (typeof context !== "object") {
throw new Error(
Expand Down
15 changes: 12 additions & 3 deletions scripts/typings/godot.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,13 +1227,22 @@ declare module "godot.annotations" {
) => (_target: undefined, context: string | ClassFieldDecoratorContext) => void;
deprecated: (
message?: string,
) => (target: GObjectConstructor, context: ClassDecoratorContext | ClassValueMemberDecoratorContext) => void;
) => (
target: GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext | ClassMethodDecoratorContext,
) => void;
experimental: (
message?: string,
) => (target: GObjectConstructor, context: ClassDecoratorContext | ClassValueMemberDecoratorContext) => void;
) => (
target: GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext | ClassMethodDecoratorContext,
) => void;
help: (
message?: string,
) => (target: GObjectConstructor, context: ClassDecoratorContext | ClassValueMemberDecoratorContext) => void;
) => (
target: GObjectConstructor,
context: ClassDecoratorContext | ClassValueMemberDecoratorContext | ClassMethodDecoratorContext,
) => void;
};

type ExportOptions = {
Expand Down
1 change: 1 addition & 0 deletions tests/project/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions tests/project/assets/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://0312tiuxwg17"
path="res://.godot/imported/icon.svg-56083ea2a1f1a4f1e49773bdc6d7826c.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/icon.svg"
dest_files=["res://.godot/imported/icon.svg-56083ea2a1f1a4f1e49773bdc6d7826c.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
5 changes: 5 additions & 0 deletions tests/project/gen/godot/assets/icon.svg.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "godot" {
interface ResourceTypes {
"res://assets/icon.svg": CompressedTexture2D;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "godot" {
interface SceneNodes {
"tests/annotations/Annotations.tscn": { Label: Label<{}>; };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Annotations from "../../../../tests/annotations/annotations";
declare module "godot" {
interface ResourceTypes {
"res://tests/annotations/Annotations.tscn": PackedScene<Annotations>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "godot" {
interface ResourceTypes {
"res://tests/annotations/annotations.ts": Script;
}
}
11 changes: 11 additions & 0 deletions tests/project/tests/annotations/Annotations.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://dg678hkmjdk8q"]

[ext_resource type="Script" uid="uid://crxgru6txypvq" path="res://tests/annotations/annotations.ts" id="1_wypiw"]

[node name="Annotations" type="Node2D"]
script = ExtResource("1_wypiw")

[node name="Label" type="Label" parent="."]
offset_right = 40.0
offset_bottom = 23.0
text = "Annotations"
Loading
Loading