Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
TaskGraphMigrator_v3_to_v4.h
Go to the documentation of this file.
1/**
2 * @file TaskGraphMigrator_v3_to_v4.h
3 * @brief Migrates task graph JSON from schema v3 (BT-style) to schema v4 (VS-style).
4 * @author Olympe Engine
5 * @date 2026-03-08
6 *
7 * @details
8 * Schema v3 uses a flat node list with `NextOnSuccess` / `NextOnFailure` integer
9 * fields to express control flow (Behavior-Tree-style).
10 *
11 * Schema v4 replaces those fields with explicit `ExecConnections` and
12 * `DataConnections` arrays (Visual-Script-style), adds `graphType`, and
13 * bumps `schema_version` to 4.
14 *
15 * @par Usage
16 * @code
17 * std::vector<std::string> errors;
18 * bool ok = TaskGraphMigrator_v3_to_v4::Migrate("input_v3.json",
19 * "output_v4.json",
20 * errors);
21 * if (!ok) {
22 * for (auto& e : errors) std::cerr << e << "\n";
23 * }
24 * @endcode
25 *
26 * C++14 compliant - no C++17/20 features.
27 */
28
29#pragma once
30
31#include <string>
32#include <vector>
33
34#include "../third_party/nlohmann/json.hpp"
35
37
38namespace Olympe {
39
40/**
41 * @class TaskGraphMigrator_v3_to_v4
42 * @brief Converts task graph JSON from schema v3 to schema v4 (VisualScript).
43 *
44 * @details
45 * Migration rules applied by MigrateJson():
46 * 1. Checks `schema_version == 3`; adds error and returns `{}` if not.
47 * 2. Copies `name`, `description`, `blackboard` / `localBlackboard`.
48 * 3. For each node in `nodes`:
49 * - If `NextOnSuccess != -1`: adds an ExecConnection
50 * `{ NodeID, "Out", NextOnSuccess, "In" }`.
51 * - If `NextOnFailure != -1`: adds an ExecConnection
52 * `{ NodeID, "OutFailure", NextOnFailure, "In" }`.
53 * - Copies node fields (`nodeType`, `nodeID`, `nodeName`, `parameters`).
54 * - Removes `NextOnSuccess` / `NextOnFailure` from the output node object.
55 * 4. Inserts `"graphType": "VisualScript"` and `"schema_version": 4`.
56 * 5. Inserts an empty `"DataConnections": []` array.
57 */
59public:
60
61 /**
62 * @brief Migrates a v3 JSON file to v4 and writes the result to disk.
63 *
64 * @param inputPath Path to the v3 JSON file to read.
65 * @param outputPath Path where the v4 JSON file will be written.
66 * @param outErrors Receives human-readable error descriptions on failure.
67 * @return true if the migration succeeded; false otherwise.
68 */
69 static bool Migrate(const std::string& inputPath,
70 const std::string& outputPath,
71 std::vector<std::string>& outErrors);
72
73 /**
74 * @brief Performs the v3->v4 JSON transformation in memory.
75 *
76 * @param v3data Parsed JSON object representing the v3 graph.
77 * @param outErrors Receives human-readable error descriptions on failure.
78 * @return Transformed v4 JSON object, or `{}` on error.
79 */
80 static json MigrateJson(const json& v3data,
81 std::vector<std::string>& outErrors);
82};
83
84} // namespace Olympe
nlohmann::json json
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Converts task graph JSON from schema v3 to schema v4 (VisualScript).
static json MigrateJson(const json &v3data, std::vector< std::string > &outErrors)
Performs the v3->v4 JSON transformation in memory.
static bool Migrate(const std::string &inputPath, const std::string &outputPath, std::vector< std::string > &outErrors)
Migrates a v3 JSON file to v4 and writes the result to disk.
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
nlohmann::json json