Skip to content

Database ​

Inherits: RefCounted

The database of the project: every resource you make in the editor (an ability, an effect, an NPC, a quest ...) is a file, and this class finds, creates, saves and deletes them.

Description ​

The resources are grouped in TYPES. REGISTRY says, for each type, the folder under res://src/data/ where its files live and the class the resources must be. A resource is the file <id>.tres in that folder, and everything else refers to it by its id: Database.get_resource("effect", id). Each type is read from disk once, on first use, into a cache (a dictionary id -> resource) that stays for the whole session.

All the resources extend DatabaseResource. The database also makes the few resources every project needs (the Environmental and Player factions, the Health and Shield pools, the core stats, the default environment configs, the default popup). The asset libraries (animations, audio, VFX, meshes, model scenes, icons) are not in this registry: they have their own classes, see DatabaseAnimation, DatabaseAudio, DatabaseVFX, DatabaseMeshes, ModelSceneDatabase and DatabaseIcons.

Variables ​

VariantREGISTRY{ ... }
booldefer_scanfalse

Methods ​

voidflush_scan() static
voidensure_initialized() static
PopupDataget_popup_data_by_scene_path( scene_path: String ) static
voidregister_popup_data( popup: PopupData ) static
TimeConfigget_default_time_config() static
SunConfigget_default_sun_config() static
SkyConfigget_default_sky_config() static
WeatherConfigget_default_weather_config() static
EnvironmentConfigget_default_environment_config() static
Arrayget_all_stat_definitions() static
voidreload_cache( type: String ) static
Dictionaryget_cache( type: String ) static
boolresource_exists( type: String, id: int ) static
DatabaseResourcecreate_resource( type: String, res_name: String, type_override: GDScript = null ) static
boolsave_resource( type: String, res: DatabaseResource ) static
DatabaseResourceget_resource( type: String, id: int ) static
booldelete_resource( type: String, id: int ) static
Array[WorldData]get_all_world_data() static
WorldDataget_world_data_by_scene_path( scene_path: String ) static
intget_next_world_id() static
PackedStringArrayget_all_world_categories() static
Array[WorldData]get_worlds_by_category( category: String ) static
voidregister_world_data( world_data: WorldData ) static
Dictionaryvalidate_all_worlds() static
voidreload_world_cache() static
GlobalVariableget_global_variable_by_key( variable_key: String ) static
Dictionaryget_all_global_variables_as_dict() static
boolhas_global_variable( variable_key: String ) static
Array[Dictionary]get_list_for_ui( type: String ) static
Array[Dictionary]get_all_equipment_types_for_ui() static
EquipmentTypeDefinitionget_equipment_type_resource( id: int ) static
boolequipment_type_exists( id: int ) static
Array[Dictionary]get_abilities_by_subtype_for_ui( subtype: String ) static
ToggleGroupsResourceget_toggle_groups_resource() static
Array[String]get_all_toggle_groups() static
booladd_toggle_group( group_name: String ) static
boolremove_toggle_group( group_name: String ) static
boolrename_toggle_group( old_name: String, new_name: String ) static
NPCDefinitioncreate_entity_from_template( template_id: int, display_name: String ) static
InteractableDefinitioncreate_interactable_from_template( template_id: int, display_name: String ) static
NPCDefinitionclone_entity_as_template( source_id: int, template_name: String = "", follow: bool = false ) static
InteractableDefinitionclone_interactable_as_template( source_id: int, template_name: String = "", follow: bool = false ) static
PlayerClassDefinitioncreate_player_class_from_template( template_id: int, display_name: String ) static
PlayerClassDefinitionclone_player_class_as_template( source_id: int, template_name: String = "", follow: bool = false ) static

