Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
Olympe::SubgraphMigrator Class Reference

Converts legacy blueprint JSON to the Phase 8 subgraph flat-dict format. More...

#include <SubgraphMigrator.h>

Public Member Functions

 SubgraphMigrator ()=default
 
 ~SubgraphMigrator ()=default
 
bool NeedsMigration (const nlohmann::json &blueprint) const
 Returns true when the blueprint uses the legacy format (data.nodes exists at the top level of the data object).
 
bool IsNewFormat (const nlohmann::json &blueprint) const
 Returns true when the blueprint is already in the Phase 8 format (data.rootGraph exists).
 
nlohmann::json Migrate (const nlohmann::json &blueprint) const
 Migrates a legacy blueprint to the flat-dictionary format.
 

Static Public Member Functions

static nlohmann::json MakeEmptySubgraph (const std::string &name, const std::string &uuid, const std::string &blueprintType)
 Creates an empty subgraph definition JSON object.
 
static bool ValidateSubgraphReferences (const nlohmann::json &blueprint, std::string &outError)
 Validates that every subgraphUUID referenced by SubGraph nodes actually exists in data.subgraphs and that there are no circular dependencies (A -> B -> A).
 

Private Member Functions

void MigrateDataSection (nlohmann::json &blueprint) const
 

Static Private Member Functions

static bool HasCycle (const std::string &start, const nlohmann::json &subgraphs, std::vector< std::string > &visited, std::vector< std::string > &inStack)
 
static std::vector< std::string > CollectSubgraphRefs (const nlohmann::json &graphObj)
 

Detailed Description

Converts legacy blueprint JSON to the Phase 8 subgraph flat-dict format.

Usage:

if (m.NeedsMigration(blueprint))
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Converts legacy blueprint JSON to the Phase 8 subgraph flat-dict format.
nlohmann::json Migrate(const nlohmann::json &blueprint) const
Migrates a legacy blueprint to the flat-dictionary format.

Definition at line 44 of file SubgraphMigrator.h.

Constructor & Destructor Documentation

◆ SubgraphMigrator()

Olympe::SubgraphMigrator::SubgraphMigrator ( )
default

◆ ~SubgraphMigrator()

Olympe::SubgraphMigrator::~SubgraphMigrator ( )
default

Member Function Documentation

◆ CollectSubgraphRefs()

std::vector< std::string > Olympe::SubgraphMigrator::CollectSubgraphRefs ( const nlohmann::json graphObj)
staticprivate

Definition at line 249 of file SubgraphMigrator.cpp.

References GetComponentTypeID_Static().

Referenced by HasCycle(), and ValidateSubgraphReferences().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasCycle()

bool Olympe::SubgraphMigrator::HasCycle ( const std::string &  start,
const nlohmann::json subgraphs,
std::vector< std::string > &  visited,
std::vector< std::string > &  inStack 
)
staticprivate

Definition at line 219 of file SubgraphMigrator.cpp.

References CollectSubgraphRefs(), GetComponentTypeID_Static(), and HasCycle().

Referenced by HasCycle(), and ValidateSubgraphReferences().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsNewFormat()

bool Olympe::SubgraphMigrator::IsNewFormat ( const nlohmann::json blueprint) const

Returns true when the blueprint is already in the Phase 8 format (data.rootGraph exists).

Definition at line 45 of file SubgraphMigrator.cpp.

References GetComponentTypeID_Static().

Referenced by Migrate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeEmptySubgraph()

json Olympe::SubgraphMigrator::MakeEmptySubgraph ( const std::string &  name,
const std::string &  uuid,
const std::string &  blueprintType 
)
static

Creates an empty subgraph definition JSON object.

Parameters
nameHuman-readable name shown in the tab.
uuidPre-generated UUID string for this subgraph.
blueprintType"BehaviorTree" or "HFSM".
Returns
JSON object suitable for insertion into data.subgraphs[uuid].

Definition at line 119 of file SubgraphMigrator.cpp.

References GetComponentTypeID_Static().

+ Here is the call graph for this function:

◆ Migrate()

nlohmann::json Olympe::SubgraphMigrator::Migrate ( const nlohmann::json blueprint) const

Migrates a legacy blueprint to the flat-dictionary format.

Parameters
blueprintInput JSON (may be legacy or already new format).
Returns
Migrated JSON in new format. If already new, a copy is returned.

Definition at line 58 of file SubgraphMigrator.cpp.

References GetComponentTypeID_Static(), IsNewFormat(), MigrateDataSection(), and NeedsMigration().

Referenced by Olympe::NodeGraphManager::LoadGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MigrateDataSection()

void Olympe::SubgraphMigrator::MigrateDataSection ( nlohmann::json blueprint) const
private

Definition at line 84 of file SubgraphMigrator.cpp.

References GetComponentTypeID_Static().

Referenced by Migrate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NeedsMigration()

bool Olympe::SubgraphMigrator::NeedsMigration ( const nlohmann::json blueprint) const

Returns true when the blueprint uses the legacy format (data.nodes exists at the top level of the data object).

Both BehaviorTree and HFSM variants are detected.

Definition at line 24 of file SubgraphMigrator.cpp.

References GetComponentTypeID_Static().

Referenced by Migrate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ValidateSubgraphReferences()

bool Olympe::SubgraphMigrator::ValidateSubgraphReferences ( const nlohmann::json blueprint,
std::string &  outError 
)
static

Validates that every subgraphUUID referenced by SubGraph nodes actually exists in data.subgraphs and that there are no circular dependencies (A -> B -> A).

Parameters
blueprintFull blueprint JSON in new format.
outErrorFilled with a human-readable message when false is returned.
Returns
true if the blueprint is self-consistent; false otherwise.

Definition at line 150 of file SubgraphMigrator.cpp.

References CollectSubgraphRefs(), GetComponentTypeID_Static(), and HasCycle().

Referenced by Olympe::BehaviorTreeEditorPlugin::Validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: