I want to have a constants file that has a bunch of enums, ints, vectors, and preloads that I can use in all gdscript files. If I want to export some of these enums, the only way I know is to preload this constants file in all the scripts, which seems pretty inconvenient and potentially redundant loading (not sure if preload is handled intelligently across different gdscript files). Is there an equivalent of python import or C++ #include in gdscript?
imagine the following scenario:
# constants.gd
enum Spell = { FIRE, WATER, WIND EARTH };
enum Item = { CONSUMABLE, WEAPON, ARMOR, KEYITEM };
enum Obj = { BUILDING, NPC, OTHER };
# spell.gd
const constants = preload("res://constants.gd");
export (constants.Spell) var Type;
# item.gd
const constants = preload("res://constants.gd");
export (constants.Item) var Type;
# obj.gd
const constants = preload("res://constants.gd");
export (constants.Obj) var Type;
I'm not sure if calling preload() on the same resource will consume more memory, imagine hundreds or thousands of obj/item/spell classes. Is there is a better way at handling this situation. I think it's a very common practice to have a separate constants file. But in practice, it's much trickier than it should be.
Perhaps we can take AutoLoad to the next level with AutoPreload in the next version?