godotengine / godotengine/godot-cpp

TypedArray and TypedDictionary do not allow enums as template parameters

Open
#1,684 4 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### Godot version

4.4.dev7.official.46c8f8c5c

### godot-cpp version

befe3ee2f2a129faa321c08e814ccfbd8cd6651c

### System information

Debian Trixie, i7-1360P

### Issue description

Related to #1584, although the introduction of typed dictionaries makes this much more complicated.

`TypedArray` and `TypedDictionary` should be able to take enum types that have been registered with `VARIANT_ENUM_CAST` as the element or key or value type, treating it as an integer with whatever metadata is needed to make the editor show the correct type name in the brackets.

### Steps to reproduce

Contrived toy example:

```
class Foo : public Object {
GDCLASS(Foo, Object);

protected:
static void _bind_methods();

public:
enum Animal {
CAT,
DOG,
HORSE,
};

TypedArray get_animals_that_should_go_in_a_house() const;
TypedDictionary get_animal_meshes() const;
};

VARIANT_ENUM_CAST(Foo::Animal);
```

Actual project where I am using typed arrays and dictionaries of enum types: https://github.com/BenLubar/godot4-spy-cards-online
(In the actual project, `src/dry.h` contains a lot of helper macros.)

### Minimal reproduction project

N/A

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.