Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ComponentNodeData.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <map>
5#include <vector>
6#include "./../../vector.h"
7#include "./../../third_party/nlohmann/json.hpp"
8
9namespace Olympe
10{
11 using json = nlohmann::json;
16
17 struct NodePort
18 {
23 // Visual radius for rendering (kept small at 4.0 for clean appearance)
24 float radius = 4.0f;
25 bool isOutput = false;
26
27 NodePort() = default;
32
33 json ToJson() const
34 {
35 json j;
36 j["portId"] = static_cast<int>(portId);
37 j["portIndex"] = static_cast<int>(portIndex);
38 j["position"] = { {"x", position.x}, {"y", position.y}, {"z", position.z} };
39 j["radius"] = radius;
40 j["isOutput"] = isOutput;
41 return j;
42 }
43
44 static NodePort FromJson(const json& data, NodeId nodeId)
45 {
48 port.portId = data.value("portId", InvalidPortId);
49 port.portIndex = data.value("portIndex", 0);
50 port.radius = data.value("radius", 4.0f);
51 port.isOutput = data.value("isOutput", false);
52 if (data.contains("position"))
53 {
54 port.position.x = data["position"].value("x", 0.0f);
55 port.position.y = data["position"].value("y", 0.0f);
56 port.position.z = data["position"].value("z", 0.0f);
57 }
58 return port;
59 }
60 };
61
63 {
71
73 : normalColor(0.2f, 0.3f, 0.5f),
74 selectedColor(0.4f, 0.6f, 0.9f),
75 hoverColor(0.3f, 0.5f, 0.8f),
76 disabledColor(0.3f, 0.3f, 0.3f),
77 textColor(1.0f, 1.0f, 1.0f),
78 borderWidth(2.0f),
79 cornerRadius(4.0f)
80 {
81 }
82 };
83
85 {
87 std::string componentType;
88 std::string componentName;
90 Vector size = Vector(150.0f, 80.0f, 0.0f);
91 bool selected = false;
92 bool hovered = false;
93 bool enabled = true;
94 std::map<std::string, std::string> properties;
96 std::vector<NodePort> ports;
97
99 explicit ComponentNode(const std::string& type);
100
101 bool operator==(const ComponentNode& other) const;
102 bool operator!=(const ComponentNode& other) const;
103
104 std::string ToDisplayString() const;
105
106 json ToJson() const;
107 static ComponentNode FromJson(const json& data);
108
109 void SetProperty(const std::string& key, const std::string& value);
110 std::string GetProperty(const std::string& key) const;
111 bool HasProperty(const std::string& key) const;
112
113 Vector GetCurrentColor() const;
114
115 // Port management
117 const std::vector<NodePort>& GetPorts() const;
118 std::vector<NodePort>& GetPorts();
119 NodePort* FindPort(PortId portId);
120 const NodePort* FindPort(PortId portId) const;
121 };
122}
nlohmann::json json
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
float z
Definition vector.h:25
float y
Definition vector.h:25
float x
Definition vector.h:25
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
@ Vector
3-component vector (Vector from vector.h)
const PortId InvalidPortId
uint32_t NodeId
uint32_t PortId
const NodeId InvalidNodeId
nlohmann::json json
bool HasProperty(const std::string &key) const
std::string GetProperty(const std::string &key) const
std::map< std::string, std::string > properties
std::vector< NodePort > ports
const std::vector< NodePort > & GetPorts() const
bool operator!=(const ComponentNode &other) const
NodePort * FindPort(PortId portId)
static ComponentNode FromJson(const json &data)
void SetProperty(const std::string &key, const std::string &value)
void InitializePorts(uint32_t numInputPorts=1, uint32_t numOutputPorts=1)
bool operator==(const ComponentNode &other) const
ComponentNodeStyle style
std::string ToDisplayString() const
NodePort(NodeId nodeId, uint32_t index, bool isOutput=false)
NodePort()=default
static NodePort FromJson(const json &data, NodeId nodeId)