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

Godot 3.2: Implement enum exports for GDScript #25

Open
willnationsdev opened this issue Oct 7, 2018 · 1 comment
Open

Godot 3.2: Implement enum exports for GDScript #25

willnationsdev opened this issue Oct 7, 2018 · 1 comment

Comments

@willnationsdev
Copy link
Owner

willnationsdev commented Oct 7, 2018

At this time, exporting enums in GDScript is very cumbersome. In order for the enums' names to be visible in the editor, you must specify a set of strings to be displayed for each value. This requires a hardcoded list of strings that must be updated as the enum changes over time. Either that, or a Dictionary mapping must be made and then used in a _get_property_list() override in a tool script (which, in turn, necessitates an implementation of _set() and _get(). This can amount to as much as 20 extra lines of code + converting it to a tool script JUST to make an enum value automatically updated in the Inspector.

This change would allow you to define enum exports based on an enum's identifier and using an optional string prefix to filter out string content from the keys, similar to the way the engine treats property groups.

enum Elements {
    ELEM_FIRE,
    ELEM_ICE
}
export(int, Elements, "ELEM_") var element = ELEM_FIRE

This would then display "Fire" and "Ice" as options within the editor as it would filter out the content. If you wished to change the order, you could just change the ordering within the enum.

@willnationsdev
Copy link
Owner Author

Turns out this was largely already done in 3.1! All you had to do was export the enum directly. I have submitted a PR to add the optional prefix filter portion.

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

No branches or pull requests

1 participant