Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ConditionPreset.h
Go to the documentation of this file.
1/**
2 * @file ConditionPreset.h
3 * @brief Defines ConditionPreset — a reusable, globally-stored condition expression.
4 * @author Olympe Engine
5 * @date 2026-03-16
6 *
7 * @details
8 * A ConditionPreset represents a single boolean comparison of the form:
9 * <left Operand> <ComparisonOp> <right Operand>
10 *
11 * Presets are stored in the global ConditionPresetRegistry and referenced by
12 * NodeBranch nodes via NodeConditionRef. This separation allows the same
13 * condition to be reused across multiple nodes and edited in one place.
14 *
15 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
16 */
17
18#pragma once
19
20#include <string>
21#include <utility>
22#include "Operand.h"
23#include "../../third_party/nlohmann/json.hpp"
24
25namespace Olympe {
26
27/**
28 * @enum ComparisonOp
29 * @brief The relational operator used in a ConditionPreset.
30 */
31enum class ComparisonOp {
32 Equal, ///< ==
33 NotEqual, ///< !=
34 Less, ///< <
35 LessEqual, ///< <=
36 Greater, ///< >
37 GreaterEqual ///< >=
38};
39
40/**
41 * @struct ConditionPreset
42 * @brief A globally-stored, reusable condition expression.
43 *
44 * @details
45 * Identified by a UUID string. Holds a left Operand, a ComparisonOp, and a
46 * right Operand. Serialized to / loaded from
47 * `./Blueprints/Presets/condition_presets.json`.
48 */
50 std::string id; ///< Global unique UUID (e.g. "preset_001")
51 std::string name; ///< Human-readable display name (e.g. "Condition #1")
55
56 // -----------------------------------------------------------------------
57 // Constructors
58 // -----------------------------------------------------------------------
59
60 /// Default constructor — generates an empty preset.
62
63 /// @brief Full constructor.
64 /// @param id UUID string (caller must supply a unique value).
65 /// @param l Left operand.
66 /// @param o Comparison operator.
67 /// @param r Right operand.
68 ConditionPreset(const std::string& id,
69 const Operand& l,
71 const Operand& r);
72
73 // -----------------------------------------------------------------------
74 // Helpers
75 // -----------------------------------------------------------------------
76
77 /// @brief Returns a human-readable preview string.
78 /// Example: "[mHealth] <= [2]"
79 std::string GetPreview() const;
80
81 /// @brief Returns true when the left operand is in Pin mode.
82 bool NeedsLeftPin() const;
83
84 /// @brief Returns true when the right operand is in Pin mode.
85 bool NeedsRightPin() const;
86
87 /// @brief Returns a pair {needsLeft, needsRight}.
88 std::pair<bool, bool> GetPinNeeds() const;
89
90 /// @brief Returns the operator as a display string (e.g. "<=").
91 static std::string OpToString(ComparisonOp o);
92
93 /// @brief Parses a display string back to a ComparisonOp.
94 /// Returns ComparisonOp::Equal on unknown input.
95 static ComparisonOp OpFromString(const std::string& s);
96
97 // -----------------------------------------------------------------------
98 // Serialization
99 // -----------------------------------------------------------------------
100
101 /// @brief Serializes this preset to a JSON object.
102 nlohmann::json ToJson() const;
103
104 /// @brief Deserializes a ConditionPreset from a JSON object.
105 static ConditionPreset FromJson(const nlohmann::json& data);
106};
107
108} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Defines the Operand type used in condition preset expressions.
< Provides AssetID and INVALID_ASSET_ID
ComparisonOp
The relational operator used in a ConditionPreset.
nlohmann::json json
A globally-stored, reusable condition expression.
std::pair< bool, bool > GetPinNeeds() const
Returns a pair {needsLeft, needsRight}.
nlohmann::json ToJson() const
Serializes this preset to a JSON object.
std::string GetPreview() const
Returns a human-readable preview string.
static ConditionPreset FromJson(const nlohmann::json &data)
Deserializes a ConditionPreset from a JSON object.
ConditionPreset()
Default constructor — generates an empty preset.
static std::string OpToString(ComparisonOp o)
Returns the operator as a display string (e.g. "<=").
std::string id
Global unique UUID (e.g. "preset_001")
bool NeedsLeftPin() const
Returns true when the left operand is in Pin mode.
static ComparisonOp OpFromString(const std::string &s)
Parses a display string back to a ComparisonOp.
bool NeedsRightPin() const
Returns true when the right operand is in Pin mode.
std::string name
Human-readable display name (e.g. "Condition #1")
One side of a ConditionPreset comparison expression.
Definition Operand.h:45