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

Static utility that loads TaskGraphTemplate from schema v4 JSON. More...

#include <TaskGraphLoader.h>

Static Public Member Functions

static TaskGraphTemplateLoadFromFile (const std::string &path, std::vector< std::string > &outErrors)
 Loads a TaskGraphTemplate from a JSON file on disk.
 
static TaskGraphTemplateLoadFromJson (const json &data, std::vector< std::string > &outErrors)
 Loads a TaskGraphTemplate from an already-parsed JSON object.
 
static bool ValidateJson (const json &data, std::vector< std::string > &outErrors)
 Validates a JSON object against the expected task graph schema.
 
static bool FileExists (const std::string &path)
 Returns true if the given file path exists and can be opened.
 
static std::vector< std::string > ScanTaskGraphDirectory (const std::string &dir)
 Recursively scans a directory for .ats task graph files.
 

Private Member Functions

 TaskGraphLoader ()
 

Static Private Member Functions

static TaskGraphTemplateParseSchemaV4 (const json &data, std::vector< std::string > &outErrors)
 Parses a schema v4 flat JSON into a TaskGraphTemplate.
 
static TaskNodeDefinition ParseNodeV4 (const json &nodeJson, const std::string &graphType, std::vector< std::string > &outErrors)
 Parses a single node JSON (v4 flat format) into a TaskNodeDefinition.
 
static void ParseBlackboardV4 (const json &root, TaskGraphTemplate *tmpl, std::vector< std::string > &outErrors)
 Parses the blackboard array (v4) and fills tmpl->Blackboard.
 
static void ParseExecConnectionsV4 (const json &root, TaskGraphTemplate *tmpl)
 Parses execConnections (v4) and fills tmpl->ExecConnections.
 
static void ParseDataConnectionsV4 (const json &root, TaskGraphTemplate *tmpl)
 Parses dataConnections (v4) and fills tmpl->DataConnections.
 
static void ParseParameters (const json &paramsJson, std::unordered_map< std::string, ParameterBinding > &outParams)
 
static TaskValue ParsePrimitiveValue (const json &val)
 
static bool GetChildValue (const json &obj, const std::string &key, json &outVal)
 
static int ResolveRootNodeId (const json &data, const json &dataSection)
 
static TaskNodeType StringToNodeType (const std::string &s, const std::string &graphType, bool &outOk)
 
static VariableType StringToVariableType (const std::string &s)
 
static DataPinDir StringToDataPinDir (const std::string &s)
 
static ExecPinRole StringToExecPinRole (const std::string &s)
 

Detailed Description

Static utility that loads TaskGraphTemplate from schema v4 JSON.

All methods are static; do not instantiate this class. The caller owns the returned TaskGraphTemplate* and is responsible for deletion.

Definition at line 65 of file TaskGraphLoader.h.

Constructor & Destructor Documentation

◆ TaskGraphLoader()

Olympe::TaskGraphLoader::TaskGraphLoader ( )
inlineprivate

Definition at line 209 of file TaskGraphLoader.h.

Member Function Documentation

◆ FileExists()

bool Olympe::TaskGraphLoader::FileExists ( const std::string &  path)
static

Returns true if the given file path exists and can be opened.

C++14 compatible implementation using std::ifstream.

Parameters
pathFile path to check.
Returns
true if the file can be opened for reading.

Definition at line 1324 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static().

+ Here is the call graph for this function:

◆ GetChildValue()

bool Olympe::TaskGraphLoader::GetChildValue ( const json obj,
const std::string &  key,
json outVal 
)
staticprivate

Definition at line 1222 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static().

Referenced by ParseBlackboardV4(), and ParseParameters().

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

◆ LoadFromFile()

TaskGraphTemplate * Olympe::TaskGraphLoader::LoadFromFile ( const std::string &  path,
std::vector< std::string > &  outErrors 
)
static

Loads a TaskGraphTemplate from a JSON file on disk.

Parameters
pathPath to the JSON file (absolute or relative to working dir).
outErrorsReceives human-readable error messages if loading fails.
Returns
Pointer to a newly allocated TaskGraphTemplate on success, or nullptr if the file cannot be read, parsed, or validated.
Note
The caller is responsible for deleting the returned pointer.

Definition at line 44 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), LoadFromJson(), JsonHelper::LoadJsonFromFile(), and SYSTEM_LOG.

