Thank you for the solution (changing the hint didn’t do anything, it still works exactly identically)!
The only thing is that the values of the stats’ enum isn’t being capitalized, it still shows in all upper case and with the underlines the value came in.
I tried to fix the issue with:
@export var category: Stats.BuffableCategories:
set(value):
class_list = Stats.get_category_buffable_list(value)
for i in class_list:
i.capitalize()
category = value
notify_property_list_changed()
var class_list: Array = []
and
func _validate_property(property: Dictionary) -> void:
if property.name == "stat":
var items: Array = Stats.get_category_buffable_list(category)
print(items)
for item in items:
item.capitalize()
print(items)
var items_string: String = ",".join(items)
property.hint = PROPERTY_HINT_ENUM
property.hint_string = "%s" % [items_string]
stat = clampi(stat, 0, items.size() - 1)
Neither of these worked. I tried setting an aux var at the set(value) of categoryand assigning it class_list, but that still didn’t work.
Will I have to live with that, or change the keys in the enum itself?
Nvm, fixed the capitalization issue myself:
func _validate_property(property: Dictionary) -> void:
if property.name == "stat":
var items: Array = Stats.get_category_buffable_list(category)
items = items as Array[String]
var items_string: String = ", ".join(items).capitalize().replace(", ", ",")
property.hint = PROPERTY_HINT_ENUM
property.hint_string = ("%s" % [items_string])
stat = clampi(stat, 0, items.size() - 1)
I hope this helps anyone in the future.
The point was to demonstrate that you can set the hint to PROPERTY_HINT_ENUM instead of declaring the property using @export_enum
Btw there is no “capitalization issue”. The property will verbatim use the string you provide.
Well, yeah, but iterating the array and assigning its values as value.capitalized() to themselves, won’t change capitalization, which is weird IMO.
You need to do the jank ", ".join(arr).capitalize().replace(", ", "," shuffle in my follow up, or it won’t capitalize at all, other than the source capitalization.
Strings are passed and assigned by value. Assigning to the iterator won’t set the value in the array.
Try this:
var array = ["one", "two", "three"]
print(array)
for i in array.size():
array[i] = array[i].capitalize()
print(array)
Output:
["one", "two", "three"]
["One", "Two", "Three"]
Although the most elegant way to do it is via map():
array = array.map(func(s): return s.capitalize())
I tried exactly that, and it didn’t work lol
Map worked, too, tho, and I agree it’s far more elegant, so I’m sticking with
func _validate_property(property: Dictionary) -> void:
if property.name == "stat":
var items: Array = Stats.get_category_buffable_list(category)
items = items.map(func(s: String): return s.capitalize())
property.hint = PROPERTY_HINT_ENUM
property.hint_string = ("%s" % [",".join(items)])
stat = clampi(stat, 0, items.size() - 1)