Constants ​

  • String TOGGLE_GROUPS_PATH = "res://src/data/abilities/toggle_groups/toggle_groups.tres" - The file that holds the toggle groups of abilities.
  • int ID_ENVIRONMENTAL_FACTION = 1000001 - Built in DatabaseResources
  • int ID_PLAYER_FACTION = 1000002 - The id of the built-in faction of the player.
  • int ID_HEALTH_POOL = 1000001 - The id of the built-in health pool.
  • int ID_SHIELD_POOL = 1000002 - The shield pool: a protective pool that absorbs damage before health and is never healed. The default pool of "Add Health Pool"
  • int ID_DEFAULT_TIME_CONFIG = 1000001 - Default environment config IDs
  • int ID_DEFAULT_SUN_CONFIG = 1000001 - The id of the built-in sun setup.
  • int ID_DEFAULT_SKY_CONFIG = 1000001 - The id of the built-in sky setup.
  • int ID_DEFAULT_ENVIRONMENT_CONFIG = 1000001 - The id of the built-in environment setup.
  • int ID_DEFAULT_WEATHER_CONFIG = 1000001 - The id of the built-in clear weather (no particles, dry ground).
  • int ID_DEFAULT_POPUP = 1000001 - The popup that comes with the toolkit (title, text, icon, button)
  • String DEFAULT_POPUP_SCENE = "res://addons/chroniclenode/ui_scenes/in_game/popups/default_popup_ui.tscn" - The scene a popup uses when it has none of its own.

Variable descriptions ​

REGISTRY ​

Every type of resource: the key is the type name used everywhere ("effect", "npc" ...), path is the folder of its files and class the class the resources must be. See the Database types page for the whole table. The type "enviroment" is spelled that way in the code.

bool defer_scan = false ​

While this is set the editor's file scan after a save or a delete waits (a batch of saves sets it, then calls flush_scan once)

Method descriptions ​

void flush_scan() ​

Scans the files of the project in the editor (once, if a save or delete asked for it while defer_scan was set)

void ensure_initialized() ​

Makes the folder of every type in REGISTRY (when missing) and the built-in resources. Runs once; every other function of this class calls it first.

PopupData get_popup_data_by_scene_path( scene_path: String ) ​

The popup data made for a scene (null when the scene has none yet)

void register_popup_data( popup: PopupData ) ​

Put the popup data of a scene in the database (called when the scene is saved in the editor; a data without an id gets one)

TimeConfig get_default_time_config() ​

Get default time config

SunConfig get_default_sun_config() ​

Get default sun config

SkyConfig get_default_sky_config() ​

Get default sky config

WeatherConfig get_default_weather_config() ​

Get the built-in clear weather

EnvironmentConfig get_default_environment_config() ​

Get default environment config

Array get_all_stat_definitions() ​

Every stat definition the entities get: the stats of the project, and the hidden stat of each proficiency (it carries the effects of the proficiency, see ProficiencyDefinition.get_virtual_stat). Not saved anywhere: made when asked for

void reload_cache( type: String ) ​

The cache of a type: a dictionary id -> resource of everything in its folder. Read from disk on the first call, then kept. An unknown type gives an empty dictionary. Forgets what was read of a type, so the next get_cache reads the folder again (the editor does it when a list of resources must be fresh).

Dictionary get_cache( type: String ) ​

No description yet.

bool resource_exists( type: String, id: int ) ​

Check if a specific resource ID exists in a category

DatabaseResource create_resource( type: String, res_name: String, type_override: GDScript = null ) ​

Create a database resource.

bool save_resource( type: String, res: DatabaseResource ) ​

