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

Improve enum usage in Dictionary exports for C# #28536

Open
JarLowrey opened this issue Apr 30, 2019 · 1 comment
Open

Improve enum usage in Dictionary exports for C# #28536

JarLowrey opened this issue Apr 30, 2019 · 1 comment

Comments

@JarLowrey
Copy link

JarLowrey commented Apr 30, 2019

Godot version:

3.1.1

OS/device including version:

Win10

Issue description:

Feature request:

I am trying to export a dictionary of enum: float. In the editor my enum shows up as an int, instead of a string. This makes it difficult to use. There is also no auto-complete available. If possible these would be great features to have.

Steps to reproduce:

[Export]
public Godot.Collections.Dictionary Weights = new Godot.Collections.Dictionary() {
    {EnumName1, 0.5}
};

Appears as the following in the editor

image

If you type the dictionary, it will correctly set the value as a float (otherwise initializing to 1 will cause it to be an int in the editor), but the enum is still not auto-translated to a string in the editor.

[Export]
public Godot.Collections.Dictionary<ClassName.EnumNames, float> Weights = new Godot.Collections.Dictionary<ClassName.EnumNames, float> () {
    { EnumName1, 1 } // 1 will be a float in the editor, but EnumName1 will still show up as 11 and not offer auto-complete
};

Using a C# dictionary causes the exported var to not show up at all in the editor.

@raulsntos
Copy link
Member

I am trying to export a dictionary of enum: float.

The C# specification says the underlying type of an enum can be any integral type other than char (see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/enums#182-enum-declarations). Even if you could, it's probably not a good idea because of precision loss.

In the editor my enum shows up as an int, instead of a string. [...] There is also no auto-complete available.

Without typing information the editor can't know that your values represent an enum. The editor receives a value of the underlying type, which means an integral type.

IntelliSense also can't know what is the type of the keys or the values of the Dictionary without the typing information, since you are using the non-generic Godot.Collections.Dictionary the typing information is not available.

If you use the generic Godot.Collections.Dictionary<TKey, TValue> the typing information is available and IntelliSense can help you when using the dictionary keys/values, this information needs to be passed to the editor but currently this is not supported.

For the typing information to be supported in the editor we'd need to implement type hints for dictionaries, there is already a proposal for this: godotengine/godot-proposals#56.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants