1#include "Data/ProjectData.h"
2#include "Data/ApplicationState.h"
3#include "Utils/Utils.h"
6#include <json/json.hpp>
13 return s_ProjectManager;
16ProjectManager::~ProjectManager()
23 s_ProjectManager =
this;
26void ProjectManager::SetId(std::string
id)
31std::string ProjectManager::GetId()
41void ProjectManager::RegisterAsset(std::string uid, std::string path)
43 projectDatase[uid] = path;
46std::string ProjectManager::GetAsset(std::string
id)
48 if(projectDatase.
find(
id) != projectDatase.
end())
50 std::string path = projectDatase[id];
53 for(
int i = 0; i < path.size(); i++)
67bool ProjectManager::AssetExists(std::string
id)
69 return (projectDatase.
find(
id) != projectDatase.
end());
77void ProjectManager::SaveDatabase()
79 if (!PathExist(GetResourcePath()))
81 MkDir(GetResourcePath());
84 SaveToFile(GetResourcePath() + PATH_SEPARATOR
"project_database.terr3d", projectDatase.
dump());
87std::string ProjectManager::GetResourcePath()
89 return GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR
"cache" PATH_SEPARATOR
"project_data" PATH_SEPARATOR
"project_" + GetId();
92std::string ProjectManager::SaveTexture(
Texture2D *texture)
94 return SaveResource(
"textures", texture->GetPath());
97std::string ProjectManager::SaveResource(std::string folder, std::string path)
104 std::string
hash = MD5File(path).ToString();
106 if (GetAsset(hash).size() <= 0)
108 MkDir(GetResourcePath() + PATH_SEPARATOR + folder);
109 CopyFileData(path, GetResourcePath() + PATH_SEPARATOR + folder + PATH_SEPARATOR + hash);
110 RegisterAsset(hash, folder + PATH_SEPARATOR + hash);
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
iterator end() noexcept
returns an iterator to one past the last element
iterator find(KeyT &&key)
find an element in a JSON object
a class to store JSON values
std::size_t hash(const BasicJsonType &j)
hash a JSON value