mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 11:18:22 -05:00
Enable subdirectories for modules
Move newhorizons scene modules into subdirectories
This commit is contained in:
+68
-55
@@ -175,9 +175,14 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
std::sort(keys.begin(), keys.end());
|
||||
ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory();
|
||||
for (const std::string& key : keys) {
|
||||
std::string moduleName = moduleDictionary.value<std::string>(key);
|
||||
std::string modulePath = FileSys.pathByAppendingComponent(sceneDirectory, moduleName);
|
||||
|
||||
std::string fullModuleName = moduleDictionary.value<std::string>(key);
|
||||
std::string modulePath = FileSys.pathByAppendingComponent(sceneDirectory, fullModuleName);
|
||||
|
||||
std::string moduleName = fullModuleName;
|
||||
std::string::size_type pos = fullModuleName.find_last_of(FileSys.PathSeparator);
|
||||
if (pos != std::string::npos)
|
||||
moduleName = fullModuleName.substr(pos + 1);
|
||||
|
||||
if (!FileSys.directoryExists(modulePath)) {
|
||||
LERROR("Could not load module '" << moduleName << "'. Directory did not exist");
|
||||
continue;
|
||||
@@ -188,70 +193,78 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
moduleName + _moduleExtension
|
||||
);
|
||||
|
||||
if (!FileSys.fileExists(moduleFile)) {
|
||||
LERROR("Could not load module file '" << moduleFile << "'. File did not exist");
|
||||
continue;
|
||||
}
|
||||
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
try {
|
||||
ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state);
|
||||
}
|
||||
catch (...) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> keys = moduleDictionary.keys();
|
||||
for (const std::string& key : keys) {
|
||||
if (!moduleDictionary.hasValue<ghoul::Dictionary>(key)) {
|
||||
LERROR("SceneGraphNode '" << key << "' is not a table in module '"
|
||||
<< moduleFile << "'");
|
||||
std::vector<ghoul::Dictionary> moduleDictionaries;
|
||||
if (FileSys.fileExists(moduleFile)) {
|
||||
// We have a module file, so it is a direct include
|
||||
try {
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state);
|
||||
moduleDictionaries.push_back(std::move(moduleDictionary));
|
||||
}
|
||||
catch (...) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// // If we do not have a module file, we have to include all subdirectories
|
||||
// ghoul::filesystem::
|
||||
// ghoul::filesystem::Directory d = modulePath;
|
||||
|
||||
// }
|
||||
|
||||
for (const ghoul::Dictionary& moduleDictionary : moduleDictionaries) {
|
||||
std::vector<std::string> keys = moduleDictionary.keys();
|
||||
for (const std::string& key : keys) {
|
||||
if (!moduleDictionary.hasValue<ghoul::Dictionary>(key)) {
|
||||
LERROR("SceneGraphNode '" << key << "' is not a table in module '"
|
||||
<< moduleFile << "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
ghoul::Dictionary element;
|
||||
std::string nodeName;
|
||||
std::string parentName;
|
||||
ghoul::Dictionary element;
|
||||
std::string nodeName;
|
||||
std::string parentName;
|
||||
|
||||
moduleDictionary.getValue(key, element);
|
||||
element.setValue(KeyPathModule, modulePath);
|
||||
moduleDictionary.getValue(key, element);
|
||||
element.setValue(KeyPathModule, modulePath);
|
||||
|
||||
element.getValue(SceneGraphNode::KeyName, nodeName);
|
||||
element.getValue(SceneGraphNode::KeyParentName, parentName);
|
||||
element.getValue(SceneGraphNode::KeyName, nodeName);
|
||||
element.getValue(SceneGraphNode::KeyParentName, parentName);
|
||||
|
||||
FileSys.setCurrentDirectory(modulePath);
|
||||
SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
|
||||
if (node == nullptr) {
|
||||
LERROR("Error loading SceneGraphNode '" << nodeName << "' in module '" << moduleName << "'");
|
||||
continue;
|
||||
//clear();
|
||||
//return false;
|
||||
}
|
||||
FileSys.setCurrentDirectory(modulePath);
|
||||
SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
|
||||
if (node == nullptr) {
|
||||
LERROR("Error loading SceneGraphNode '" << nodeName << "' in module '" << moduleName << "'");
|
||||
continue;
|
||||
//clear();
|
||||
//return false;
|
||||
}
|
||||
|
||||
dependencies[nodeName].push_back(parentName);
|
||||
parents[nodeName] = parentName;
|
||||
// Also include loaded dependencies
|
||||
dependencies[nodeName].push_back(parentName);
|
||||
parents[nodeName] = parentName;
|
||||
// Also include loaded dependencies
|
||||
|
||||
if (element.hasKey(SceneGraphNode::KeyDependencies)) {
|
||||
if (element.hasValue<ghoul::Dictionary>(SceneGraphNode::KeyDependencies)) {
|
||||
ghoul::Dictionary nodeDependencies;
|
||||
element.getValue(SceneGraphNode::KeyDependencies, nodeDependencies);
|
||||
if (element.hasKey(SceneGraphNode::KeyDependencies)) {
|
||||
if (element.hasValue<ghoul::Dictionary>(SceneGraphNode::KeyDependencies)) {
|
||||
ghoul::Dictionary nodeDependencies;
|
||||
element.getValue(SceneGraphNode::KeyDependencies, nodeDependencies);
|
||||
|
||||
std::vector<std::string> keys = nodeDependencies.keys();
|
||||
for (const std::string& key : keys) {
|
||||
std::string value = nodeDependencies.value<std::string>(key);
|
||||
dependencies[nodeName].push_back(value);
|
||||
std::vector<std::string> keys = nodeDependencies.keys();
|
||||
for (const std::string& key : keys) {
|
||||
std::string value = nodeDependencies.value<std::string>(key);
|
||||
dependencies[nodeName].push_back(value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
LERROR("Dependencies did not have the corrent type");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LERROR("Dependencies did not have the corrent type");
|
||||
}
|
||||
|
||||
|
||||
SceneGraphNodeInternal* internalNode = new SceneGraphNodeInternal;
|
||||
internalNode->node = node;
|
||||
_nodes.push_back(internalNode);
|
||||
}
|
||||
|
||||
|
||||
SceneGraphNodeInternal* internalNode = new SceneGraphNodeInternal;
|
||||
internalNode->node = node;
|
||||
_nodes.push_back(internalNode);
|
||||
}
|
||||
}
|
||||
ghoul::lua::destroyLuaState(state);
|
||||
|
||||
Reference in New Issue
Block a user