Skip to content

Add the the ability to iterate over Godot enums #600

Closed
@AndreLouisIssa

Description

@AndreLouisIssa

I'm looking at the struct Mode (godot::engine::window::Mode) and I want some way to iterate over the pub const fields. Minimally, this would be an iterator over the keys (field names in the order they appear in Godot), and a map from key to value, which most naturally could be added to EngineEnum (godot::obj::EngineEnum) (or to sidecars).

I want to use this to automatically represent the window settings in an options menu without writing out a mapping manually.
I would still have to massage the names of the fields to be human readable, but this is usually quite easy (_ -> , convert to title case, create inverse mapping). I have previously used this approach in C# (Enum.Parse, Enum.GetNames) and Java (enum.keys), and AFAIK it was possible in previous Godot versions since enums used to be dictionaries.

In the long term it's probably better to just write the mapping myself, especially when eventually serialising and localising it, but it could be at least used to quickly generate the templates for those (although I could generate them from outside of gdext).

If this is already possible somehow, please add information about it to a section in the book or to docs on each EngineEnum or on EngineEnum itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: engineGodot classes (nodes, resources, ...)featureAdds functionality to the librarygood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions