Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate "Glaze" JSON library #215

Open
Ghabry opened this issue Mar 2, 2023 · 0 comments
Open

Evaluate "Glaze" JSON library #215

Ghabry opened this issue Mar 2, 2023 · 0 comments
Assignees
Labels

Comments

@Ghabry
Copy link
Member

Ghabry commented Mar 2, 2023

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.

@Ghabry Ghabry added the Building label Mar 2, 2023
@Ghabry Ghabry self-assigned this Mar 2, 2023
@Ghabry Ghabry changed the title Evalute "Glaze" JSON library Evaluate "Glaze" JSON library Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant