forked from ObEngine/ObEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataParserLuaBridge.cpp
More file actions
147 lines (139 loc) · 5.08 KB
/
Copy pathDataParserLuaBridge.cpp
File metadata and controls
147 lines (139 loc) · 5.08 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "DataParserLuaBridge.hpp"
namespace obe
{
namespace Data
{
namespace DataBridge
{
void dataToLua(kaguya::LuaTable& target, vili::Attribute& convert)
{
}
vili::Attribute* luaToData(kaguya::LuaRef& convert)
{
//return Attribute();
return nullptr;
}
void complexAttributeToLuaTable(kaguya::LuaTable& target, vili::ComplexAttribute& convert)
{
target[convert.getID()] = kaguya::NewTable();
kaguya::LuaTable injectTable = target[convert.getID()];
kaguya::State olol;
for (std::string elementName : convert.getAll())
{
if (convert.getAttributeType(elementName) == vili::Types::BaseAttribute)
{
baseAttributeToLuaElement(injectTable, *convert.getBaseAttribute(elementName));
}
else if (convert.getAttributeType(elementName) == vili::Types::ComplexAttribute)
{
complexAttributeToLuaTable(injectTable, *convert.getComplexAttribute(elementName));
}
else if (convert.getAttributeType(elementName) == vili::Types::ListAttribute)
{
listAttributeToLuaTable(injectTable, *convert.getListAttribute(elementName));
}
}
target[convert.getID()] = injectTable;
}
void baseAttributeToLuaElement(kaguya::LuaTable& target, vili::BaseAttribute& convert)
{
if (convert.getDataType() == vili::Types::Int)
target[convert.getID()] = convert.get<int>();
else if (convert.getDataType() == vili::Types::String)
target[convert.getID()] = convert.get<std::string>();
else if (convert.getDataType() == vili::Types::Bool)
target[convert.getID()] = convert.get<bool>();
else if (convert.getDataType() == vili::Types::Float)
{
double val = convert.get<double>();
std::string vid = convert.getID();
target[vid] = val;
}
}
void listAttributeToLuaTable(kaguya::LuaTable& target, vili::ListAttribute& convert)
{
kaguya::LuaTable injectList;
for (int i = 0; i < convert.size(); i++)
{
injectList[i] = convert.get(i);
}
target[convert.getID()] = injectList;
}
vili::ComplexAttribute* luaTableToComplexAttribute(std::string id, kaguya::LuaRef& convert)
{
std::cout << "Convert table : " << id << std::endl;
vili::ComplexAttribute* returnElement = new vili::ComplexAttribute(id);
if (convert.type() == 0 || convert.type() == 5)
{
std::map<std::string, kaguya::LuaRef> tableMap = convert;
for (std::pair<std::string, kaguya::LuaRef> tableItem : tableMap)
{
std::string tableKey = tableItem.first;
if (convert[tableKey].type() == 5)
{
std::cout << "Push subtable : " << tableKey << std::endl;
kaguya::LuaRef tempTableRef = convert[tableKey];
returnElement->pushComplexAttribute(luaTableToComplexAttribute(tableKey, tempTableRef));
}
else if (Functions::Vector::isInList(convert[tableKey].type(), std::vector<int>({ 1, 3, 4 })))
{
std::cout << "Push subelement : " << tableKey << std::endl;
kaguya::LuaRef tempElemRef = convert[tableKey];
returnElement->pushBaseAttribute(luaElementToBaseAttribute(tableKey, tempElemRef));
}
}
}
else
throw aube::ErrorHandler::Raise("ObEngine.DataParserLuaBridge.LuaTableToComplexAttribute.NotATable", { { "id", id } });
return returnElement;
}
vili::BaseAttribute* luaElementToBaseAttribute(std::string id, kaguya::LuaRef& convert)
{
std::string luaElement = convert;
std::string convertType = "";
if (convert.type() == 3 && Functions::String::isStringInt(luaElement))
{
convertType = "int";
}
else if (convert.type() == 3 && vili::Functions::String::isStringFloat(luaElement))
{
convertType = "float";
}
else if (convert.type() == 1)
{
convertType = "bool";
}
else if (convert.type() == 4)
{
convertType = "string";
}
return new vili::BaseAttribute(id, vili::Types::stringToDataType(convertType), convert);
}
vili::ListAttribute* luaTableToListAttribute(std::string id, kaguya::LuaTable& convert)
{
/*ListAttribute* returnElement = new ListAttribute(id, dataType);
std::cout << "Table Type : " << convert.type() << std::endl;
if (convert.type() == 0 || convert.type() == 5) {
std::map<std::string, kaguya::LuaRef> tableMap = convert;
for (std::pair<std::string, kaguya::LuaRef> tableItem : tableMap) {
std::string tableKey = tableItem.first;
std::cout << "Current Table Key : " << tableKey << std::endl;
if (convert[tableKey].type() == 5) {
kaguya::LuaRef tempTableRef = convert[tableKey];
returnElement->pushComplexAttribute(luaTableToComplexAttribute(tableKey, tempTableRef));
}
else if (Functions::Vector::isInList(convert[tableKey].type(), std::vector<int>({ 1, 3, 4 }))) {
kaguya::LuaRef tempElemRef = convert[tableKey];
returnElement->pushBaseAttribute(luaElementToBaseAttribute(tableKey, tempElemRef));
}
}
}
else {
std::cout << "<Error:DataParserLuaBridge:DataBridge>[luaTableToComplexAttribute] LuaElement " << id << " is not a table" << std::endl;
}
return returnElement;*/
return nullptr;
}
}
}
}