5 #ifndef TILESON_PROJECT_HPP
6 #define TILESON_PROJECT_HPP
12 #include "../objects/ProjectFolder.hpp"
13 #include "../objects/ProjectData.hpp"
20 #ifdef JSON11_IS_DEFINED
21 inline explicit Project(std::unique_ptr<tson::IJson> jsonParser = std::make_unique<tson::Json11>()) : m_json {std::move(jsonParser)}
25 inline explicit Project(
const fs::path &path, std::unique_ptr<tson::IJson> jsonParser = std::make_unique<tson::Json11>());
27 inline explicit Project(std::unique_ptr<tson::IJson> jsonParser) : m_json {std::move(jsonParser)}
31 inline explicit Project(
const fs::path &path, std::unique_ptr<tson::IJson> jsonParser);
33 inline bool parse(
const fs::path &path);
36 [[nodiscard]]
inline const fs::path &
getPath()
const;
37 [[nodiscard]]
inline const std::vector<ProjectFolder> &
getFolders()
const;
40 inline void parseJson(
IJson &json);
42 std::vector<ProjectFolder> m_folders;
44 std::unique_ptr<IJson> m_json =
nullptr;
47 Project::Project(
const fs::path &path, std::unique_ptr<tson::IJson> jsonParser) : m_json {std::move(jsonParser)}
55 std::ifstream i(m_path.u8string());
59 if(!m_json->parse(path))
62 catch(
const std::exception &error)
64 std::string message =
"Parse error: ";
65 message += std::string(error.what());
66 message += std::string(
"\n");
78 void Project::parseJson(
IJson &json)
80 m_data.
basePath = m_path.parent_path();
83 if(json.
count(
"commands") > 0)
86 auto &commands = json.
array(
"commands");
87 std::for_each(commands.begin(), commands.end(), [&](std::unique_ptr<IJson> &item)
89 m_data.commands.emplace_back(item->get<std::string>());
93 if(json.
count(
"folders") > 0)
97 auto &folders = json.
array(
"folders");
98 std::for_each(folders.begin(), folders.end(), [&](std::unique_ptr<IJson> &item)
100 std::string folder = item->get<std::string>();
101 m_data.folders.emplace_back(folder);
102 m_data.folderPaths.emplace_back(m_data.basePath / folder);
103 m_folders.emplace_back(m_data.basePath / folder);
T get(std::string_view key)
Definition: IJson.hpp:72
virtual size_t count(std::string_view key) const =0
virtual std::vector< std::unique_ptr< IJson > > array()=0
Definition: ProjectData.hpp:11
std::string automappingRulesFile
Definition: ProjectData.hpp:14
std::vector< std::string > folders
Definition: ProjectData.hpp:17
fs::path basePath
Definition: ProjectData.hpp:21
std::string objectTypesFile
Definition: ProjectData.hpp:18
std::vector< std::string > commands
Definition: ProjectData.hpp:15
std::string extensionsPath
Definition: ProjectData.hpp:16
std::vector< tson::ProjectFolder > folderPaths
Definition: ProjectData.hpp:22
Definition: Project.hpp:18
const ProjectData & getData() const
Definition: Project.hpp:73
const std::vector< ProjectFolder > & getFolders() const
Definition: Project.hpp:115
const fs::path & getPath() const
Definition: Project.hpp:110
Project(std::unique_ptr< tson::IJson > jsonParser)
Definition: Project.hpp:27
bool parse(const fs::path &path)
Definition: Project.hpp:52
Definition: Base64.hpp:12