7#include "third_party/nlohmann/json.hpp"
29 j[
"description"] =
t.description;
30 j[
"completed"] =
t.completed;
34 if (
j.contains(
"description"))
t.description =
j[
"description"].get<std::string>();
35 if (
j.contains(
"completed"))
t.completed =
j[
"completed"].get<
bool>();
43 j[
"tasks"] = json::array();
48 if (
j.contains(
"title"))
o.title =
j[
"title"].get<std::string>();
49 if (
j.contains(
"tasks") &&
j[
"tasks"].is_array()) {
50 for (
size_t i=0;
i<
j[
"tasks"].size();++
i) {
53 o.tasks.push_back(std::unique_ptr<Task>(
new Task(
t)));
63 j[
"objectives"] = json::array();
64 for (
auto const& op :
q.objectives)
j[
"objectives"].
push_back(*op);
68 if (
j.contains(
"name"))
q.name =
j[
"name"].get<std::string>();
69 if (
j.contains(
"objectives") &&
j[
"objectives"].is_array()) {
70 for (
size_t i=0;
i<
j[
"objectives"].size();++
i) {
73 q.objectives.push_back(std::unique_ptr<Objective>(
new Objective(
o)));
82 j[
"quests"] = json::array();
88 if (
j.contains(
"quests") &&
j[
"quests"].is_array()) {
89 for (
size_t i=0;
i<
j[
"quests"].size();++
i) {
92 m.AddQuest(std::unique_ptr<Quest>(
new Quest(
q)));
101 j[
"data"] = json::array();
106 if (
j.contains(
"data") &&
j[
"data"].is_array()) {
108 for (
size_t i=0;
i<
j[
"data"].size();++
i)
c.data.push_back(
j[
"data"][
i].get<
int>());
116 j[
"elements"] = json::array();
121 if (
j.contains(
"elements") &&
j[
"elements"].is_array()) {
123 for (
size_t i=0;
i<
j[
"elements"].size();++
i) g.
elements.push_back(
j[
"elements"][
i].get<std::string>());
132 if (
s.collision)
j[
"collision"] = *
s.collision;
else j[
"collision"] =
nullptr;
133 if (
s.graphics)
j[
"graphics"] = *
s.graphics;
else j[
"graphics"] =
nullptr;
137 if (
j.contains(
"name"))
s.name =
j[
"name"].get<std::string>();
138 if (
j.contains(
"collision") && !
j[
"collision"].is_null()) {
139 s.collision = std::unique_ptr<CollisionMap>(
new CollisionMap());
142 if (
j.contains(
"graphics") && !
j[
"graphics"].is_null()) {
143 s.graphics = std::unique_ptr<GraphicMap>(
new GraphicMap());
153 j[
"sectors"] = json::array();
158 if (
j.contains(
"name"))
l.name =
j[
"name"].get<std::string>();
159 if (
j.contains(
"sectors") &&
j[
"sectors"].is_array()) {
160 for (
size_t i=0;
i<
j[
"sectors"].size();++
i) {
163 l.sectors.push_back(std::unique_ptr<Sector>(
new Sector(
s)));
173 j[
"levels"] = json::array();
178 if (
j.contains(
"name"))
w.name =
j[
"name"].get<std::string>();
179 if (
j.contains(
"levels") &&
j[
"levels"].is_array()) {
180 for (
size_t i=0;
i<
j[
"levels"].size();++
i) {
183 w.AddLevel(std::unique_ptr<Level>(
new Level(
l)));
192 j[
"schema_version"] =1;
193 j[
"type"] =
"VideoGame";
194 j[
"rules"] =
vg.GetRules().name;
195 j[
"world"] =
vg.GetWorld();
197 j[
"quests"] = json::array();
202 if (
j.contains(
"rules"))
vg.GetRules().name =
j[
"rules"].get<std::string>();
203 if (
j.contains(
"world")) {
206 vg.GetWorld() = std::move(
w);
208 if (
j.contains(
"quests") &&
j[
"quests"].is_array()) {
209 for (
size_t i=0;
i<
j[
"quests"].size();++
i) {
220 std::ofstream
ofs(path);
221 if (!
ofs)
return false;
227 std::ifstream
ifs(path);
228 if (!
ifs)
return false;
229 std::ostringstream
ss;
232 j = json::parse(
ss.str());
233 }
catch (std::exception&
e) {
234 std::cerr <<
"JSON parse error: " <<
e.what() << std::endl;
toVisit push_back(childId)
ComponentTypeID GetComponentTypeID_Static()
bool SaveToFile(const json &j, const std::string &path)
void from_json(json const &j, Task &t)
void to_json(json &j, Task const &t)
bool LoadFromFile(json &j, const std::string &path)
World and ECS Manager for Olympe Engine.
std::vector< std::string > elements
static QuestManager & Get()
void AddQuest(std::unique_ptr< Quest > q)
const std::vector< std::unique_ptr< Quest > > & GetQuests() const
Core ECS manager and world coordinator.