Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ConditionRef.h
Go to the documentation of this file.
1/**
2 * @file ConditionRef.h
3 * @brief Defines OperandRef and ConditionRef — standalone operand-to-pin mapping structures.
4 * @author Olympe Engine
5 * @date 2026-03-18
6 *
7 * @details
8 * ConditionRef is a self-contained representation of one condition expression
9 * for a Branch or While node. Unlike NodeConditionRef (which references a
10 * ConditionPreset in the global registry), ConditionRef stores the full
11 * operand data inline — enabling use cases where no registry round-trip is
12 * required (e.g. migration, serialisation helpers, runtime evaluation).
13 *
14 * The `OperandRef::dynamicPinID` field provides the
15 * ConditionRef -> DynamicDataPin mapping required by Phase 24 Milestone 1:
16 * when an operand is in Pin mode the field holds the UUID of the
17 * DynamicDataPin generated by DynamicDataPinManager so the runtime can look
18 * up the live float value.
19 *
20 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
21 */
22
23#pragma once
24
25#include <string>
26#include <vector>
27
28#include "../TaskSystem/TaskGraphTypes.h" // VariableType
29#include "../third_party/nlohmann/json.hpp"
30
31namespace Olympe {
32
33/**
34 * @struct OperandRef
35 * @brief References one operand of a condition (left or right).
36 *
37 * @details
38 * If mode is `Pin`, `dynamicPinID` stores the UUID of the DynamicDataPin
39 * generated on the node by DynamicDataPinManager::RegeneratePinsFromConditions().
40 * If mode is `Variable` or `Const`, no pin is generated and `dynamicPinID`
41 * is left empty.
42 */
44{
45 /** @brief Discriminates the data source of this operand. */
46 enum class Mode
47 {
48 Variable, ///< References a blackboard variable by name
49 Const, ///< Literal constant value
50 Pin ///< External data-input pin on the owning node
51 };
52
53 Mode mode = Mode::Const; ///< Active mode
54
55 // Variable / Const modes
56 std::string variableName; ///< Blackboard key (mode == Variable), e.g. "mHealth"
57 std::string constValue; ///< Literal string (mode == Const), e.g. "100.0"
58
59 // Pin mode only
60 /**
61 * @brief UUID of the DynamicDataPin that supplies this operand's value.
62 *
63 * Populated by DynamicDataPinManager::RegeneratePinsFromConditions() when
64 * the parent ConditionRef is registered with a Pin-mode operand.
65 * Format: "pin_inst_<random>", e.g. "pin_inst_abc123def456".
66 * Empty string means no pin has been assigned yet.
67 */
68 std::string dynamicPinID;
69
70 // -----------------------------------------------------------------------
71 // Serialization
72 // -----------------------------------------------------------------------
73
74 /// @brief Serializes this OperandRef to a JSON object.
75 nlohmann::json ToJson() const;
76
77 /// @brief Deserializes an OperandRef from a JSON object.
78 static OperandRef FromJson(const nlohmann::json& data);
79};
80
81/**
82 * @struct ConditionRef
83 * @brief Stores the complete reference for one condition including
84 * operand-to-DynamicDataPin mapping.
85 *
86 * @details
87 * Conditions whose operands are in Pin mode automatically have
88 * DynamicDataPin objects generated for them by DynamicDataPinManager.
89 * The panel renders this structure with editable fields for each component
90 * (operand values, operator, logical combinator).
91 *
92 * Multiple ConditionRef objects on a single node are evaluated in order,
93 * combined via their implicit logical operators (And/Or).
94 */
96{
97 int conditionIndex = -1; ///< Index in the Branch/While node's conditions[] array
98
99 // Operands
100 OperandRef leftOperand; ///< Left-hand side of the comparison
101 std::string operatorStr = "=="; ///< Comparison operator: "==", "<=", ">=", "!=", "<", ">"
102 OperandRef rightOperand; ///< Right-hand side of the comparison
103
104 // Type hint used for type-checking and pin dataType selection
105 VariableType compareType = VariableType::Float; ///< Expected value type of both operands
106
107 // -----------------------------------------------------------------------
108 // Serialization
109 // -----------------------------------------------------------------------
110
111 /// @brief Serializes this ConditionRef to a JSON object.
112 nlohmann::json ToJson() const;
113
114 /// @brief Deserializes a ConditionRef from a JSON object.
115 static ConditionRef FromJson(const nlohmann::json& data);
116};
117
118} // namespace Olympe
< Provides AssetID and INVALID_ASSET_ID
VariableType
Type tags used by TaskValue to identify stored data.
@ Float
Single-precision float.
nlohmann::json json
Stores the complete reference for one condition including operand-to-DynamicDataPin mapping.
OperandRef rightOperand
Right-hand side of the comparison.
OperandRef leftOperand
Left-hand side of the comparison.
std::string operatorStr
Comparison operator: "==", "<=", ">=", "!=", "<", ">".
VariableType compareType
Expected value type of both operands.
int conditionIndex
Index in the Branch/While node's conditions[] array.
static ConditionRef FromJson(const nlohmann::json &data)
Deserializes a ConditionRef from a JSON object.
nlohmann::json ToJson() const
Serializes this ConditionRef to a JSON object.
References one operand of a condition (left or right).
static OperandRef FromJson(const nlohmann::json &data)
Deserializes an OperandRef from a JSON object.
Mode
Discriminates the data source of this operand.
@ Variable
References a blackboard variable by name.
@ Const
Literal constant value.
@ Pin
External data-input pin on the owning node.
std::string constValue
Literal string (mode == Const), e.g. "100.0".
std::string variableName
Blackboard key (mode == Variable), e.g. "mHealth".
nlohmann::json ToJson() const
Serializes this OperandRef to a JSON object.
Mode mode
Active mode.
std::string dynamicPinID
UUID of the DynamicDataPin that supplies this operand's value.