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

Custom numerical values for Enum custom properties #3534

Open
eishiya opened this issue Nov 29, 2022 · 4 comments
Open

Custom numerical values for Enum custom properties #3534

eishiya opened this issue Nov 29, 2022 · 4 comments
Labels
feature It's a feature, not a bug.

Comments

@eishiya
Copy link
Contributor

eishiya commented Nov 29, 2022

Background

Currently, numerical enum values are set by Tiled based on whether that custom type is allowed to have multiple values. This is great as a default, but the lack of control makes it difficult to add Enums in Tiled that align with Enums in one's game, or enums that only allow a particular range of values, as those may have values that don't start at 0 and/or don't increase in the ways Tiled supports.

Feature request

For Enums that cannot have multiple values, it would be good to allow users to set custom numerical values. These would only be relevant when saving the values as numbers, so perhaps it would also make sense to limit this feature to those.

(In case this request sounds familiar, I brought this up before in #1211 (comment), but that issue was closed without this feature being added.)

UI suggestions

I think the numerical values should be displayed in the list of values, greyed out when they cannot be edited. Perhaps when saving as String, the number column should be hidden entirely since it's irrelevant, though it should keep any custom numerical values that were previously set.
When editing a value, you should be able to click or double-click the number and edit it like an integer. When committing a change, if there's a conflict, I think a warning should be displayed, with options to Edit NameOfValue, which puts the just-edited value back into focus without committing the change, and Edit NameOfConflictingValue, which commits the just-edited value and puts the conflicting value into focus for editing instead. This second option would put the definitions into an invalid state if the user closes the editor at this point (and while Tiled can try to keep the user from exiting, it can't stop a force-quit xP). A potential fix is to set the conflicting value to 1+ current highest value (but give the user the old value to edit), so that the enums are never in an invalid state under the hood, even if they're temporarily displayed with invalid values for editing.

@eishiya eishiya added the feature It's a feature, not a bug. label Nov 29, 2022
@tumatanquang
Copy link

I agree, especially with Custom Type saved as Number, rather than value that always start at 0, I'd like to be able to customize their values.

@duarm

This comment was marked as off-topic.

@eishiya
Copy link
Contributor Author

eishiya commented Nov 21, 2023

it would help a lot if tiled held an internal enum for each custom type too, so instead of exporting a string for the class of an object, we would be able to export "class": 2 instead of "class": "spawn", which our engine would probably map to 2 anyway.

I think that is an entirely unrelated issue to this one.

@eishiya
Copy link
Contributor Author

eishiya commented Feb 21, 2025

A prerequisite to implementing this feature would be to assign persistent indices to enum values, rather than just using their order in the list of values as is done now. This would also fix the "bug" where deleting an enum value changes the chosen values in currently open documents in Tiled:
Before deleting any values, three properties have the values One, Two, and Three

After deleting the value "One", the first two properties become Two and Three instead of One and Two, and the third property becomes unset.

Deleting enum values and editing their indices after using them isn't something I had considered, but that's an important thing to think about as well. What should be done when changing the value? I would expect the chosen value to remain and the number that's stored in the file to change on save, but perhaps the alternative (keeping the number as-is, whatever it now means) is preferred in some cases. If the first option is to be offered, then Tiled would need a way to iterate and update all custom properties of that type in all open assets, and it could only handle open assets, leading so the same problem as resizing tilesets with some maps not currently open in Tiled... Perhaps the indices should be kept-as is always, but Tiled or a script could provide an Action to replace all instances of one value with another in all open assets, or in all assets in a Project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature It's a feature, not a bug.
Projects
None yet
Development

No branches or pull requests

3 participants