Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
serialize_example.cpp
Go to the documentation of this file.
1#include <fstream>
2#include "Graph.h"
3#include "../../Source/third_party/nlohmann/json.hpp"
4
5void SaveGraphToFile(const Graph& g, const std::string& path)
6{
7 auto j = g.ToJson();
8 std::ofstream ofs(path);
9 if (ofs) ofs << j.dump(4);
10}
11
12Graph LoadGraphFromFile(const std::string& path)
13{
14 std::ifstream ifs(path);
15 if (!ifs) return Graph();
16 std::string contents((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
17 nlohmann::json j = nlohmann::json::parse(contents);
18 return Graph::FromJson(j);
19}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
nlohmann::json json
Graph LoadGraphFromFile(const std::string &path)
void SaveGraphToFile(const Graph &g, const std::string &path)
Definition Graph.h:15
static Graph FromJson(const nlohmann::json &j)
Definition Graph.cpp:23
nlohmann::json ToJson() const
Definition Graph.cpp:6