summaryrefslogtreecommitdiff
path: root/core/include
diff options
context:
space:
mode:
Diffstat (limited to 'core/include')
-rw-r--r--core/include/turns/core/json_ext.hpp43
-rw-r--r--core/include/turns/core/turn_order.hpp8
2 files changed, 51 insertions, 0 deletions
diff --git a/core/include/turns/core/json_ext.hpp b/core/include/turns/core/json_ext.hpp
new file mode 100644
index 0000000..3eedb64
--- /dev/null
+++ b/core/include/turns/core/json_ext.hpp
@@ -0,0 +1,43 @@
+#ifndef TURNS_CORE_JSON_EXT_HPP
+#define TURNS_CORE_JSON_EXT_HPP
+
+#include <glibmm/property.h>
+#include <glibmm/ustring.h>
+
+#include <nlohmann/json.hpp>
+
+#include <string>
+
+NLOHMANN_JSON_NAMESPACE_BEGIN
+
+template<typename T>
+struct adl_serializer<Glib::Property<T>>
+{
+ static void to_json(json & to, Glib::Property<T> const & from)
+ {
+ to = from.get_value();
+ }
+
+ static void from_json(json const & from, Glib::Property<T> & to)
+ {
+ to = from.template get<T>();
+ }
+};
+
+template<>
+struct adl_serializer<Glib::ustring>
+{
+ static void to_json(json & to, Glib::ustring const & from)
+ {
+ to = static_cast<std::string>(from);
+ }
+
+ static void from_json(json const & from, Glib::ustring & to)
+ {
+ to = from.template get<std::string>();
+ }
+};
+
+NLOHMANN_JSON_NAMESPACE_END
+
+#endif \ No newline at end of file
diff --git a/core/include/turns/core/turn_order.hpp b/core/include/turns/core/turn_order.hpp
index 59556bb..5dbc6c6 100644
--- a/core/include/turns/core/turn_order.hpp
+++ b/core/include/turns/core/turn_order.hpp
@@ -14,6 +14,8 @@
#include <optional>
#include <vector>
+#include <nlohmann/json_fwd.hpp>
+
namespace turns::core
{
@@ -40,6 +42,7 @@ namespace turns::core
turn_order();
auto static create() -> Glib::RefPtr<turn_order>;
+ auto static create(nlohmann::json const & from) -> Glib::RefPtr<turn_order>;
/** Properties */
auto is_empty() const -> Glib::PropertyProxy_ReadOnly<is_empty_type>;
@@ -60,7 +63,12 @@ namespace turns::core
auto start() -> void;
auto stop() -> void;
+ /** Serialization */
+ auto serialize() -> nlohmann::json;
+
private:
+ explicit turn_order(nlohmann::json const & from);
+
auto get_item_type_vfunc() -> GType override;
auto get_n_items_vfunc() -> unsigned override;
auto get_item_vfunc(unsigned position) -> void * override;