From ffeb2e5e02e25174bf0d9040a809a5287ccc83d5 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Sat, 10 May 2025 13:12:10 -0500 Subject: [PATCH] Update Prefab.cpp --- src/src/core/functions/Prefab.cpp | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/src/core/functions/Prefab.cpp b/src/src/core/functions/Prefab.cpp index 2aa73a2..ee36f6c 100644 --- a/src/src/core/functions/Prefab.cpp +++ b/src/src/core/functions/Prefab.cpp @@ -12,24 +12,21 @@ #include #include - namespace fs = std::filesystem; -std::string Prefab::CreatePrefab(const std::shared_ptr& obj) +std::string Prefab::CreatePrefab(const std::shared_ptr &obj) { if (!obj) return ""; // sanitize the prefab filename std::string filename = obj->GetName().empty() ? "Unnamed" : obj->GetName(); - for (auto& ch : filename) + for (auto &ch : filename) if (ch == '/' || ch == '\\' || ch == ':' || ch == '*' || ch == '?' || ch == '\"' || ch == '<' || ch == '>' || ch == '|') ch = '_'; - // build path: //asset/Prefabs - fs::path prefabDir = - fs::path(ProjectManager::GetCurrentAssetsPath()) / "Prefabs"; + fs::path prefabDir = fs::path(ProjectManager::GetCurrentAssetsPath()) / "Prefabs"; std::error_code ec; fs::create_directories(prefabDir, ec); @@ -44,9 +41,12 @@ std::string Prefab::CreatePrefab(const std::shared_ptr& obj) obj->Save(objectOut); YAML::Node objectNode; - try { + try + { objectNode = YAML::Load(objectOut.c_str()); - } catch (const YAML::Exception& e) { + } + catch (const YAML::Exception &e) + { Logger::LogError("[Prefab] Failed to parse object YAML: %s", e.what()); return ""; } @@ -54,19 +54,20 @@ std::string Prefab::CreatePrefab(const std::shared_ptr& obj) YAML::Emitter out; out.SetIndent(2); out << YAML::BeginMap; - out << YAML::Key << "uaid" << YAML::Value << AssetManager::GenerateUAID(); - out << YAML::Key << "filename" << YAML::Value << (filename + ".cpfb"); - out << YAML::Key << "filetype" << YAML::Value << "cpfb"; - out << YAML::Key << "type" << YAML::Value << "Prefab"; - out << YAML::Key << "prefabName" << YAML::Value << obj->GetName(); - out << YAML::Key << "hash" << YAML::Value << ""; + out << YAML::Key << "uaid" << YAML::Value << AssetManager::GenerateUAID(); + out << YAML::Key << "filename" << YAML::Value << (filename + ".cpfb"); + out << YAML::Key << "filetype" << YAML::Value << "cpfb"; + out << YAML::Key << "type" << YAML::Value << "Prefab"; + out << YAML::Key << "prefabName" << YAML::Value << obj->GetName(); + out << YAML::Key << "hash" << YAML::Value << ""; out << YAML::Key << "lastModified" << YAML::Value << GetFileLastWrite(fullPath.string()); - out << YAML::Key << "prefabYAML" << YAML::Value << objectNode; + out << YAML::Key << "prefabYAML" << YAML::Value << objectNode; out << YAML::EndMap; // write out the file std::ofstream file(fullPath); - if (!file.is_open()) { + if (!file.is_open()) + { Logger::LogError("[Prefab] Failed to write prefab file: %s", fullPath.string().c_str()); return "";