Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodeConditionRef.cpp
Go to the documentation of this file.
1/**
2 * @file NodeConditionRef.cpp
3 * @brief Implementation of NodeConditionRef — construction, helpers, serialization.
4 * @author Olympe Engine
5 * @date 2026-03-16
6 *
7 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
8 */
9
10#include "NodeConditionRef.h"
11
12#include <string>
13
14namespace Olympe {
15
16// ---------------------------------------------------------------------------
17// Constructors
18// ---------------------------------------------------------------------------
19
21 : presetID("")
22 , logicalOp(LogicalOp::Start)
23 , leftPinID("")
24 , rightPinID("")
25{
26}
27
29 : presetID(pid)
30 , logicalOp(op)
31 , leftPinID("")
32 , rightPinID("")
33{
34}
35
36// ---------------------------------------------------------------------------
37// Helpers
38// ---------------------------------------------------------------------------
39
41{
42 switch (logicalOp)
43 {
44 case LogicalOp::Start: return "Start";
45 case LogicalOp::And: return "And";
46 case LogicalOp::Or: return "Or";
47 }
48 return "Start";
49}
50
52{
53 return !leftPinID.empty();
54}
55
57{
58 return !rightPinID.empty();
59}
60
61// ---------------------------------------------------------------------------
62// Serialization
63// ---------------------------------------------------------------------------
64
66{
67 nlohmann::json j = nlohmann::json::object();
68 j["presetID"] = presetID;
69 j["logicalOp"] = GetLogicalOpString();
70 j["leftPinID"] = leftPinID;
71 j["rightPinID"] = rightPinID;
72 return j;
73}
74
75/*static*/
77{
79
80 if (!data.is_object())
81 return ref;
82
83 if (data.contains("presetID") && data["presetID"].is_string())
84 ref.presetID = data["presetID"].get<std::string>();
85
86 if (data.contains("logicalOp") && data["logicalOp"].is_string())
87 {
88 std::string op = data["logicalOp"].get<std::string>();
89 if (op == "And") ref.logicalOp = LogicalOp::And;
90 else if (op == "Or") ref.logicalOp = LogicalOp::Or;
91 else ref.logicalOp = LogicalOp::Start;
92 }
93
94 if (data.contains("leftPinID") && data["leftPinID"].is_string())
95 ref.leftPinID = data["leftPinID"].get<std::string>();
96
97 if (data.contains("rightPinID") && data["rightPinID"].is_string())
98 ref.rightPinID = data["rightPinID"].get<std::string>();
99
100 return ref;
101}
102
103} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Defines NodeConditionRef — a node's reference to a global ConditionPreset.
< Provides AssetID and INVALID_ASSET_ID
LogicalOp
How this condition is combined with the one preceding it.
@ Or
Combined with OR.
@ Start
First condition in the list (no logical combinator)
@ And
Combined with AND.
nlohmann::json json
One entry in a NodeBranch's conditions list.
std::string rightPinID
DynamicDataPin UUID for right Pin operand (or empty)
nlohmann::json ToJson() const
Serializes this ref to a JSON object.
std::string GetLogicalOpString() const
Returns the logical-op as a display string ("Start", "And", "Or").
bool HasLeftPin() const
Returns true when a left-side DynamicDataPin is assigned.
bool HasRightPin() const
Returns true when a right-side DynamicDataPin is assigned.
static NodeConditionRef FromJson(const nlohmann::json &data)
Deserializes a NodeConditionRef from a JSON object.
std::string presetID
UUID of the referenced ConditionPreset.
std::string leftPinID
DynamicDataPin UUID for left Pin operand (or empty)
NodeConditionRef()
Default constructor — empty preset ID, LogicalOp::Start.
LogicalOp logicalOp
Combinator with previous condition (ignored for first)