Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Add PropertyHint.Enum support to Array<StringName> #78264

Merged
merged 1 commit into from
Jul 18, 2023

Conversation

magian1127
Copy link
Contributor

Previously, only StringName was supported but not Array<StringName>, now it has been added.

    [Export(PropertyHint.Enum, "a,b,c")]
    public Godot.Collections.Array<StringName> Tests

@magian1127 magian1127 requested a review from a team as a code owner June 15, 2023 08:06
@akien-mga akien-mga added this to the 4.2 milestone Jun 15, 2023
Copy link
Member

@RedworkDE RedworkDE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected, code change looks good.

@akien-mga
Copy link
Member

Out of curiosity, is this feature supported in GDScript? I don't see it in the docs / can't find intuitively how to use it for an Array[String] or Array[StringName].

@RedworkDE
Copy link
Member

RedworkDE commented Jul 7, 2023

I don't think it is, beyond manually defining an appropriate PROPERTY_HINT_TYPE_STRING for a property using _get_property_list.

Edit: gdscript doesn't even support the enum annotation on StringName.

@magian1127
Copy link
Contributor Author

gds 3.5 export support Array[String] .
4.x ......

@raulsntos
Copy link
Member

GDScript doesn't support this, but there's an open PR:

It seems to support Array[int], Array[String] and Array[T] where T is an enum.
But it doesn't seem to support Array[StringName]. It may be an oversight, specially since String and StringName are pretty much interchangeable in GDScript, I'd expect both to be supported.

Personally, I think it'd be best to merge GDScript support first, and make the C# implementation sync with that. My biggest concern is to deviate too much from whatever GDScript ends up doing.

@dalexeev
Copy link
Member

dalexeev commented Jul 9, 2023

It seems to support Array[int], Array[String] and Array[T] where T is an enum.

I don't know how applicable this is to C#, but I'll mention it here for completeness. In the PR, Array[Enum] is not supported by the @export_enum annotation, it makes no sense and is confusing. Array[int] is for values, Array[String] and Array[StringName] are for keys. Array[Enum] is supported by the @export annotation, for which you don't need to list options as annotation arguments.

@raulsntos
Copy link
Member

Thanks for the explanation! We don't have an [ExportEnum] attribute in C#, what we have is [Export] which is similar to the @export_custom annotation1, but when used without parameters it works like @export (no need to provide a list of values for enum arrays).

If/when we implement an [ExportEnum] attribute I assume it will work like @export_enum.

When [Export] is used with PropertyHint.Enum and an Array[Enum] property, I agree it can be confusing, but it just creates the PropertyInfo with the hint and hint_string as specified. So it's up to Core whether those hints work or not, we don't touch them2.

Footnotes

  1. Yet another unmerged GDScript PR about export annotations: https://github.com/godotengine/godot/pull/72912

  2. We do actually touch them a little bit, to format the hint_string as {ARRAY_ELEMENT_TYPE}/{PROVIDED_HINT}:{PROVIDED_HINT_STRING}.

@YuriSizov
Copy link
Contributor

YuriSizov commented Jul 17, 2023

Personally, I think it'd be best to merge GDScript support first, and make the C# implementation sync with that. My biggest concern is to deviate too much from whatever GDScript ends up doing.

So it looks like there are already deviations. [ExportEnum] does not exist, and [Export] doesn't work like @export but rather like a not-yet-implemented @export_custom or just manually crafted property definitions. So it seems to me that this PR doesn't make the situation worse and less in line than the implementation already is.

What do you think @raulsntos @RedworkDE @neikeq, should we merge this now then?

@RedworkDE
Copy link
Member

I don't see how this can conflict with any future plans we may end up having, unless these plans break the behavior of the existing Array<string> support, in which case breaking the behavior of Array<StringName> as well doesn't make the change any bigger of a deal; so I would merge this.

Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also fine with merging this. Since we already support Array<string> it's not too far-fetched to also support Array<StringName>.

My biggest concerns were addressed by @dalexeev, it seems we want to support Array[String] and Array[StringName] with @export_enum in GDScript too, so it feels like this matches.

@YuriSizov YuriSizov changed the title C# Array<StringName> support PropertyHint.Enum C#: Add PropertyHint.Enum support to Array<StringName> Jul 18, 2023
@YuriSizov YuriSizov merged commit f8f06d3 into godotengine:master Jul 18, 2023
@YuriSizov
Copy link
Contributor

Let's merge it then. Thanks!

@magian1127 magian1127 deleted the 4.0StringName branch July 20, 2023 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants