EasyRPG / Editor

Game editor similar to RPG Maker
https://easyrpg.org/editor/
GNU General Public License v3.0
350 stars 58 forks source link

Evaluate "Glaze" JSON library #215

Open Ghabry opened 1 year ago

Ghabry commented 1 year ago

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.

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.