-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParsedObject.cpp
96 lines (86 loc) · 2.65 KB
/
ParsedObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* ParsedObject.cpp
*
* Created on: 19 kwi 2020
* Author: andr
*/
#include "ParsedObject.h"
void ParsedObject::Parse(const JsonObject * obj)
{
for (int i = 0; i < obj->values.size(); i++)
{
JsonVariant * var = obj->values[i];
if (var->name == "name") name = var->string_value;
if (var->name == "type") type = var->string_value;
if (var->name == "id") name = var->number_value;
if (var->name == "position")
{
JsonObject * obj = dynamic_cast<JsonObject *>(var);
for (int i = 0; i < obj->values.size(); i++)
{
JsonVariant * var = obj->values[i];
if (var->name == "x") position.x = var->float_value;
if (var->name == "y") position.y = var->float_value;
if (var->name == "z") position.z = var->float_value;
}
}
if (var->name == "scale")
{
JsonObject * obj = dynamic_cast<JsonObject *>(var);
for (int i = 0; i < obj->values.size(); i++)
{
JsonVariant * var = obj->values[i];
if (var->name == "x") scale.x = var->float_value;
if (var->name == "y") scale.y = var->float_value;
if (var->name == "z") scale.z = var->float_value;
}
}
if (var->name == "rotate")
{
JsonObject * obj = dynamic_cast<JsonObject *>(var);
for (int i = 0; i < obj->values.size(); i++)
{
JsonVariant * var = obj->values[i];
if (var->name == "x") rotate.x = var->float_value;
if (var->name == "y") rotate.y = var->float_value;
if (var->name == "z") rotate.z = var->float_value;
}
}
}
}
JsonObject * ParsedObject::ReturnJson()
{
JsonObject * obj = new JsonObject("");
JsonVariant * var;
var = new JsonVariant("name", name);
obj->values.push_back(var);
var = new JsonVariant("type", type);
obj->values.push_back(var);
var = new JsonVariant("id", id);
obj->values.push_back(var);
JsonObject * objpos = new JsonObject("position");
var = new JsonVariant("x", position.x);
objpos->values.push_back(var);
var = new JsonVariant("y", position.y);
objpos->values.push_back(var);
var = new JsonVariant("z", position.z);
objpos->values.push_back(var);
obj->values.push_back(objpos);
JsonObject * objscale = new JsonObject("scale");
var = new JsonVariant("x", scale.x);
objscale->values.push_back(var);
var = new JsonVariant("y", scale.y);
objscale->values.push_back(var);
var = new JsonVariant("z", scale.z);
objscale->values.push_back(var);
obj->values.push_back(objscale);
JsonObject * objrotate = new JsonObject("rotate");
var = new JsonVariant("x", rotate.x);
objrotate->values.push_back(var);
var = new JsonVariant("y", rotate.y);
objrotate->values.push_back(var);
var = new JsonVariant("z", rotate.z);
objrotate->values.push_back(var);
obj->values.push_back(objrotate);
return obj;
}