Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BTtoVSMigrator.h
Go to the documentation of this file.
1/**
2 * @file BTtoVSMigrator.h
3 * @brief Converts legacy BT v2 JSON graphs to ATS VS v4 JSON format (Phase 6).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * BTtoVSMigrator translates a "BehaviorTree" schema_version 2 (or lower) JSON
9 * document to the ATS VisualScript schema_version 4 format consumed by
10 * TaskGraphLoader.
11 *
12 * Node type mapping:
13 * BT v2 type -> VS v4 TaskNodeType
14 * ─────────────────────────────────────────
15 * "Selector" -> TaskNodeType::Branch (conditions as children)
16 * "Sequence" -> TaskNodeType::VSSequence
17 * "Action" -> TaskNodeType::AtomicTask
18 * "Condition" -> TaskNodeType::Branch (single condition leaf)
19 * "Decorator" -> TaskNodeType::AtomicTask (inline, stripped)
20 * "Root" / "Start" -> TaskNodeType::EntryPoint
21 *
22 * Connection mapping:
23 * BT parent->child -> ExecPinConnection { parent, "Out", child, "In" }
24 *
25 * Blackboard mapping:
26 * BT blackboard entries are copied verbatim to the VS graph's Blackboard.
27 *
28 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
29 */
30
31#pragma once
32
33#include <string>
34#include <vector>
35
36#include "../TaskSystem/TaskGraphTemplate.h"
37#include "../third_party/nlohmann/json.hpp"
38
39namespace Olympe {
40
41// ============================================================================
42// BTtoVSMigrator
43// ============================================================================
44
45/**
46 * @class BTtoVSMigrator
47 * @brief Converts a BT v2 JSON object to a TaskGraphTemplate (VS v4).
48 *
49 * All methods are static; the class is a pure utility with no instance state.
50 */
52public:
53
54 /**
55 * @brief Converts a BT v2 JSON document to a TaskGraphTemplate.
56 *
57 * @param btV2Json Parsed JSON from a BT v2 asset file.
58 * @param outErrors Receives human-readable error messages on failure.
59 * @return Populated TaskGraphTemplate (may be partial on error).
60 */
62 std::vector<std::string>& outErrors);
63
64 /**
65 * @brief Returns true if @p j looks like a BT v2 document.
66 *
67 * @details
68 * Heuristic: document must contain @c "blueprintType" == "BehaviorTree"
69 * and either no @c schema_version or @c schema_version <= 2.
70 */
71 static bool IsBTv2(const nlohmann::json& j);
72
73 /**
74 * @brief Returns true if @p nodeName indicates a BT Decorator node.
75 *
76 * @details
77 * Some BT v2 files encode Decorator nodes as type "Action" with a
78 * descriptive name (e.g. "Repeater", "Inverter", "Cooldown", "Timeout").
79 * This helper centralises that heuristic so both the migrator and the
80 * loader can use it consistently.
81 */
82 static bool IsDecoratorName(const std::string& nodeName);
83
84private:
85
86 /// Converts one BT node JSON object to a TaskNodeDefinition.
88 std::vector<std::string>& outErrors);
89
90 /**
91 * @brief Builds exec connections from the BT "children" tree structure.
92 *
93 * @details
94 * Walks the node array and for each node that has a "children" array,
95 * emits an ExecPinConnection { nodeID, "Out", childID, "In" }.
96 */
97 static std::vector<ExecPinConnection> ConvertConnections(
99 std::vector<std::string>& outErrors);
100
101 /**
102 * @brief Copies blackboard entries from the BT JSON to the VS template.
103 */
104 static void ConvertBlackboard(const nlohmann::json& btV2Json,
106 std::vector<std::string>& outErrors);
107
108 /// Maps a BT node type string to the closest TaskNodeType equivalent.
109 static TaskNodeType MapNodeType(const std::string& btType);
110};
111
112} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Converts a BT v2 JSON object to a TaskGraphTemplate (VS v4).
static TaskGraphTemplate Convert(const nlohmann::json &btV2Json, std::vector< std::string > &outErrors)
Converts a BT v2 JSON document to a TaskGraphTemplate.
static TaskNodeDefinition ConvertNode(const nlohmann::json &btNode, std::vector< std::string > &outErrors)
Converts one BT node JSON object to a TaskNodeDefinition.
static void ConvertBlackboard(const nlohmann::json &btV2Json, TaskGraphTemplate &vsGraph, std::vector< std::string > &outErrors)
Copies blackboard entries from the BT JSON to the VS template.
static TaskNodeType MapNodeType(const std::string &btType)
Maps a BT node type string to the closest TaskNodeType equivalent.
static bool IsDecoratorName(const std::string &nodeName)
Returns true if nodeName indicates a BT Decorator node.
static bool IsBTv2(const nlohmann::json &j)
Returns true if j looks like a BT v2 document.
static std::vector< ExecPinConnection > ConvertConnections(const nlohmann::json &nodesArray, std::vector< std::string > &outErrors)
Builds exec connections from the BT "children" tree structure.
Immutable, shareable task graph asset.
< Provides AssetID and INVALID_ASSET_ID
TaskNodeType
Identifies the role of a node in the task graph.
nlohmann::json json
Full description of a single node in the task graph.