11#ifndef _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
12#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
14#include <experimental/filesystem>
16namespace fs = std::experimental::filesystem;
51 if (
j.contains(
"id"))
tpl.
id =
j[
"id"].get<std::string>();
52 if (
j.contains(
"name"))
tpl.name =
j[
"name"].get<std::string>();
53 if (
j.contains(
"description"))
tpl.description =
j[
"description"].get<std::string>();
54 if (
j.contains(
"category"))
tpl.category =
j[
"category"].get<std::string>();
55 if (
j.contains(
"author"))
tpl.author =
j[
"author"].get<std::string>();
56 if (
j.contains(
"version"))
tpl.version =
j[
"version"].get<std::string>();
57 if (
j.contains(
"thumbnailPath"))
tpl.thumbnailPath =
j[
"thumbnailPath"].get<std::string>();
58 if (
j.contains(
"createdDate"))
tpl.createdDate =
static_cast<time_t>(
j[
"createdDate"].get<
double>());
59 if (
j.contains(
"modifiedDate"))
tpl.modifiedDate =
static_cast<time_t>(
j[
"modifiedDate"].get<
double>());
60 if (
j.contains(
"blueprintData"))
tpl.blueprintData =
j[
"blueprintData"];
69 std::ofstream
file(filepath);
72 std::cerr <<
"Failed to open file for writing: " << filepath << std::endl;
82 catch (
const std::exception&
e)
84 std::cerr <<
"Error saving template to file: " <<
e.what() << std::endl;
93 std::ifstream
file(filepath);
96 std::cerr <<
"Failed to open template file: " << filepath << std::endl;
107 catch (
const std::exception&
e)
109 std::cerr <<
"Error loading template from file: " <<
e.what() << std::endl;
125 : m_Initialized(
false)
188 if (!
tpl.SaveToFile(filepath))
190 m_LastError =
"Failed to save template to file: " + filepath;
227 return tpl.id == templateId;
242 if (fs::exists(filepath))
244 fs::remove(filepath);
247 catch (
const std::exception&
e)
249 m_LastError =
"Failed to delete template file: " + std::string(
e.what());
279 std::vector<BlueprintTemplate>
result;
283 if (
tpl.category == category)
294 std::vector<std::string> categories;
299 if (std::find(categories.begin(), categories.end(),
tpl.category) == categories.end())
301 categories.push_back(
tpl.category);
325 const std::string& name,
326 const std::string& description,
327 const std::string& category,
328 const std::string& author)
334 tpl.description = description;
335 tpl.category = category;
339 tpl.thumbnailPath =
"";
340 tpl.createdDate = std::time(
nullptr);
341 tpl.modifiedDate =
tpl.createdDate;
349 std::random_device
rd;
350 std::mt19937
gen(
rd());
351 std::uniform_int_distribution<>
dis(0, 15);
353 const char*
hexChars =
"0123456789abcdef";
381 if (fs::is_regular_file(
entry.path()) &&
entry.path().extension() ==
".json")
393 catch (
const std::exception&
e)
395 m_LastError =
"Error scanning template directory: " + std::string(
e.what());
404 if (!fs::exists(path))
406 fs::create_directories(path);
410 catch (
const std::exception&
e)
412 std::cerr <<
"Failed to create directory: " << path <<
" - " <<
e.what() << std::endl;
ComponentTypeID GetComponentTypeID_Static()
static std::mt19937 gen(rd())
static std::random_device rd
TemplateManager - Manages blueprint templates Singleton manager for template catalog and operations.
bool SaveTemplate(const BlueprintTemplate &tpl)
std::string m_TemplatesPath
void Initialize(const std::string &templatesPath="Blueprints/Templates")
std::string GenerateUUID() const
bool DeleteTemplate(const std::string &templateId)
std::vector< BlueprintTemplate > m_Templates
bool EnsureDirectoryExists(const std::string &path)
std::vector< BlueprintTemplate > GetTemplatesByCategory(const std::string &category) const
bool ApplyTemplateToBlueprint(const std::string &templateId, json &targetBlueprint)
static TemplateManager & Instance()
const BlueprintTemplate * FindTemplate(const std::string &id) const
void ScanTemplateDirectory()
bool LoadTemplates(const std::string &templatesPath)
BlueprintTemplate CreateTemplateFromBlueprint(const json &blueprint, const std::string &name, const std::string &description, const std::string &category, const std::string &author="User")
std::vector< std::string > GetAllCategories() const
BlueprintTemplate - Template metadata and data Stores a complete blueprint that can be reused as a te...
std::string thumbnailPath
static BlueprintTemplate LoadFromFile(const std::string &filepath)
static BlueprintTemplate FromJson(const json &j)
bool SaveToFile(const std::string &filepath) const