forked from ObEngine/ObEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathResolver.cpp
More file actions
120 lines (116 loc) · 4.62 KB
/
Copy pathPathResolver.cpp
File metadata and controls
120 lines (116 loc) · 4.62 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
#include "PathResolver.hpp"
namespace obe
{
namespace System
{
namespace Loaders
{
std::function<int(sf::Texture*, std::string)> textureLoader = [](sf::Texture* obj, std::string path) -> int { return obj->loadFromFile(path); };
std::function<int(vili::DataParser*, std::string)> dataLoader = [](vili::DataParser* obj, std::string path) -> int { return obj->parseFile(path); };
std::function<int(sf::Font*, std::string)> fontLoader = [](sf::Font* obj, std::string path) -> int { return obj->loadFromFile(path); };
std::function<int(std::vector<std::string>*, std::string)> dirPathLoader = [](std::vector<std::string>* obj, std::string path) -> int {
std::vector<std::string> newPaths = Functions::File::listDirInDir(path);
obj->insert(obj->end(), newPaths.begin(), newPaths.end());
return 0x002;
};
std::function<int(std::vector<std::string>*, std::string)> filePathLoader = [](std::vector<std::string>* obj, std::string path) -> int {
std::vector<std::string> newFiles = Functions::File::listFileInDir(path);
obj->insert(obj->end(), newFiles.begin(), newFiles.end());
return 0x002;
};
std::function<int(kaguya::State*, std::string)> luaLoader = [](kaguya::State* obj, std::string path) -> int { return obj->dofile(path); };
std::function<int(sf::SoundBuffer*, std::string)> soundLoader = [](sf::SoundBuffer* sound, std::string path) -> int { return sound->loadFromFile(path); };
std::function<int(sf::Music*, std::string)> musicLoader = [](sf::Music* music, std::string path) -> int { return music->openFromFile(path); };
}
PriorizedPath::PriorizedPath(PathType::PathType pathType, std::string basePath, unsigned int priority)
{
this->pathType = pathType;
this->basePath = basePath;
this->priority = priority;
}
std::string PriorizedPath::getPath() const
{
return basePath;
}
std::vector<PriorizedPath> Path::basePaths = std::vector<PriorizedPath>();
void Path::orderPriorizedPaths()
{
bool noChange = false;
while (noChange == false)
{
noChange = true;
for (unsigned int i = 0; i < basePaths.size(); i++)
{
if (i != basePaths.size() - 1 && basePaths[i].priority < basePaths[i + 1].priority)
{
std::iter_swap(basePaths.begin() + i, basePaths.begin() + i + 1);
noChange = false;
}
}
}
}
Path::Path()
{
this->path = "";
}
Path::Path(const Path& path)
{
this->path = path.toString();
}
Path::Path(std::string path)
{
this->path = path;
}
Path Path::add(std::string path) const
{
return Path(this->path + "/" + path);
}
std::string Path::getPath(int index)
{
if (basePaths.size() > index)
return basePaths[index].getPath() + ((basePaths[index].getPath() != "") ? "/" : "") + this->path;
throw aube::ErrorHandler::Raise("ObEngine.PathResolver.Path.UnknownPathAtIndex", { {"index", std::to_string(index)}, {"path", path} });
}
std::string Path::toString() const
{
return this->path;
}
void Path::addPath(PriorizedPath path)
{
basePaths.push_back(path);
orderPriorizedPaths();
}
std::vector<PriorizedPath>& Path::Paths()
{
return basePaths;
}
void MountPaths()
{
Path::basePaths.clear();
vili::DataParser mountedPaths;
mountedPaths.parseFile("Mount.vili", true);
for (std::string path : mountedPaths->at("Mount")->getAll(vili::Types::ComplexAttribute)) {
vili::ComplexAttribute* currentElement = mountedPaths->at("Mount", path);
std::string currentType = currentElement->at<vili::BaseAttribute>("type")->get<std::string>();
std::string currentPath = currentElement->at<vili::BaseAttribute>("path")->get<std::string>();
int currentPriority = currentElement->at<vili::BaseAttribute>("priority")->get<int>();
if (currentType == "Path") {
obe::System::Path::addPath(obe::System::PriorizedPath(obe::System::PathType::Path, currentPath, currentPriority));
std::cout << "Mounted Path : <" << currentPath << "> with priority : " << currentPriority << std::endl;
}
else if (currentType == "Package") {
System::Package::Load(currentPath, currentPriority);
std::cout << "Mounted Package : <" << currentPath << "> with priority : " << currentPriority << std::endl;
}
else if (currentType == "Workspace") {
System::Workspace::Load(currentPath, currentPriority);
std::cout << "Mounted Workspace : <" << currentPath << "> with priority : " << currentPriority << std::endl;
}
}
std::cout << "<System> List of mounted paths : " << std::endl;
for (obe::System::PriorizedPath& currentPath : obe::System::Path::basePaths) {
std::cout << " <System> MountedPath : " << currentPath.getPath() << std::endl;
}
}
}
}