Best practice to keep track of many custom resources/scenes?

Godot Version

4.x

Question

I’m using procedural and random generation.

Currently I have Stuff as an autoloaded singleton which generates dictionaries by category, so that I can access those where needed. Since I need to be able to sort and loop through the elements, I also have a corresponding array with the keys.

Here is an example:

extends Node

const ITEMS = ["PlateHelmet", "LeatherShirt"] # Sorted by tier
const ITEMS_DB = {
	"LeatherShirt": {
		"tier": 2,
		"category": "armor",
		"subcategory": "torso",
		"resource": load("res://resources/cannons/Ballistic.tres")
	},
	"PlateHelmet": {
		"tier": 6,
		"category": "armor",
		"subcategory": "head",
		"resource": load("res://resources/cannons/Plasma.tres")
	}
}

This is not ideal.

This way I can do this for example in the drop system:

var drop_table = []
for item in Stuff.ITEMS:
  if ITEMS_DB[item].tier <= max_tier:
    drop_table.append(item)

Ideally, I would want to be able to generate the abstraction / items database by getting all the resources from referencing the folder, and then put all the information inside the .tres files instead of having to hardcode it. But using DirAccess doesn’t work after exporting to mobile.

Does anyone have some best practice to share around this?

If you want to save data on your game on mobile, I think you need to use some third party platforms like SilentWolf, Nakama, etc. Have you tried this by saving the data inside the project like res://? Or saving the data as a resource?
I think this page will help you

Thank you for the link.

I have several hundreds of items of different types and also other categories than items.

It is mixed as Scenes for complex things, resources for less complex things and things like CompressedTexture2D for the simplest things.

The way I have done it now for example for the heroes, I have a hero.gd singleton.

Then, I put all the heroes in there, generate the required stats such as tier, rarity, probability, sprite, etc. This makes it easy for me to add heroes, all I need to do is:

  1. Create a sprite png file with the same name as the hero.
  2. Add the hero name to the correct tier in the autoloaded singleton.

This way I can do things like:

for hero_data in Hero.all:

Or:

var hero_data = Hero.data["Leonard"]
print(hero_data.texture, hero_data.scene, hero_data.probability, hero_data.rarity)

And:

var hero_card_rewards = Hero.get_rewards(rolls, tier, multi_drop_factor)
for hero_card in hero_card_rewards:
  DropHandler.drop_reward(hero_card, recipient)

I have a DataManager singleton which handles loading and saving.

That one instantiates a custom resource PlayerData which holds data like unlocked heroes, items, currencies, etc.

I’m looking for best practices in Godot.

I’ve searched a lot on YouTube, but haven’t found anything which seems better than what I’ve made (I’ve worked with system development since 2007). At the same time, what I’ve made feels like less of an optimal data structure than what I am used to working with.

I really think there are best practices in Godot in terms of data structuring. I have just yet to find it.

I see people posting videos, but then they seem to not having finished a single game yet.