Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ConditionRegistry.cpp
Go to the documentation of this file.
1/**
2 * @file ConditionRegistry.cpp
3 * @brief Implementation of ConditionRegistry with built-in conditions.
4 * @author Olympe Engine
5 * @date 2026-03-14
6 *
7 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
8 */
9
10#include "ConditionRegistry.h"
11
12#include <algorithm>
13
14namespace Olympe {
15
16// ---------------------------------------------------------------------------
17// Singleton
18// ---------------------------------------------------------------------------
19
25
30
31// ---------------------------------------------------------------------------
32// Registration
33// ---------------------------------------------------------------------------
34
36{
37 if (!spec.id.empty())
38 m_specs[spec.id] = spec;
39}
40
41// ---------------------------------------------------------------------------
42// Queries
43// ---------------------------------------------------------------------------
44
45const ConditionSpec* ConditionRegistry::GetConditionSpec(const std::string& id) const
46{
47 auto it = m_specs.find(id);
48 return (it != m_specs.end()) ? &it->second : nullptr;
49}
50
51std::vector<std::string> ConditionRegistry::GetAllConditionIds() const
52{
53 std::vector<std::string> ids;
54 ids.reserve(m_specs.size());
55 for (const auto& kv : m_specs)
56 ids.push_back(kv.first);
57 std::sort(ids.begin(), ids.end());
58 return ids;
59}
60
61std::vector<ConditionSpec> ConditionRegistry::GetAllConditions() const
62{
63 std::vector<ConditionSpec> result;
64 result.reserve(m_specs.size());
65 for (const auto& kv : m_specs)
66 result.push_back(kv.second);
67 std::sort(result.begin(), result.end(),
68 [](const ConditionSpec& a, const ConditionSpec& b) {
69 return a.id < b.id;
70 });
71 return result;
72}
73
74// ---------------------------------------------------------------------------
75// Built-in condition specs
76// ---------------------------------------------------------------------------
77
79{
80 // ---- CompareValue ----
81 {
83 spec.id = "CompareValue";
84 spec.displayName = "Compare Value";
85 spec.description = "Compare a blackboard variable against a literal value.";
86 spec.parameters.push_back({"Key", ParameterBindingType::LocalVariable,
87 "Blackboard key to read", true});
88 spec.parameters.push_back({"Operator", ParameterBindingType::ComparisonOp,
89 "Comparison operator (==, !=, <, <=, >, >=)", true});
90 spec.parameters.push_back({"Value", ParameterBindingType::Literal,
91 "Literal value to compare against", true});
93 }
94
95 // ---- IsSet ----
96 {
98 spec.id = "IsSet";
99 spec.displayName = "Is Set";
100 spec.description = "True if the blackboard key has been assigned a value.";
101 spec.parameters.push_back({"Key", ParameterBindingType::LocalVariable,
102 "Blackboard key to check", true});
103 Register(spec);
104 }
105
106 // ---- IsNotSet ----
107 {
109 spec.id = "IsNotSet";
110 spec.displayName = "Is Not Set";
111 spec.description = "True if the blackboard key has not been assigned a value.";
112 spec.parameters.push_back({"Key", ParameterBindingType::LocalVariable,
113 "Blackboard key to check", true});
114 Register(spec);
115 }
116
117 // ---- InRange ----
118 {
120 spec.id = "InRange";
121 spec.displayName = "In Range";
122 spec.description = "True if a blackboard value is within [Min, Max].";
123 spec.parameters.push_back({"Key", ParameterBindingType::LocalVariable,
124 "Blackboard key to read", true});
125 spec.parameters.push_back({"Min", ParameterBindingType::Literal,
126 "Minimum value (inclusive)", true});
127 spec.parameters.push_back({"Max", ParameterBindingType::Literal,
128 "Maximum value (inclusive)", true});
129 Register(spec);
130 }
131
132 // ---- RandomChance ----
133 {
135 spec.id = "RandomChance";
136 spec.displayName = "Random Chance";
137 spec.description = "True with a given probability [0.0 .. 1.0].";
138 spec.parameters.push_back({"Probability", ParameterBindingType::Literal,
139 "Probability of returning true (0.0 to 1.0)", true});
140 Register(spec);
141 }
142}
143
144} // namespace Olympe
Registry of available condition types for Branch/While node dropdowns.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton registry of available condition types.
void Register(const ConditionSpec &spec)
Registers a ConditionSpec.
static ConditionRegistry & Get()
Returns the singleton instance.
std::vector< ConditionSpec > GetAllConditions() const
Returns all registered condition specs, sorted by id.
std::vector< std::string > GetAllConditionIds() const
Returns all registered condition IDs.
const ConditionSpec * GetConditionSpec(const std::string &id) const
Returns the ConditionSpec for the given id, or nullptr if not found.
std::unordered_map< std::string, ConditionSpec > m_specs
< Provides AssetID and INVALID_ASSET_ID
@ LocalVariable
Value is read from the local blackboard at runtime.
@ Literal
Value is embedded directly in the template.
@ ComparisonOp
Comparison operator (==, !=, <, <=, >, >=) (from OperatorRegistry)
Full metadata for a single condition type.
std::string id
Condition type ID (e.g. "CompareValue")