Hi y'all!
I'm creating an inventory system. There are the ItemData, which are basically static, .tres resources describing a kind of item, like "wheat", "flour", etc... With properties like name, value, ingredients used to make it, icon, etc...
And then there are Items themselves - they store a reference to an ItemData and have an amount and are what is actually used in an inventory. This leads to accessing the properties of the data reference when dealing with items: item.ref.name
, item.ref.value
...
And so on. This concerns me because, ideally, external systems should not be worried about the internal makeup of the Item class and the mental hoops to change from ref to item caused some silly mistakes.
I thought of some possible solutions:
1) Item extends ItemRef, values are copied on _init.
This works but causes data duplication and sync issues. ie: if the ref.name changes, the item would be outdated. This would require updating the item on ref change, which seems... ugh.
2) Item _get(property) points to ItemRef
Works but breaks autocompletion and is unsafe, due to the dynamic nature of it
func _get(property: String):
return ref.get(property)
3) Item with same fields as ItemRef and a lot of setget
Works but is quite verbose. I mean:
var my_name : String setget noop, get_my_name
func noop(v):
return
func get_my_name():
return ref.my_name
I was wondering if anyone else has a better solution (or maybe even a different idea altogether!).