Referenced by Olympe::AssetManager::LoadTaskGraph(), Olympe::VisualScriptEditorPanel::RunGraphSimulation(), and Olympe::VisualScriptEditorPanel::RunGraphSimulationRecursive().

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

◆ LoadFromJson()

TaskGraphTemplate * Olympe::TaskGraphLoader::LoadFromJson ( const json data,
std::vector< std::string > &  outErrors 
)
static

Loads a TaskGraphTemplate from an already-parsed JSON object.

Dispatch logic:

  • schema_version == 4: ParseSchemaV4 (flat ATS VS format).
  • schema_version == 3: run TaskGraphMigrator_v3_to_v4::MigrateJson(), then ParseSchemaV4.
  • schema_version <= 2 or absent: ParseSchemaV4 with nested data.nodes support.
Parameters
dataRoot JSON object.
outErrorsReceives human-readable error messages if loading fails.
Returns
Pointer to a newly allocated TaskGraphTemplate on success, or nullptr if parsing or validation fails.

Definition at line 83 of file TaskGraphLoader.cpp.

References Olympe::BTtoVSMigrator::Convert(), GetComponentTypeID_Static(), JsonHelper::GetInt(), Olympe::BTtoVSMigrator::IsBTv2(), Olympe::TaskGraphMigrator_v3_to_v4::MigrateJson(), ParseSchemaV4(), and SYSTEM_LOG.

Referenced by Olympe::VisualScriptRenderer::Load(), and LoadFromFile().

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

◆ ParseBlackboardV4()

void Olympe::TaskGraphLoader::ParseBlackboardV4 ( const json root,
TaskGraphTemplate tmpl,
std::vector< std::string > &  outErrors 
)
staticprivate

Parses the blackboard array (v4) and fills tmpl->Blackboard.

Supports both "value" (new) and "default" (legacy) for the initial value. Supports both "key" (new) and "Key" (legacy PascalCase) field names.

Definition at line 933 of file TaskGraphLoader.cpp.

References Olympe::Float, JsonHelper::GetBool(), GetChildValue(), GetComponentTypeID_Static(), Olympe::GetDefaultValueForType(), JsonHelper::GetString(), Olympe::Int, JsonHelper::IsArray(), JsonHelper::IsObject(), Olympe::BlackboardEntry::Key, Olympe::None, ParsePrimitiveValue(), and StringToVariableType().

Referenced by ParseSchemaV4().

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

◆ ParseDataConnectionsV4()

void Olympe::TaskGraphLoader::ParseDataConnectionsV4 ( const json root,
TaskGraphTemplate tmpl 
)
staticprivate

Parses dataConnections (v4) and fills tmpl->DataConnections.

Accepts "dataConnections" (new camelCase), "DataConnections" (PascalCase), and "data.data_connections" (legacy nested).

Definition at line 1083 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), JsonHelper::GetInt(), JsonHelper::GetString(), JsonHelper::IsArray(), JsonHelper::IsObject(), Olympe::NODE_INDEX_NONE, and Olympe::DataPinConnection::SourceNodeID.

Referenced by ParseSchemaV4().

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

◆ ParseExecConnectionsV4()

void Olympe::TaskGraphLoader::ParseExecConnectionsV4 ( const json root,
TaskGraphTemplate tmpl 
)
staticprivate

Parses execConnections (v4) and fills tmpl->ExecConnections.

Accepts "execConnections" (new camelCase), "ExecConnections" (PascalCase), and "data.exec_connections" (legacy nested).

Definition at line 1028 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), JsonHelper::GetInt(), JsonHelper::GetString(), JsonHelper::IsArray(), JsonHelper::IsObject(), Olympe::NODE_INDEX_NONE, and Olympe::ExecPinConnection::SourceNodeID.

Referenced by ParseSchemaV4().

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

◆ ParseNodeV4()

TaskNodeDefinition Olympe::TaskGraphLoader::ParseNodeV4 ( const json nodeJson,
const std::string &  graphType,
std::vector< std::string > &  outErrors 
)
staticprivate

◆ ParseParameters()

void Olympe::TaskGraphLoader::ParseParameters ( const json paramsJson,
std::unordered_map< std::string, ParameterBinding > &  outParams 
)
staticprivate

◆ ParsePrimitiveValue()

TaskValue Olympe::TaskGraphLoader::ParsePrimitiveValue ( const json val)
staticprivate

