tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Custom enums: Allow of multiple values enhancement

Open ChristianPervoelz opened this issue 1 year ago • 2 comments

Custom enums are a great and really easy way to define custom properties and by that create new templates/classes in a quick manner. But in some cases they might become confusing or may lead to errors. :(

In one of my projects I have defined an enum named Fruits with (just an excerpt) values: apple, banana, peach and so on.

Now I have two custom classes: SingleFruit (represents a single fruit) and PileOfFruits (represents many fruits). Both have Fruits as member.

The problem is now, that I have to check Allow mutiple values (flags) in the enum, as else I cannot easily have multiple entries for the PileOfFruits class. On the other hand, this allows the SingleFruit class to have multiple values too, but that one should have one value at a time only (as the name says).

Idea It would be very great to have an additional option in custom types editor, that allows to set an enum member of a class to be either multi-value or single-value.

Alternatives There is a couple of alternatives, of course:

  • create a second enum with the same values (and different name), not allowing multi selection (could become quite messy, easily)
  • don't use the enum at all (would be a pitty)
  • being careful, what is selected for SingleFruit ;)

ChristianPervoelz avatar Aug 22 '22 14:08 ChristianPervoelz

I feel like there is another solution, which would be to add support for array properties (#1493). Then your PileOfFruits could have an array of Fruit member. A possible downside is that it can then contain the same fruit multiple times, though that could also be a positive.

bjorn avatar Aug 22 '22 18:08 bjorn

Agreed. That sounds like a very good solution. And yes, multiple entries of the same type would be good for a pile of fruits,, as only one of each type doesn't leave much choices, if one does not like bananas, but apples only. ;)

So I think, it would be great to have arrays, may with the option to prevent multiple entries of the same value (not sure whether that's really meaningful).

ChristianPervoelz avatar Aug 22 '22 21:08 ChristianPervoelz