Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
DynamicDataPin.h
Go to the documentation of this file.
1/**
2 * @file DynamicDataPin.h
3 * @brief Defines DynamicDataPin — a runtime data-input pin attached to a node.
4 * @author Olympe Engine
5 * @date 2026-03-16
6 *
7 * @details
8 * When a ConditionPreset uses a Pin-mode operand, the owning NodeBranch needs
9 * a physical input pin rendered in the graph editor. A DynamicDataPin tracks
10 * all metadata required to:
11 * - Render the pin in the node UI.
12 * - Map incoming float data to the correct operand side of the correct
13 * condition during runtime evaluation.
14 * - Persist to JSON alongside the node so that connections survive save/load.
15 *
16 * Each DynamicDataPin has a globally unique UUID so that graph links can
17 * reference it by ID without ambiguity.
18 *
19 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
20 */
21
22#pragma once
23
24#include <string>
25#include "../../third_party/nlohmann/json.hpp"
26
27namespace Olympe {
28
29/**
30 * @enum OperandPosition
31 * @brief Identifies which operand side a DynamicDataPin serves.
32 */
33enum class OperandPosition {
34 Left, ///< Pin provides data for the left operand of the condition
35 Right ///< Pin provides data for the right operand of the condition
36};
37
38/**
39 * @struct DynamicDataPin
40 * @brief A data-input pin created dynamically for a Pin-mode operand.
41 *
42 * @details
43 * Created automatically by the Dynamic Pin Manager (Phase 24.3) when a
44 * ConditionPreset containing a Pin-mode operand is assigned to a NodeBranch.
45 * The `nodePinID` field is populated at render time (ImNodes pin ID).
46 */
48 std::string id; ///< Global unique UUID (e.g. "pin_inst_abc123")
49 int conditionIndex; ///< Index in node.conditions (0-based)
50 OperandPosition position; ///< Left or Right operand side
51 std::string label; ///< Display label (set at construction)
52 std::string nodePinID; ///< ImGui/ImNodes pin ID (assigned at render time)
53 float dataValue; ///< Runtime float value received from connected node
54 int sequenceNumber; ///< 1-based sequence index across all pins on the node (for "Pin-in #N" label)
55
56 // -----------------------------------------------------------------------
57 // Constructors
58 // -----------------------------------------------------------------------
59
60 /// Default constructor — zero-initialised.
62
63 /// @brief Convenience constructor.
64 /// @param condIdx Index of the owning condition in node.conditions.
65 /// @param pos Which operand side (Left or Right).
66 /// @param condPreview Short preview of the parent condition for the label
67 /// (e.g. "[mSpeed] == [Pin:1]").
68 DynamicDataPin(int condIdx, OperandPosition pos, const std::string& condPreview);
69
70 // -----------------------------------------------------------------------
71 // Helpers
72 // -----------------------------------------------------------------------
73
74 /// @brief Returns the full display label shown on the node.
75 /// Format: "In #<condIdx+1><L|R>: <condPreview>"
76 /// Example: "In #3L: [mSpeed] == [Pin:1]"
77 std::string GetDisplayLabel() const;
78
79 /// @brief Returns the short label for use as a pin connector slot.
80 /// Format: "Pin-in #<sequenceNumber>"
81 /// Example: "Pin-in #1"
82 std::string GetShortLabel() const;
83
84 /// @brief Generates a globally unique identifier string (UUID v4-style).
85 static std::string GenerateUniqueID();
86
87 // -----------------------------------------------------------------------
88 // Serialization
89 // -----------------------------------------------------------------------
90
91 /// @brief Serializes this pin to a JSON object.
92 nlohmann::json ToJson() const;
93
94 /// @brief Deserializes a DynamicDataPin from a JSON object.
95 static DynamicDataPin FromJson(const nlohmann::json& data);
96};
97
98} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
< Provides AssetID and INVALID_ASSET_ID
OperandPosition
Identifies which operand side a DynamicDataPin serves.
@ Right
Pin provides data for the right operand of the condition.
@ Left
Pin provides data for the left operand of the condition.
nlohmann::json json
A data-input pin created dynamically for a Pin-mode operand.
static DynamicDataPin FromJson(const nlohmann::json &data)
Deserializes a DynamicDataPin from a JSON object.
int sequenceNumber
1-based sequence index across all pins on the node (for "Pin-in #N" label)
int conditionIndex
Index in node.conditions (0-based)
nlohmann::json ToJson() const
Serializes this pin to a JSON object.
OperandPosition position
Left or Right operand side.
std::string GetDisplayLabel() const
Returns the full display label shown on the node.
static std::string GenerateUniqueID()
Generates a globally unique identifier string (UUID v4-style).
float dataValue
Runtime float value received from connected node.
std::string GetShortLabel() const
Returns the short label for use as a pin connector slot.
std::string id
Global unique UUID (e.g. "pin_inst_abc123")
std::string nodePinID
ImGui/ImNodes pin ID (assigned at render time)
std::string label
Display label (set at construction)
DynamicDataPin()
Default constructor — zero-initialised.