I’m trying to set up a Resource script, LevelData, for a 2D plarformer I’m working on, to manage the info per levels.
I wish to maintain two exported enum in the resource, the second updating its values following the first one.
Example:
First @export enum would be for areas : Area1, Area2, Area3, etc.
Seconc @export enum would be available rooms in each area, among a whole list of rooms ; Room1, Room2, Room3, Room4, etc.
Upon selecting Area1, second enum would only show Room1 and Room2.
Upon selecting Area2, second enum would only show Room3 and Room4.
This would be so I don’t make mistakes, like selecting Room5 for Area1.
For future use of using for loops to make totals following other variables, like traking progress of collectables, etc.
Can someone help me?
I can make the enum working indepently.
@tool
extends Node
enum Area { Area1, Area2 }
enum Room { Room1, Room2, Room3, Room4 }
@export var area:Area:
set(value):
area = value
notify_property_list_changed()
@export var room:Room
func _validate_property(property: Dictionary) -> void:
if property.name == "room":
match area:
Area.Area1:
room = Room.Room1
property.hint_string = "Room 1:0,Room 2:1"
Area.Area2:
room = Room.Room3
property.hint_string = "Room 3:2,Room 4:3"
func _property_can_revert(property: StringName) -> bool:
if property == "room":
# room default value depends on the area so we need to use a custom revert value
return true
return false
func _property_get_revert(property: StringName) -> Variant:
if property == "room":
# return the default value depending on the area
match area:
Area.Area1:
return Room.Room1
Area.Area2:
return Room.Room3
return null
You can get more information here about what the property dictionary should contain and how to fill it by checking the Object.get_property_list() documentation.