6#include "../../Source/third_party/imgui/imgui.h"
25 auto now = std::chrono::system_clock::now();
26 auto time = std::chrono::system_clock::to_time_t(
now);
33 ss << std::put_time(&
timeinfo,
"%Y-%m-%dT%H:%M:%S");
35 ss << std::put_time(std::localtime(&
time),
"%Y-%m-%dT%H:%M:%S");
44 bt[
"schema_version"] = 2;
45 bt[
"blueprintType"] =
"BehaviorTree";
47 bt[
"description"] =
"";
48 bt[
"metadata"][
"author"] =
"Atlasbruce";
51 bt[
"metadata"][
"tags"] = json::array();
52 bt[
"editorState"][
"zoom"] = 1.0;
53 bt[
"editorState"][
"scrollOffset"] = nlohmann::json::object();
54 bt[
"editorState"][
"scrollOffset"][
"x"] = 0;
55 bt[
"editorState"][
"scrollOffset"][
"y"] = 0;
58 bt[
"data"][
"rootNodeId"] = 1;
67 rootNode[
"children"] = json::array();
68 rootNode[
"parameters"] = json::object();
69 bt[
"data"][
"nodes"] = json::array();
78 if (
blueprint.contains(
"blueprintType") &&
79 blueprint[
"blueprintType"].get<std::string>() ==
"BehaviorTree")
85 return blueprint.contains(
"rootNodeId") &&
92 std::vector<ValidationError> errors;
104 int rootId = data.contains(
"rootNodeId") ? data[
"rootNodeId"].get<
int>() : -1;
113 if (data.contains(
"nodes") && data[
"nodes"].is_array())
115 for (
size_t i = 0;
i < data[
"nodes"].size(); ++
i)
133 if (data.contains(
"nodes") && data[
"nodes"].is_array())
135 for (
size_t i = 0;
i < data[
"nodes"].size(); ++
i)
138 if (
node.contains(
"children") &&
node[
"children"].is_array())
140 for (
size_t j = 0;
j <
node[
"children"].size(); ++
j)
146 for (
size_t k = 0;
k < data[
"nodes"].size(); ++
k)
149 if (
n.is_object() &&
n.contains(
"id") &&
n[
"id"].is_number() &&
n[
"id"].get<
int>() ==
cid)
158 int nodeId =
node.contains(
"id") &&
node[
"id"].is_number() ?
node[
"id"].get<
int>() : -1;
159 std::string
nodeIdStr = std::to_string(nodeId);
162 "Child node " + std::to_string(
cid) +
" not found",
176 if (!blueprintData.contains(
"data"))
178 ImGui::Text(
"Invalid blueprint: missing 'data' section");
187 ImGui::Text(
"Type: Behavior Tree");
189 if (blueprintData.contains(
"data") && blueprintData[
"data"].contains(
"nodes"))
191 ImGui::Text(
"Nodes: %d", (
int)blueprintData[
"data"][
"nodes"].size());
195 ImGui::Text(
"Nodes: 0");
200 if (ImGui::Button(
"Validate Tree",
ImVec2(-1, 0)))
203 ImGui::OpenPopup(
"Validation Results");
209 if (ImGui::Button(
"Add Node"))
211 ImGui::OpenPopup(
"AddNodePopup");
216 if (ImGui::Button(
"Validate"))
226 ImGui::Text(
"Behavior Tree Graph");
227 ImGui::Text(
"Root Node ID: %d", data.value(
"rootNodeId", -1));
229 if (data.contains(
"nodes") && data[
"nodes"].is_array())
232 ImGui::Text(
"Nodes:");
234 for (
size_t i = 0;
i < data[
"nodes"].size(); ++
i)
237 std::string nodeName =
node.is_object() &&
node.contains(
"name") ?
node[
"name"].get<std::string>() :
"Unnamed";
238 std::string
nodeType =
node.is_object() &&
node.contains(
"type") ?
node[
"type"].get<std::string>() :
"Unknown";
239 int nodeId =
node.value(
"id", -1);
241 ImGui::BulletText(
"[%d] %s (%s)", nodeId, nodeName.c_str(),
nodeType.c_str());
ComponentTypeID GetComponentTypeID_Static()
virtual ~BehaviorTreeEditorPlugin()
void RenderToolbar(nlohmann::json &blueprintData) override
void RenderProperties(const nlohmann::json &blueprintData) override
std::string GetCurrentTimestamp()
nlohmann::json CreateNew(const std::string &name) override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
BehaviorTreeEditorPlugin()
bool CanHandle(const nlohmann::json &blueprint) const override
void RenderBehaviorTreeGraph(nlohmann::json &data, EditorContext_st &ctx)