|
@@ -454,83 +454,101 @@ namespace sushi
|
|
|
|
|
|
|
|
LoadeData loaded;
|
|
LoadeData loaded;
|
|
|
|
|
|
|
|
- if (!loadAllData(data, loaded)) { return 0; }
|
|
|
|
|
|
|
+ if (!loadAllData(data, loaded)) { *this = {}; return 0; }
|
|
|
|
|
|
|
|
if (loaded.mainParent)
|
|
if (loaded.mainParent)
|
|
|
{
|
|
{
|
|
|
unsigned int oldId = root.id;
|
|
unsigned int oldId = root.id;
|
|
|
root = *loaded.mainParent;
|
|
root = *loaded.mainParent;
|
|
|
root.id = oldId;
|
|
root.id = oldId;
|
|
|
|
|
+ root.orderedElementsIds = {};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SushiParent *parentToAddTo = &root;
|
|
SushiParent *parentToAddTo = &root;
|
|
|
|
|
|
|
|
- //todo if no loaded.mainParent we will make the first found parent root
|
|
|
|
|
|
|
+ //todo if no loaded.mainParent we will make a default root
|
|
|
|
|
|
|
|
if (!loaded.parents.empty())
|
|
if (!loaded.parents.empty())
|
|
|
{
|
|
{
|
|
|
|
|
+ struct ParentPair
|
|
|
|
|
+ {
|
|
|
|
|
+ SushiParent *element = 0;
|
|
|
|
|
+ SushiParent *parentToAddTo = 0;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<ParentPair> parentsToAdd;
|
|
|
|
|
+
|
|
|
#pragma region find first parent
|
|
#pragma region find first parent
|
|
|
- SushiParent *firstParent = 0;
|
|
|
|
|
if (loaded.mainParent)
|
|
if (loaded.mainParent)
|
|
|
{
|
|
{
|
|
|
- firstParent = &(*loaded.mainParent);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
|
|
+ for (auto &id : loaded.mainParent->orderedElementsIds)
|
|
|
{
|
|
{
|
|
|
- //determine the main parent
|
|
|
|
|
- std::unordered_set<unsigned int> allparentsids;
|
|
|
|
|
- for (auto &p : loaded.parents)
|
|
|
|
|
|
|
+ bool found = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (auto &e : loaded.parents)
|
|
|
{
|
|
{
|
|
|
- if (allparentsids.find(p.id) != allparentsids.end())
|
|
|
|
|
|
|
+ if (e.id == id)
|
|
|
{
|
|
{
|
|
|
- return 0;
|
|
|
|
|
|
|
+ parentsToAdd.push_back({&e,&this->root});
|
|
|
|
|
+ found = true;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- allparentsids.insert(p.id);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for (auto &p : loaded.parents)
|
|
|
|
|
|
|
+ if (!found) { *this = {}; return 0; }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else //not tested
|
|
|
|
|
+ {
|
|
|
|
|
+ SushiParent *firstParent = 0;
|
|
|
|
|
+
|
|
|
|
|
+ //determine the main parent
|
|
|
|
|
+ std::unordered_set<unsigned int> allparentsids;
|
|
|
|
|
+ for (auto &p : loaded.parents)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (allparentsids.find(p.id) != allparentsids.end())
|
|
|
{
|
|
{
|
|
|
- for (auto &id : p.orderedElementsIds)
|
|
|
|
|
- {
|
|
|
|
|
- auto f = allparentsids.find(id);
|
|
|
|
|
- if (f != allparentsids.end())
|
|
|
|
|
- {
|
|
|
|
|
- allparentsids.erase(f);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ *this = {};
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+ allparentsids.insert(p.id);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //we found the main parent id
|
|
|
|
|
- if (allparentsids.size() == 1)
|
|
|
|
|
|
|
+ for (auto &p : loaded.parents)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (auto &id : p.orderedElementsIds)
|
|
|
{
|
|
{
|
|
|
- unsigned int id = *allparentsids.begin();
|
|
|
|
|
-
|
|
|
|
|
- for (auto &p : loaded.parents)
|
|
|
|
|
|
|
+ auto f = allparentsids.find(id);
|
|
|
|
|
+ if (f != allparentsids.end())
|
|
|
{
|
|
{
|
|
|
- if (p.id == id)
|
|
|
|
|
- {
|
|
|
|
|
- firstParent = &p;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ allparentsids.erase(f);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //we found the main parent id
|
|
|
|
|
+ if (allparentsids.size() == 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ unsigned int id = *allparentsids.begin();
|
|
|
|
|
+
|
|
|
|
|
+ for (auto &p : loaded.parents)
|
|
|
{
|
|
{
|
|
|
- return 0;
|
|
|
|
|
|
|
+ if (p.id == id)
|
|
|
|
|
+ {
|
|
|
|
|
+ firstParent = &p;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- #pragma endregion
|
|
|
|
|
-
|
|
|
|
|
- if (!firstParent) { return 0; }
|
|
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ *this = {};
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- struct ParentPair
|
|
|
|
|
- {
|
|
|
|
|
- SushiParent *element = 0;
|
|
|
|
|
- SushiParent *parentToAddTo = 0;
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ parentsToAdd.push_back({firstParent, parentToAddTo});
|
|
|
|
|
+ }
|
|
|
|
|
+ #pragma endregion
|
|
|
|
|
|
|
|
- std::vector<ParentPair> parentsToAdd;
|
|
|
|
|
- parentsToAdd.push_back({firstParent, parentToAddTo});
|
|
|
|
|
|
|
|
|
|
while (parentsToAdd.size())
|
|
while (parentsToAdd.size())
|
|
|
{
|
|
{
|
|
@@ -540,27 +558,23 @@ namespace sushi
|
|
|
addParent(*currentP.parentToAddTo, currentP.element->name, currentP.element->transform,
|
|
addParent(*currentP.parentToAddTo, currentP.element->name, currentP.element->transform,
|
|
|
currentP.element->background);
|
|
currentP.element->background);
|
|
|
|
|
|
|
|
- bool found = 0;
|
|
|
|
|
for (auto &id : currentP.element->orderedElementsIds)
|
|
for (auto &id : currentP.element->orderedElementsIds)
|
|
|
{
|
|
{
|
|
|
|
|
+ bool found = 0;
|
|
|
|
|
|
|
|
- if (!found)
|
|
|
|
|
|
|
+ for (auto &e : loaded.parents)
|
|
|
{
|
|
{
|
|
|
- for (auto &e : loaded.parents)
|
|
|
|
|
|
|
+ if (e.id == id)
|
|
|
{
|
|
{
|
|
|
- if (e.id == id)
|
|
|
|
|
- {
|
|
|
|
|
- parentsToAdd.push_back({&e,currentP.element});
|
|
|
|
|
- found = true;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ parentsToAdd.push_back({&e,currentP.element});
|
|
|
|
|
+ found = true;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (found) { break; }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (!found) { *this = {}; return 0; }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!found) { return 0; }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|