Text Database 1.3 Scripts 4.0 Community
Submitted by user KoBeWi; MIT; 2024-08-13
Advanced loader for text data files (JSON, CFG). It can load your files and perform a complex data validation. If you like keeping your data in text files, this will be useful as it ensures that your data is correct, i.e. without typos.
Data collections in TextDatabase are arrays of dictionaries. You can e.g. store items, enemy data, or level metadata etc. in a JSON or CFG files, where each item/enemy/level/etc is a Dictionary with some properties. You can define fields for your data, which can be either mandatory, or just allowed, and the loader will ensure that your fields are correct.
Example usage:
var database = TextDatabase.new()
database.add_mandatory_property("price")
database.add_valid_property("attack")
database.load_from_path("res://items.json)
var data = database.get_array()
Example valid file:
[
{
"name": "Sword",
"price": 100,
"attack": 5
}
]
Example invalid file:
[
{
"name": "Shield",
"defense": 1
}
]
It's missing "price" and "defense" is not a defined property, so the file won't load. You can catch errors like this, so you can avoid unexpected behaviors due to data typos.
btw, ConfigFiles (CFG) are much better than JSON. Here's the Sword example as CFG:
[Sword]
price = 100
attack = 5
You can store multiple items in one file and load multiple files into database. Just use load() multiple times on one database and then get_array() will return data from all files. Or you can use get_dictionary() instead and access the entries by name.
Explaining all functionality would be very long, so just read the README, which you can find in the asset's repository (: You can also find an example project in there.
View files Download Submit an issue Recent Edits