CSVs are often used to define data for games, but it's common for one CSV to need to reference information from another CSV. This tutorial will walk you through creating two CSVs, one which will reference another.
In this situation we will create two CSVs:
The first will define the weapons which exist in your game. The weapons defined for this game will be for a traditional RPG.
The second will define the shops in the game which will contain a list of the weapons which they can sell.
First we'll create a CSV for weapons, which we'll call WeaponInfo:
Right-click on GlobalContent
Select "Add File"->"New File"
Select "Spreadsheet (.csv)" as the type
Enter the name "WeaponInfo" as the new file's name
Click OK
Next create the CSV for StoreInfo:
Right-click on GlobalContent
Select "Add File"->"New File"
Select "Spreadsheet (.csv)" as the type
Enter the name "StoreInfo" as the new file's name
Click OK
Fill the WeaponInfo so it appears as follows:
Fill the StoreInfo so it appears as follows:
**Note we used List<string>:**Note that the StoreInfo CSV file uses a List<string> instead of a List<WeaponInfo> for the WeaponTypes it contains. The reason for this is because we want to simply reference the key from WeaponInfo.csv so that it can change without requiring changes to StoreInfo.csv.
Next we'll need to write some simple code to associate the values in the WeaponTypes column in the StoreInfo CSV to the weapons defined in WeaponInfo.csv. To do this:
Open your project in Visual Studio
Expand the "DataTypes" folder in the Solution Explorer
Right-click on the "DataTypes" folder and select "Add"->"Class..."
Name the class "StoreInfo". This should be the same name as your CSV.
Finally save your project through the "File"->"Save All" option in Visual Studio. This will save changes to the project so that if Glue is open it will reload the changes. Visual Studio may notify you that the project has changed. This may be because Glue has inserted the StoreInfo.Generated.cs file under the StoreInfo.cs in the Solution Explorer.
Next we'll add a property to the StoreInfo.cs file to make it more convenient to access which WeaponInfo's a Store contains. To do this, add the following code to StoreInfo.cs:
Now each ScreenInfo which is loaded into GlobalContent has an IEnumerable of WeaponInfo's that can be used to populate UI, menus, and drive game logic.
You should now have 2 CSVs in your Global Content Files in Glue:
You should now have a file called StoreInfo.cs and a file called StoreInfo.Generated.cs. Next, open the newly-created StoreInfo.cs file and make it a "public partial" class. After you do this, your code should look like:
Name (string, required)
Damage (float)
Sword
3
Spear
4
Dagger
2
Name (string, required)
WeaponTypes (List<string>)
CapitalCity
Sword
Spear
SouthCity
Dagger
Spear