Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.

Engine Data config

Rewlion edited this page May 15, 2024 · 1 revision

Engine Data (ED) is a hierarchy data config with support for custom types.

Format:

ScopeA @("scope annotation") {
 someInt:i = 3 @("var annotation")
 someArr:i[] = [1,2,3,4]
 someVec:i3 = 1,2,3
 someText:t = "foo"
 ChildScopeA {
 }
}

Default variable types:

  • i,i2,i3,i4 (int)
  • f,f2,f3,f4 (float)
  • t (string)
  • b (bool)
  • m3, m4 (float3x3, float4x4)

C++ Access:

  ed::Parser parser{};
  bool acceptFails = true;
  ed::Scope scopeA = parser.parseFile("data.ed", acceptFails);
  int someInt = scopeA.getVariableOr<int>("someInt", 5);
  
  const ed::Scope& ChildScopeA = scopeA.getScope("ChildScopeA");

Custom Type registration

attributes : Attributes = {
  health:i = 200
  mana:i = 10
  speed: SpeedComponent = {
    velocity:f = 200.0
  }
}

  auto reg = std::make_shared<ed::CustomTypeRegistry>();

  struct SpeedComponent
  {
    SpeedComponent() = default;
    SpeedComponent(const ed::Scope* data)
    {
      if (data)
      {
        velocity = data->getVariable<float>("velocity");
      }
    }

    float velocity = 0;
  };

  struct Attributes
  {
    Attributes() = default;
    Attributes(const ed::Scope* data)
    {
      if (data)
      {
        health = data->getVariable<int>("health");
        mana = data->getVariable<int>("mana");
        speed = data->getVariable<SpeedComponent>("speed");
      }
    }

    int health = 0;
    int mana = 0;
    SpeedComponent speed;
  };

  reg->add<SpeedComponent>("SpeedComponent");
  reg->add<Attributes>("Attributes");

  ed::Parser parser{reg};
  ed::Scope ed = parser.parseFile("data.ed", true);

  Attributes var = ed.getVariable<Attributes>("attributes");
...

Clone this wiki locally