Page tree

This page has not yet been translated to English.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Sv translation
languageen

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.

  • GameData - API class
  • Document - base class for all entities
  • Character - entity that describes game characters
    • Id - character's numerical identifier
    • Name - character's unique name
  • LootSettings - entity containing loot settings
    • ResetTime - loot reset period
    • RewardFormula - formula for calculating reward

Loading data

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

Code Block
languagec#
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:

Code Block
languagec#
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:

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

Settings entities are accessed by name:

Code Block
languagec#
var resetTime = gameData.LootSettings.ResetTime; // -> TimeSpan

Formulas

Formulas are executed with Invoke method:

Code Block
languagec#
var reward = gameData.LootSettings.RewardFormula.Invoke()  // -> int

Formula parameters are used passed as common parameters for the 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

Content by Label
showLabelsfalse
cqllabel = "codegen" and type = "page" and space = "CHAR"