Writes a resource to <folder of the type>/<id>.tres, sets its resource_path and puts it in the cache. Returns false when the resource has no id, the type is unknown or the file cannot be written (an exported game cannot write to res://).

DatabaseResource get_resource( type: String, id: int ) ​

The resource of a type with this id, or null. The usual way to follow a reference: Database.get_resource("effect", child_effect_id).

bool delete_resource( type: String, id: int ) ​

Deletes the file of a resource and takes it out of the cache. Other resources that still refer to the id are not changed: they find nothing the next time they look it up.

Array[WorldData] get_all_world_data() ​

Get all world data

WorldData get_world_data_by_scene_path( scene_path: String ) ​

Get world data by scene path

int get_next_world_id() ​

Get next available world ID

PackedStringArray get_all_world_categories() ​

Get all unique categories from worlds

Array[WorldData] get_worlds_by_category( category: String ) ​

Get all worlds in a specific category

void register_world_data( world_data: WorldData ) ​

Register world data (used by WorldScene on save)

Dictionary validate_all_worlds() ​

Validate all worlds and return report

void reload_world_cache() ​

Reload world cache (forces re-scan of world directory)

GlobalVariable get_global_variable_by_key( variable_key: String ) ​

Get a global variable by its key

Dictionary get_all_global_variables_as_dict() ​

Get all global variables as a dictionary {key: value}

bool has_global_variable( variable_key: String ) ​

Check if a global variable exists

Array[Dictionary] get_list_for_ui( type: String ) ​

The resources of a type as a list of {id, name, description}, sorted by name, for the pickers of the editor.

Array[Dictionary] get_all_equipment_types_for_ui() ​

Get combined list of equipment types AND weapon types for UI Use this when you need both types together (e.g., equipment slots)

EquipmentTypeDefinition get_equipment_type_resource( id: int ) ​

Get an equipment type resource by ID, checking both equipment_type and weapon_type Use this when you need to load equipment types but don't know if it's a weapon type

bool equipment_type_exists( id: int ) ​

Check if an equipment type resource exists (checks both equipment_type and weapon_type)

Array[Dictionary] get_abilities_by_subtype_for_ui( subtype: String ) ​

Get list of abilities filtered by subtype for UI (Active or Passive) subtype: "ActiveAbility" or "PassiveAbility"

ToggleGroupsResource get_toggle_groups_resource() ​

Get or create toggle groups resource (read-only)

Array[String] get_all_toggle_groups() ​

Get all toggle groups (read-only)

bool add_toggle_group( group_name: String ) ​

Adds a toggle group (a name that toggle abilities share, such as "auras" or "combat_stances") and saves the list. False when it exists already.

bool remove_toggle_group( group_name: String ) ​

Removes a toggle group and saves the list.

bool rename_toggle_group( old_name: String, new_name: String ) ​

Renames a toggle group and saves the list.

NPCDefinition create_entity_from_template( template_id: int, display_name: String ) ​

Makes a new NPC from the NPC template with this id, named display_name, and saves it in "npc". Null when the name is empty, the template does not exist or the file cannot be written.

InteractableDefinition create_interactable_from_template( template_id: int, display_name: String ) ​

Makes a new interactable from the interactable template with this id, named display_name, and saves it in "interactable". It follows the template. Null when the name is empty, the template does not exist or the file cannot be written.

NPCDefinition clone_entity_as_template( source_id: int, template_name: String = "", follow: bool = false ) ​

Saves a copy of the NPC with this id as a new NPC template (template = true, named template_name, no name when empty) in "npc_template". With follow the NPC follows the new template from then on. Null when the NPC does not exist or the file cannot be written.

InteractableDefinition clone_interactable_as_template( source_id: int, template_name: String = "", follow: bool = false ) ​

The same for an interactable: saves a copy of it as a new interactable template in "interactable_template"

PlayerClassDefinition create_player_class_from_template( template_id: int, display_name: String ) ​

Makes a new player class from the player class template with this id, named display_name, and saves it in "player_class". It follows the template. Null when the name is empty, the template does not exist or the file cannot be written.

PlayerClassDefinition clone_player_class_as_template( source_id: int, template_name: String = "", follow: bool = false ) ​

Saves a copy of the player class with this id as a new player class template (template = true, named template_name) in "player_class_template". With follow the class follows the new template. Null when the class does not exist or the file cannot be written.