16#include "../BlueprintEditor/BTNodeGraphManager.h"
17#include "../AI/BTGraphLayoutEngine.h"
18#include "../third_party/nlohmann/json.hpp"
24namespace NodeGraphShared {
45 std::cerr <<
"[BTGraphDocumentConverter] ERROR: null BehaviorTreeAsset\n";
49 if (
tree->nodes.empty())
51 std::cerr <<
"[BTGraphDocumentConverter] WARNING: empty BehaviorTreeAsset '"
62 if (!filepath.empty() && filepath.rfind(
"TreeName:", 0) != 0)
75 std::cout <<
"[BTGraphDocumentConverter] Loaded BT '" <<
tree->name
76 <<
"' from JSON (saved positions preserved)\n";
91 j[
"schema_version"] = 2;
92 j[
"name"] =
tree->name;
93 j[
"blueprintType"] =
"BehaviorTree";
95 json& data =
j[
"data"];
96 data[
"rootNodeId"] =
static_cast<int>(
tree->rootNodeId);
97 data[
"nodes"] = json::array();
102 nj[
"id"] =
static_cast<int>(
btNode.id);
114 posY =
layout->position.y;
116 nj[
"position"][
"x"] = posX;
117 nj[
"position"][
"y"] = posY;
120 nj[
"parameters"] = json::object();
121 for (
const auto&
kv :
btNode.stringParams)
122 nj[
"parameters"][
kv.first] =
kv.second;
125 nj[
"children"] = json::array();
127 nj[
"children"].
push_back(
static_cast<int>(childId));
130 if (
btNode.decoratorChildId != 0)
131 nj[
"decoratorChild"] =
static_cast<int>(
btNode.decoratorChildId);
133 data[
"nodes"].push_back(
nj);
141 std::cout <<
"[BTGraphDocumentConverter] Converted BT '" <<
tree->name
142 <<
"': " <<
tree->nodes.size() <<
" nodes (BFS fallback layout)\n";
Conversion BehaviorTreeAsset -> Olympe::NodeGraph (Blueprint Editor pipeline)
BTNodeType
Behavior tree node types.
@ Action
Leaf node - performs an action.
@ Selector
OR node - succeeds if any child succeeds.
@ Sequence
AND node - succeeds if all children succeed.
@ Inverter
Decorator - inverts child result.
@ Condition
Leaf node - checks a condition.
@ Repeater
Decorator - repeats child N times.
ComponentTypeID GetComponentTypeID_Static()
std::string GetTreePathFromId(uint32_t treeId) const
static BehaviorTreeManager & Get()
Computes clean hierarchical layouts for behavior trees.
std::vector< BTNodeLayout > ComputeLayout(const BehaviorTreeAsset *tree, float nodeSpacingX=320.0f, float nodeSpacingY=180.0f, float zoomFactor=1.0f)
Compute layout for a behavior tree.
bool CloseGraph(int graphId)
int LoadGraph(const std::string &filepath)
NodeGraph * GetGraph(int graphId)
static NodeGraphManager & Get()
static NodeGraph * FromBehaviorTree(const BehaviorTreeAsset *tree)
Converts a BehaviorTreeAsset into a heap-allocated NodeGraph.
static void SyncActiveNode(NodeGraph *graph, uint32_t currentNodeId)
Synchronises the active-node metadata in an existing NodeGraph.
static NodeType MapBTToEditor(BTNodeType t)
< Provides AssetID and INVALID_ASSET_ID
const char * NodeTypeToString(NodeType type)
Layout information for a single behavior tree node.
Vector position
Final position (x, y)