Skip to content

Commit

Permalink
Allow multiple connections for quest phases
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Feb 29, 2024
1 parent 4b9f56c commit 5f36d77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/App/Extensions/QuestPhase/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,7 @@ void App::QuestPhaseModule::PatchPhase(Red::Handle<Red::questQuestPhaseResource>

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);
}
}

Expand All @@ -117,18 +110,32 @@ bool App::QuestPhaseModule::PatchPhase(Red::Handle<Red::questQuestPhaseResource>
{
auto& rootPhaseGraph = Red::Cast<Red::questGraphDefinition>(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;
}

Expand Down Expand Up @@ -204,9 +211,10 @@ void App::QuestPhaseModule::AddConnection(Red::Handle<Red::questNodeDefinition>&
}

Red::Handle<Red::questPhaseNodeDefinition> App::QuestPhaseModule::CreatePhaseNode(
const Red::Handle<Red::questGraphDefinition>& aPhaseGraph, const QuestPhaseMod& aPhaseMod)
const Red::Handle<Red::questGraphDefinition>& 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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/App/Extensions/QuestPhase/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QuestPhaseModule : public ConfigurableUnitModule<QuestPhaseUnit>
Red::CName aSocketName);
static void AddConnection(Red::Handle<Red::questNodeDefinition>& aOut, Red::Handle<Red::questNodeDefinition>& aIn);
static Red::Handle<Red::questPhaseNodeDefinition> CreatePhaseNode(
const Red::Handle<Red::questGraphDefinition>& aPhaseGraph, const QuestPhaseMod& aPhaseMod);
const Red::Handle<Red::questGraphDefinition>& aPhaseGraph, const QuestPhaseMod& aPhaseMod, uint16_t aParentId);
static uint16_t GeneratePhaseNodeID(const char* aData, uint32_t aLength);

inline static Core::Map<Red::ResourcePath, Core::Vector<QuestPhaseMod>> s_phases;
Expand Down

0 comments on commit 5f36d77

Please sign in to comment.