5#ifndef TILESON_PROJECT_HPP
6#define TILESON_PROJECT_HPP
12#include "../objects/ProjectPropertyTypes.hpp"
13#include "../objects/ProjectFolder.hpp"
14#include "../objects/ProjectData.hpp"
22 #ifdef JSON11_IS_DEFINED
23 inline explicit Project(std::unique_ptr<tson::IJson> jsonParser = std::make_unique<tson::Json11>()) : m_json {std::move(jsonParser)}
27 inline explicit Project(
const fs::path &path, std::unique_ptr<tson::IJson> jsonParser = std::make_unique<tson::Json11>());
29 inline explicit Project(std::unique_ptr<tson::IJson> jsonParser) : m_json {std::move(jsonParser)}
33 inline explicit Project(
const fs::path &path, std::unique_ptr<tson::IJson> jsonParser);
35 inline bool parse(
const fs::path &path);
39 [[nodiscard]]
inline const fs::path &
getPath()
const;
40 [[nodiscard]]
inline const std::vector<ProjectFolder> &
getFolders()
const;
46 inline void parseJson(
IJson &json);
48 std::vector<ProjectFolder> m_folders;
50 std::unique_ptr<IJson> m_json =
nullptr;
53 Project::Project(
const fs::path &path, std::unique_ptr<tson::IJson> jsonParser) : m_json {std::move(jsonParser)}
61 std::ifstream i(m_path.generic_string());
65 if(!m_json->parse(path))
68 catch(
const std::exception &error)
70 std::string message =
"Parse error: ";
71 message += std::string(error.what());
72 message += std::string(
"\n");
84 void Project::parseJson(
IJson &json)
86 m_data.
basePath = (m_path.empty()) ? fs::path() : m_path.parent_path();
89 if(json.
count(
"propertyTypes") > 0)
95 if(json.
count(
"commands") > 0)
98 auto &commands = json.
array(
"commands");
99 std::for_each(commands.begin(), commands.end(), [&](std::unique_ptr<IJson> &item)
101 m_data.commands.emplace_back(item->get<std::string>());
105 if(json.
count(
"folders") > 0)
109 auto &folders = json.
array(
"folders");
110 std::for_each(folders.begin(), folders.end(), [&](std::unique_ptr<IJson> &item)
112 std::string folder = item->get<std::string>();
113 m_data.folders.emplace_back(folder);
114 m_data.folderPaths.emplace_back(m_data.basePath / folder);
115 m_folders.emplace_back(m_data.basePath / folder);
Definition TiledEnum.hpp:11
T get(std::string_view key)
Definition IJson.hpp:82
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
ProjectPropertyTypes projectPropertyTypes
Definition ProjectData.hpp:19
std::vector< std::string > folders
Definition ProjectData.hpp:17
fs::path basePath
Definition ProjectData.hpp:22
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:23
tson::EnumDefinition * getEnumDefinition(std::string_view name)
Definition ProjectPropertyTypes.hpp:86
tson::TiledClass * getClass(std::string_view name)
Definition ProjectPropertyTypes.hpp:99
bool parse(IJson &json, tson::Project *project)
Definition ProjectPropertyTypes.hpp:29
Definition Project.hpp:20
const ProjectData & getData() const
Definition Project.hpp:79
tson::EnumDefinition * getEnumDefinition(std::string_view name)
Definition Project.hpp:131
void parse()
Definition Project.hpp:145
const std::vector< ProjectFolder > & getFolders() const
Definition Project.hpp:126
tson::TiledClass * getClass(std::string_view name)
Definition Project.hpp:136
const fs::path & getPath() const
Definition Project.hpp:121
Project(std::unique_ptr< tson::IJson > jsonParser)
Definition Project.hpp:29
Definition TiledClass.hpp:11