Hi, currently I'm working on adding an @export variable to the abilities of my game:
#AbilityData.gd
extends Resource
class_name AbilityData
@export var ability_name: String
@export var ability_name_UI: String
@export var targeting: Targeting
@export var damage: int
@export var srange: int
currently Targeting is a class that inherits resource:
#Targeting.gd
extends Resource
class_name Targeting
var srange: int
func _init() -> void:
pass
func _initialize(ability:AbilityData):
srange = ability.srange
func tiles(_source_unit: Unit, _BF: BattleField) -> TilePositionArray: #this is a custom class for a collection of tiles
return TilePositionArray.new()
But this means that every targeting protocol I need has its own .tres file (Area, Melee, Beam, etc), I would love to have all these on the same file using inner classes, something like this:
class_name Targeting
var srange: int
func _init() -> void:
pass
func _initialize(ability:AbilityData):
srange = ability.srange
func tiles(_source_unit: Unit, _BF: BattleField) -> TilePositionArray:
return TilePositionArray.new()
class Melee extends targeting:
func tiles(source_unit: Unit, BF: BattleField) -> TilePositionArray:
return BF.neighbor_tiles(source_unit)
#etc for other protocols
but then the inner classes wont appear on the editor, if I stop extending this as a resource then I get the error.
"Export type can only be built-in, a resource, a node, or an enum." I thought maybe making an enum that interfaces the methods, something like this:
enum targeting_protocols {Area, Melee, Beam}
func return_targeting(protocol:targeting_protocols)
match protocol:
targeting_methods.Area:
return Area
targeting_methods.Melee:
return Melee
targeting_methods.Beam:
return Beam
This works but I find it unwieldy and non elegant, especially since this Isn't just for targeting, I need this for procs, affecting area, etc. I'm sure there must be a better way.