Skip to content

Evaluate "Glaze" JSON library #215

Open
@Ghabry

Description

@Ghabry

Just found this JSON library here: https://github.com/stephenberry/glaze

Requires C++20 - No problem for the editor.

Looking at the examples this provides a very simple interface to enable JSON (de)serialisation without gigantic patching in liblcf. Can be even injected from the outside (in the editor code).

As JSON would be a good project format for the editor (with suggestions like "put every entity in a single file to make versioning easier") and it is really simple.

  • Supports JSON pointers to get view on a subtree of the JSON
  • It manipulates the underlying object directly so binding to QML would be quite easy as QML could just read/write by string
  • Is very fast (not a requirement that is important but cool to have)

Minimal example providing an incomplete Actor and Learning (skills of actor) serializer:

template <>
struct glz::meta<lcf::rpg::Learning> {
   using T = lcf::rpg::Learning;
   static constexpr auto value = object(
      "level", &T::level,
	  "skill_id", &T::skill_id
   );
};

template <>
struct glz::meta<lcf::rpg::Actor> {
   using T = lcf::rpg::Actor;
   static constexpr auto value = object(
      "name", &T::name,
      "character_index", &T::character_index,
      "transparent", &T::transparent,
      "state_ranks", &T::state_ranks,
      "skills", &T::skills
   );
};

For the first actor this results in

{"name":["A","l","e","x"],"character_index":0,"transparent":false,"state_ranks":[],"skills":[{"level":1,"skill_id":1},{"level":1,"skill_id":4}]}

name is incorrect because our strings are a custom class. This is fixable.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions