Working with Source Code (Haxe)

Accessing game data during runtime is possible by utilizing the generated source code.

This section provides examples using default class names, but it is possible to customize class names during the source code generation process. Additionally, this customization allows to avoid naming collisions with existing code.

Loading Game Data

The following Haxe code creates GameData class and loads your game data into memory.

import GameData;
import Formatters;
import haxe.io.Path;
sys.io.File;

var input = File.read("RpgGameData.gdjs"); // or .json
var options = new GameDataLoadOptions();
options.format = GameDataFormat.Json;
options.leaveInputsOpen = false;
// options.patches <-- put patches here
var gameData = new GameData(input, options);

The file RpgGameData.gdjs could be published game data or original database file (.gdjs or .gdmp).

Accessing Documents

You can access your documents as a list:

var allHeroes = gameData.heroesAll.list // -> ReadOnlyArray<Hero>
var heroes = gameData.heroes.list // -> ReadOnlyArray<Hero>

Or you can access specific documents by their id or Unique properties:

Settings schemas are accessed by name:

var startingHeroes = gameData.startingSet.heroes; // -> ReadOnlyArray<Hero>

Formulas

Formulas are currently not supported.

See also