Definition at line 1211 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static().

Referenced by ParseBlackboardV4(), ParseNodeV4(), and ParseParameters().

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

◆ ParseSchemaV4()

TaskGraphTemplate * Olympe::TaskGraphLoader::ParseSchemaV4 ( const json data,
std::vector< std::string > &  outErrors 
)
staticprivate

Parses a schema v4 flat JSON into a TaskGraphTemplate.

Supports both the canonical flat format ("nodes", "execConnections", "dataConnections" at root) and the legacy nested format ("data.nodes", "data.exec_connections") for backward compatibility with existing JSON assets.

Definition at line 217 of file TaskGraphLoader.cpp.

References Olympe::EntryPoint, JsonHelper::ForEachInArray(), Olympe::ConditionPreset::FromJson(), JsonHelper::GetBool(), GetComponentTypeID_Static(), JsonHelper::GetInt(), JsonHelper::GetString(), JsonHelper::IsArray(), JsonHelper::IsObject(), Olympe::SubGraphParameterDef::Name, Olympe::NODE_INDEX_NONE, ParseBlackboardV4(), ParseDataConnectionsV4(), ParseExecConnectionsV4(), ParseNodeV4(), ResolveRootNodeId(), StringToVariableType(), and SYSTEM_LOG.

Referenced by LoadFromJson().

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

◆ ResolveRootNodeId()

int Olympe::TaskGraphLoader::ResolveRootNodeId ( const json data,
const json dataSection 
)
staticprivate

Definition at line 1236 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), and JsonHelper::GetInt().

Referenced by ParseSchemaV4().

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

◆ ScanTaskGraphDirectory()

std::vector< std::string > Olympe::TaskGraphLoader::ScanTaskGraphDirectory ( const std::string &  dir)
static

Recursively scans a directory for .ats task graph files.

C++14 compatible — uses POSIX dirent.h on non-Windows, and Win32 API on Windows. Logs a warning if the directory does not exist.

Parameters
dirDirectory to scan (absolute or relative to working dir).
Returns
Sorted list of full paths to every .ats file found.

Definition at line 1334 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), ScanTaskGraphDirectory(), and SYSTEM_LOG.

Referenced by ScanTaskGraphDirectory().

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

◆ StringToDataPinDir()

DataPinDir Olympe::TaskGraphLoader::StringToDataPinDir ( const std::string &  s)
staticprivate

Definition at line 1302 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), Olympe::Input, and Olympe::Output.

+ Here is the call graph for this function:

◆ StringToExecPinRole()

ExecPinRole Olympe::TaskGraphLoader::StringToExecPinRole ( const std::string &  s)
staticprivate

Definition at line 1310 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), Olympe::In, Olympe::Out, Olympe::OutCase, Olympe::OutCompleted, Olympe::OutElse, and Olympe::OutLoop.

+ Here is the call graph for this function:

◆ StringToNodeType()

TaskNodeType Olympe::TaskGraphLoader::StringToNodeType ( const std::string &  s,
const std::string &  graphType,
bool outOk 
)
staticprivate

◆ StringToVariableType()

VariableType Olympe::TaskGraphLoader::StringToVariableType ( const std::string &  s)
staticprivate

Definition at line 1287 of file TaskGraphLoader.cpp.

References Olympe::Bool, Olympe::EntityID, Olympe::Float, GetComponentTypeID_Static(), Olympe::GlobalRef, Olympe::Int, Olympe::List, Olympe::None, Olympe::String, and Olympe::Vector.

Referenced by ParseBlackboardV4(), ParseNodeV4(), and ParseSchemaV4().

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

◆ ValidateJson()

bool Olympe::TaskGraphLoader::ValidateJson ( const json data,
std::vector< std::string > &  outErrors 
)
static

Validates a JSON object against the expected task graph schema.

For v4 flat format: checks for top-level "nodes" array. For v2/v3 nested format: checks for "data.nodes" array.

Parameters
dataRoot JSON object to validate.
outErrorsReceives human-readable messages for each validation issue.
Returns
true if the JSON passes structural checks; false otherwise.

Definition at line 180 of file TaskGraphLoader.cpp.

References GetComponentTypeID_Static(), JsonHelper::GetInt(), JsonHelper::IsArray(), and JsonHelper::IsObject().

+ Here is the call graph for this function:

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