Accessing game data from source code is possible by using pregenerated API classes

We will use standard names in this example. You can set up your own class names before generation.

Loading data

The following C# code creates API class and loads your data.

var fileStream = File.OpenRead("gamedata.json");
var gameData = new GameData(fileStream, GameData.Format.Json);

The loaded data is read-only.

Accessing documents

You can access your documents as a list:

var characters = gameData.GetCharacters() // -> ReadOnlyList<Character>
var characters = gameData.GetCharacters(onlyRoot: true) // -> ReadOnlyList<Character>

Or you can access specific documents by their Id or 'unique' fields:

var character = gameData.GetCharacter(characterId); // -> Character
var character = gameData.GetCharacterByName(characterName); // -> Character

Settings entities are accessed by name:

var resetTime = gameData.LootSettings.ResetTime; // -> TimeSpan

Formulas

Formulas are executed with Invoke method:

var reward = gameData.LootSettings.RewardFormula.Invoke()  // -> int

Formula parameters are passed as common arguments of method.

GameData methods and properties

Method

Type

Description

SupportedLanguages
ReadOnlyCollection<string>

The list of supported localizations. Must contain at least one.

SetLanguage(string language)
void

Set current localization for every localized string within game data.

LocalizedString.Value returns either a string from current localization, or empty string if localization is missing.

ApplyVisitor(Visitor visitor)
void

Go through whole document hierarchy using the supplied Visitor.

GetAllDocuments
IEnumerable<Document>

Get iterator for all documents.

partial OnBeforeInitialize()
void

Extension point for 'partial' class. Called after loading the data into lists and dictionaries and before processing references and marking documents read-only.

partial OnInitialize()
void

Extension point for 'partial' class. Called after loading and prepping all data.

Related pages