Nested resource database management

Godot Version

4.2

Question

Hello everyone ! I’m looking for your advices on database resource management

In the game I’m working on, i have a card_info structure.

This is composed of simple attributes like:

  • name: String
  • nb_discards: int
  • is_destroyed: bool
  • etc.

It also has one more complex attribute, which is the major piece that makes me think on how to better structure the code. This is

  • options: Array[Option], with Option a custom class with its own attibutes. The number of elements in the Array is unknown

The objective is to have a database structure that allow me to store and manage the hundreds of possible card_info and option instances.

I went through several possibilities:

1: A dictionary with instances of the option class. For example:

> `var card_library = { "boar1": 
{ "name": "Boar", "nb_discards": 2, "options": [Option.new(0, ["wood", "rock"], [1, 1], ["vision_skill"], [1], ["food"], [2]), Option.new(0, ["help"], [0])] }`

After more research on the Godot engine philosophy, I realized Resources were a better option. It helps to have explicit parameters, easier access to attributes, non breakable string paths via export, etc.

2: Card_info resource files with nested instances of Option resource

With this method, there would be one .tres file per card_info, so hundreds of files potentially. All attributes of the card_info instances would have to be managed via the Godot editor. The Resource As Table plugin would here be essential to manage all card_info files at once.

But, this second method has one important issue. Modifying the name of any attributes in the card_info or option script will erase all the previously set attributes in the .tres. There would be hundreds of values to re write, for one variable name change.

It would cause no issue if the attribute names are never changed. But I feel that not being able to change variable names is a bad practice for code maintainability. I did not found a workaround to this issue. (Maybe I missed ?) Modifying resource values via editor seems not to be a good option for my project.

3: I need your help

To solve the last issue and still use the management power of spreadsheet, an option would be to use spreadsheet from an external software and find some kind of way to nest an unknown number of option resource. I could use a card_info sheet and an option one with reference between the two sheets. But the fact that the number of option per card_info is not fixed makes me wonder on it this method to be feasible.

To sum up,

  • Do you have insights on a good way to store and manage my card_info data with nested Array[Option] data ?
  • Is the use of an external sheet a possible and good approach for this type of data storage, even with nested Resources ?

Thanks a lot for reading this message. Anyone who could answer would help me a lot !!

I’m a bit stuck on this data structure choice before continuing the game development