mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-08-25 12:23:58 -04:00
f39d8bb080
- When activated, the JSON of the project is saved with properties always in alphabetical order. Fields in events are also never omitted.
- The preference is controlled via `gdevelop-settings.yaml` (already read
by the IDE on project open):
```yaml
# gdevelop-settings.yaml
preferences:
canonicalEventSerialization: true
```
Only show in developer changelog
Co-authored-by: Viktor Vovk <vvovk@playtika.com>
90 lines
2.3 KiB
C++
90 lines
2.3 KiB
C++
/*
|
|
* GDevelop Core
|
|
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
|
|
#ifndef GDCORE_SERIALIZER_H
|
|
#define GDCORE_SERIALIZER_H
|
|
#include <string>
|
|
#include "GDCore/Serialization/SerializerElement.h"
|
|
|
|
namespace gd {
|
|
|
|
/**
|
|
* \brief The class used to save/load projects and GDCore classes
|
|
* from/to XML or JSON.
|
|
*/
|
|
class GD_CORE_API Serializer {
|
|
public:
|
|
/** \name XML serialization.
|
|
* Convert a gd::SerializerElement from/to XML.
|
|
*/
|
|
///@{
|
|
|
|
/**
|
|
* \brief Escape a string for inclusion in a XML tag
|
|
*/
|
|
static gd::String ToEscapedXMLString(const gd::String& str);
|
|
///@}
|
|
|
|
/** \name JSON serialization.
|
|
* Convert a gd::SerializerElement from/to JSON.
|
|
* This uses RapidJSON for fast parsing and stringification.
|
|
* See https://github.com/miloyip/nativejson-benchmark
|
|
*/
|
|
///@{
|
|
/**
|
|
* \brief Serialize a gd::SerializerElement to a JSON string.
|
|
*/
|
|
static gd::String ToJSON(const SerializerElement& element);
|
|
|
|
/**
|
|
* \brief Construct a gd::SerializerElement from a JSON string.
|
|
*/
|
|
static SerializerElement FromJSON(const char* json);
|
|
|
|
/**
|
|
* \brief Construct a gd::SerializerElement from a JSON string.
|
|
*/
|
|
static SerializerElement FromJSON(const gd::String& json) {
|
|
return FromJSON(json.c_str());
|
|
}
|
|
///@}
|
|
|
|
/** \name Canonical serialization mode.
|
|
* When enabled, ToJSON writes object keys in alphabetical order and
|
|
* various SerializeTo helpers write default values (false, "", []) for
|
|
* properties that would otherwise be omitted.
|
|
*
|
|
* This makes git diffs minimal and shift-free when toggling boolean
|
|
* flags or adding/removing optional sub-structures (e.g. sub-events,
|
|
* local variables).
|
|
*/
|
|
///@{
|
|
/**
|
|
* \brief Enable/disable canonical serialization mode globally.
|
|
*
|
|
* Affects ToJSON (alphabetical key order) and various SerializeTo helpers
|
|
* (always writing default values for optional properties).
|
|
*/
|
|
static void SetCanonicalMode(bool canonical) { canonicalMode = canonical; }
|
|
|
|
/**
|
|
* \brief Returns true if canonical serialization mode is currently active.
|
|
*/
|
|
static bool IsCanonicalMode() { return canonicalMode; }
|
|
///@}
|
|
|
|
virtual ~Serializer(){};
|
|
|
|
private:
|
|
Serializer(){};
|
|
|
|
static bool canonicalMode;
|
|
};
|
|
|
|
} // namespace gd
|
|
|
|
#endif
|