forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunNodeFromJson.cpp
More file actions
60 lines (55 loc) · 1.45 KB
/
RunNodeFromJson.cpp
File metadata and controls
60 lines (55 loc) · 1.45 KB
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
#include "RunNodeFromJson.h"
#include "GameUtil.h"
#include "TextBox.h"
#include "filefunc.h"
RunNodeFromJson::RunNodeFromJson(const std::string json_str)
{
init(json_str);
}
void RunNodeFromJson::init(const std::string json_str)
{
YAML::Node node;
if (filefunc::fileExist(json_str))
{
node = YAML::LoadFile(json_str);
}
else
{
node = YAML::Load(json_str);
}
auto n = node["Content"]["Content"]["ObjectData"];
create(n, this);
}
void RunNodeFromJson::create(YAML::Node& n, RunNode* run_node)
{
std::shared_ptr<RunNode> new_node;
auto type = n["ctype"].as<std::string>();
if (type == "TextObjectData")
{
auto t = std::make_shared<TextBox>();
t->setText(n["LabelText"].as<std::string>());
t->setFontSize(n["FontSize"].as<int>());
t->setTextPosition(n["Position"]["X"].as<double>(), n["Position"]["Y"].as<double>());
t->setHaveBox(0);
Color c{ 255, 255, 255, 255 };
t->setTextColor(c, c, c);
new_node = t;
}
else if (type == "ImageViewObjectData")
{
new_node = std::make_shared<RunNode>();
}
else
{
new_node = std::make_shared<RunNode>();
}
run_node->addChild(new_node);
LOG("{}\n", n["ctype"].as<std::string>());
if (n["Children"].IsDefined())
{
for (auto& n1 : n["Children"].as<std::vector<YAML::Node>>())
{
create(n1, new_node.get());
}
}
}