diff --git a/src/App/Extensions/QuestPhase/Module.cpp b/src/App/Extensions/QuestPhase/Module.cpp index b6d645a..640dfd9 100644 --- a/src/App/Extensions/QuestPhase/Module.cpp +++ b/src/App/Extensions/QuestPhase/Module.cpp @@ -101,14 +101,7 @@ void App::QuestPhaseModule::PatchPhase(Red::Handle for (const auto& phaseMod : phaseMods.value()) { - if (PatchPhase(aPhaseResource, phaseMod)) - { - LogInfo(R"(|{}| Merged phase "{}" from "{}".)", ModuleName, phaseMod.phasePath, phaseMod.mod); - } - else - { - LogWarning(R"(|{}| Can't merge phase "{}" from "{}".)", ModuleName, phaseMod.phasePath, phaseMod.mod); - } + PatchPhase(aPhaseResource, phaseMod); } } @@ -117,18 +110,32 @@ bool App::QuestPhaseModule::PatchPhase(Red::Handle { auto& rootPhaseGraph = Red::Cast(aPhaseResource->graph); if (!rootPhaseGraph) + { + LogWarning(R"(|{}| Can't merge phase "{}" from "{}", parent phase is not loaded.)", + ModuleName, aPhaseMod.phasePath, aPhaseMod.mod); return false; + } auto [targetPhaseGraph, targetNode] = FindConnectionPoint(rootPhaseGraph, aPhaseMod.connection); if (!targetPhaseGraph || !targetNode) + { + LogWarning(R"(|{}| Can't merge phase "{}" from "{}", connection node doesn't exist.)", + ModuleName, aPhaseMod.phasePath, aPhaseMod.mod); return false; + } - auto modPhaseNode = CreatePhaseNode(targetPhaseGraph, aPhaseMod); + auto modPhaseNode = CreatePhaseNode(targetPhaseGraph, aPhaseMod, targetNode->id); if (!modPhaseNode) + { + LogWarning(R"(|{}| Can't merge phase "{}" from "{}", node with the same id already exists.)", + ModuleName, aPhaseMod.phasePath, aPhaseMod.mod); return false; + } AddConnection(targetNode, modPhaseNode); + LogInfo(R"(|{}| Merged phase "{}" from "{}".)", ModuleName, aPhaseMod.phasePath, aPhaseMod.mod); + return true; } @@ -204,9 +211,10 @@ void App::QuestPhaseModule::AddConnection(Red::Handle& } Red::Handle App::QuestPhaseModule::CreatePhaseNode( - const Red::Handle& aPhaseGraph, const QuestPhaseMod& aPhaseMod) + const Red::Handle& aPhaseGraph, const QuestPhaseMod& aPhaseMod, uint16_t aParentId) { - auto phaseNodeId = GeneratePhaseNodeID(aPhaseMod.phasePath.data(), aPhaseMod.phasePath.size()); + auto phaseNodeKey = aPhaseMod.phasePath + ":" + std::to_string(aParentId); + auto phaseNodeId = GeneratePhaseNodeID(phaseNodeKey.data(), phaseNodeKey.size()); for (const auto& node : aPhaseGraph->nodes) { diff --git a/src/App/Extensions/QuestPhase/Module.hpp b/src/App/Extensions/QuestPhase/Module.hpp index 147c5b3..6455c52 100644 --- a/src/App/Extensions/QuestPhase/Module.hpp +++ b/src/App/Extensions/QuestPhase/Module.hpp @@ -33,7 +33,7 @@ class QuestPhaseModule : public ConfigurableUnitModule Red::CName aSocketName); static void AddConnection(Red::Handle& aOut, Red::Handle& aIn); static Red::Handle CreatePhaseNode( - const Red::Handle& aPhaseGraph, const QuestPhaseMod& aPhaseMod); + const Red::Handle& aPhaseGraph, const QuestPhaseMod& aPhaseMod, uint16_t aParentId); static uint16_t GeneratePhaseNodeID(const char* aData, uint32_t aLength); inline static Core::Map> s_phases;