6#include "../../Source/third_party/imgui/imgui.h"
26 auto now = std::chrono::system_clock::now();
27 auto time = std::chrono::system_clock::to_time_t(
now);
34 ss << std::put_time(&
timeinfo,
"%Y-%m-%dT%H:%M:%S");
36 ss << std::put_time(std::localtime(&
time),
"%Y-%m-%dT%H:%M:%S");
45 prefab[
"schema_version"] = 2;
46 prefab[
"blueprintType"] =
"EntityPrefab";
48 prefab[
"description"] =
"";
49 prefab[
"metadata"][
"author"] =
"Atlasbruce";
52 prefab[
"metadata"][
"tags"] = json::array();
55 prefab[
"data"][
"prefabName"] = name;
56 prefab[
"data"][
"components"] = json::array();
61 identity[
"properties"][
"name"] = name +
"_{id}";
62 identity[
"properties"][
"tag"] = name;
63 identity[
"properties"][
"entityType"] =
"Generic";
66 position[
"type"] =
"Position_data";
73 position[
"properties"][
"position"] =
posObj;
76 prefab[
"data"][
"components"].push_back(position);
84 if (
blueprint.contains(
"blueprintType") &&
85 blueprint[
"blueprintType"] ==
"EntityPrefab")
96 std::vector<ValidationError> errors;
103 err.message =
"Missing 'data' section";
105 errors.push_back(
err);
111 if (!data.contains(
"components"))
116 err.message =
"Missing 'components' array";
118 errors.push_back(
err);
126 if (!blueprintData.contains(
"data"))
128 ImGui::Text(
"Invalid blueprint: missing 'data' section");
132 auto& data = blueprintData[
"data"];
134 if (!data.contains(
"components"))
136 data[
"components"] = json::array();
139 auto& components = data[
"components"];
141 ImGui::Text(
"Components: %d", (
int)components.size());
146 for (
size_t i = 0;
i < components.size(); ++
i)
148 auto&
comp = components[
i];
151 ImGui::PushID((
int)
i);
156 ImGui::SameLine(ImGui::GetWindowWidth() - 80);
157 if (ImGui::SmallButton(
"Remove"))
165 if (
comp.contains(
"properties"))
185 if (ImGui::Button(
"Add Component",
ImVec2(-1, 0)))
187 ImGui::OpenPopup(
"AddComponentPopup");
190 if (ImGui::BeginPopup(
"AddComponentPopup"))
195 if (ImGui::MenuItem(type.c_str()))
207 ImGui::Text(
"Type: Entity Prefab");
209 if (blueprintData.contains(
"data") && blueprintData[
"data"].contains(
"components"))
211 ImGui::Text(
"Components: %d", (
int)blueprintData[
"data"][
"components"].size());
215 ImGui::Text(
"Components: 0");
221 if (ImGui::Button(
"Add Component"))
223 ImGui::OpenPopup(
"AddComponentToolbar");
230 for (
auto it = properties.begin();
it != properties.end(); ++
it)
232 const std::string&
key =
it.key();
235 ImGui::PushID(
key.c_str());
237 if (value.is_number_float())
239 float f = value.get<
float>();
240 if (ImGui::DragFloat(
key.c_str(), &
f, 1.0f))
246 else if (value.is_number_integer())
248 int i = value.get<
int>();
249 if (ImGui::InputInt(
key.c_str(), &
i))
255 else if (value.is_string())
257 std::string
str = value.get<std::string>();
265 if (ImGui::InputText(
key.c_str(),
buffer, 256))
271 else if (value.is_object())
274 if (ImGui::TreeNode(
key.c_str()))
289 newComp[
"properties"] = json::object();
291 blueprintData[
"data"][
"components"].push_back(
newComp);
297 "Identity_data",
"Position_data",
"VisualSprite_data",
298 "BoundingBox_data",
"Movement_data",
"PhysicsBody_data",
299 "Health_data",
"PlayerBinding_data",
"Controller_data",
300 "AIBlackboard_data",
"AISenses_data",
"AIState_data",
301 "BehaviorTreeRuntime_data",
"MoveIntent_data",
"AttackIntent_data"
ComponentTypeID GetComponentTypeID_Static()
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
nlohmann::json CreateNew(const std::string &name) override
virtual ~EntityPrefabEditorPlugin()
bool CanHandle(const nlohmann::json &blueprint) const override
void RenderProperties(const nlohmann::json &blueprintData) override
void AddComponentToBlueprint(nlohmann::json &blueprintData, const std::string &type)
EntityPrefabEditorPlugin()
std::vector< std::string > GetAvailableComponentTypes()
void RenderToolbar(nlohmann::json &blueprintData) override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
std::string GetCurrentTimestamp()
void RenderComponentPropertiesEditor(nlohmann::json &properties, EditorContext_st &ctx)