Hey all, today we’re going over Depot and how to use it as a basic database for your Haxe Project. This is something I use for m own games, and it has been instrumental in creating enemies, items, dialogue, and more easily. Let’s get into it.
What Is Depot?
Depot is a flat-file data storage extension that works with Visual Studio Code. It allows you to store data in a JSON format, but add data visually like an Excel or Google spreadsheet. Here’s an example of the layout!
Layout Example Image
For more information, here’s a video on the technology!
So now that we know what it is, how do we mak it work for us?
Haxe Black Magic
In Haxe, there is a set of tools to create macros. A macro is a piece of code that runs before the code is compiled for the final program output. This allows you to bake code into your program like black magic. For example, we could bake in the result of parsing a certain Depot File.
Database References In Code
By using macros we can create references in the code by adding the result of parsing the file to the source code itself. This is how macros work in Haxe and allows us to do things we usually can’t in several languages. So, how do we do it with a Depot File? See below, it’s a pretty crazy macro.
This macro splits a Depot file into several sheets similar to excel and goes through the structure of each one to create a type for that sheet. Because, Depot sets up everything as an individual spreadsheet, parsing the information is straightforward. The rest of the macro is ignoring irrelevant information that we don’t need for our static data.
Now that we’re done parsing, we can use the macro like so:
This then adds all the fields from the Depot data directly to the class itself. In Haxe this is known as a build macro and is extremely useful for things like this.
Now, here’s the final result of our macro being used in Visual Studio Code:
Now we can reference any of the database data in our code without any hassle of looking up the data from a map or table through the Visual Studio Code Intellisense/autocomplete.
I hope this post helps you! With that said, good luck with creating your game. If you’d like to use the macro yourself, you can find a single file version here or copy the example above!