9#include "../system/system_utils.h"
27 SYSTEM_LOG <<
"[GraphMigrator] Detected legacy BT format, migrating to v2..." << std::endl;
31 else if (version == 1)
34 SYSTEM_LOG <<
"[GraphMigrator] Detected v1 Blueprint format, migrating to v2..." << std::endl;
41 SYSTEM_LOG <<
"[GraphMigrator] Using v2 format (no migration needed)" << std::endl;
54 if (schemaVersion == -1)
60 if (schemaVersion == 2)
66 if (schemaVersion == 1)
72 if (
j.contains(
"blueprint_version"))
78 if (
j.contains(
"graphKind") &&
j.contains(
"data"))
91 v2[
"schemaVersion"] = 2;
92 v2[
"type"] =
"AIGraph";
93 v2[
"graphKind"] =
"BehaviorTree";
96 json metadata = json::object();
100 json tags = json::array();
101 tags.push_back(
"AI");
102 tags.push_back(
"BehaviorTree");
103 metadata[
"tags"] = tags;
105 v2[
"metadata"] = metadata;
108 json editorState = json::object();
111 json scrollOffset = json::object();
112 if (
v1.contains(
"editorState") &&
v1[
"editorState"].is_object())
115 if (
es.contains(
"scrollOffset") &&
es[
"scrollOffset"].is_object())
122 scrollOffset[
"x"] = 0.0f;
123 scrollOffset[
"y"] = 0.0f;
128 scrollOffset[
"x"] = 0.0f;
129 scrollOffset[
"y"] = 0.0f;
131 editorState[
"scrollOffset"] = scrollOffset;
133 json selectedNodes = json::array();
134 editorState[
"selectedNodes"] = selectedNodes;
135 editorState[
"layoutDirection"] =
"TopToBottom";
137 v2[
"editorState"] = editorState;
140 json data = json::object();
145 if (
v1.contains(
"nodes") &&
v1[
"nodes"].is_array())
157 json position = json::object();
158 if (
oldNode.contains(
"position") &&
oldNode[
"position"].is_object())
165 position[
"x"] = 0.0f;
166 position[
"y"] = 0.0f;
168 newNode[
"position"] = position;
171 json children = json::array();
172 if (
oldNode.contains(
"children") &&
oldNode[
"children"].is_array())
180 else if (
oldNode.contains(
"childIds") &&
oldNode[
"childIds"].is_array())
188 newNode[
"children"] = children;
191 json parameters = json::object();
192 if (
oldNode.contains(
"parameters") &&
oldNode[
"parameters"].is_object())
197 parameters[
it.key()] =
it.value();
200 newNode[
"parameters"] = parameters;
204 if (decoratorChild != 0)
206 newNode[
"decoratorChildId"] = decoratorChild;
216 if (
v1.contains(
"links") &&
v1[
"links"].is_array())
226 json fromPin = json::object();
227 if (
oldLink.contains(
"fromPin") &&
oldLink[
"fromPin"].is_object())
234 json toPin = json::object();
259 v2[
"schemaVersion"] = 2;
261 v2[
"graphKind"] =
"Blueprint";
264 if (
v1.contains(
"metadata") &&
v1[
"metadata"].is_object())
266 v2[
"metadata"] =
v1[
"metadata"];
270 json metadata = json::object();
271 metadata[
"author"] =
"Unknown";
272 v2[
"metadata"] = metadata;
276 json editorState = json::object();
277 editorState[
"zoom"] = 1.0f;
279 json scrollOffset = json::object();
280 scrollOffset[
"x"] = 0.0f;
281 scrollOffset[
"y"] = 0.0f;
282 editorState[
"scrollOffset"] = scrollOffset;
284 json selectedNodes = json::array();
285 editorState[
"selectedNodes"] = selectedNodes;
286 editorState[
"layoutDirection"] =
"TopToBottom";
288 v2[
"editorState"] = editorState;
291 if (
v1.contains(
"data") &&
v1[
"data"].is_object())
293 v2[
"data"] =
v1[
"data"];
297 json data = json::object();
298 data[
"rootNodeId"] = 0;
299 data[
"nodes"] = json::array();
300 data[
"links"] = json::array();
ComponentTypeID GetComponentTypeID_Static()
Migration system for JSON versions.
Main document class for a node graph.
static GraphDocument FromJson(const json &j)
Create graph from JSON.
static GraphDocument LoadWithMigration(const json &j)
Load graph with automatic migration.
static int DetectSchemaVersion(const json &j)
Detect schema version.
static json MigrateV1BlueprintToV2(const json &v1)
Migrate v1 Blueprint format to v2.
static json MigrateLegacyBTToV2(const json &v1)
Migrate legacy BT format to v2.
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
Safely get a string value from JSON.
int GetInt(const json &j, const std::string &key, int defaultValue=0)
Safely get an integer value from JSON.
float GetFloat(const json &j, const std::string &key, float defaultValue=0.0f)
Safely get a float value from JSON.
< Provides AssetID and INVALID_ASSET_ID