Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BBVariableRegistry.h
Go to the documentation of this file.
1/**
2 * @file BBVariableRegistry.h
3 * @brief Wrapper around the graph blackboard entries for dropdown editors.
4 * @author Olympe Engine
5 * @date 2026-03-14
6 *
7 * @details
8 * BBVariableRegistry wraps the Blackboard vector from a TaskGraphTemplate
9 * and exposes filtered, formatted views suitable for populating dropdown
10 * menus in the properties panel (GetBBValue, SetBBValue, Switch, etc.).
11 *
12 * Call LoadFromTemplate() each time the active template changes.
13 *
14 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
15 */
16
17#pragma once
18
19#include <string>
20#include <vector>
21
22#include "../TaskSystem/TaskGraphTypes.h"
23#include "../TaskSystem/TaskGraphTemplate.h"
24
25namespace Olympe {
26
27/**
28 * @struct VarSpec
29 * @brief Metadata for a single blackboard variable entry.
30 */
31struct VarSpec {
32 std::string name; ///< Variable key (e.g. "health", "target")
33 VariableType type; ///< Declared type
34 bool isGlobal; ///< true = global scope, false = local scope
35 std::string displayLabel; ///< Formatted label, e.g. "health (Float, local)"
36};
37
38/**
39 * @class BBVariableRegistry
40 * @brief Non-singleton registry populated from the active TaskGraphTemplate.
41 *
42 * @details
43 * Intentionally non-singleton because the variable set depends on which
44 * graph is currently open in the editor. Create one instance per editor
45 * panel and call LoadFromTemplate() whenever the template changes.
46 */
48public:
49
50 BBVariableRegistry() = default;
51
52 /**
53 * @brief Rebuilds the registry from the blackboard entries of a template.
54 * @param tmpl Source template whose Blackboard vector is read.
55 */
57
58 /**
59 * @brief Returns all variables (local and global), sorted by name.
60 */
61 const std::vector<VarSpec>& GetAllVariables() const;
62
63 /**
64 * @brief Returns variables whose type matches @p type, sorted by name.
65 * @param type VariableType filter.
66 */
67 std::vector<VarSpec> GetVariablesByType(VariableType type) const;
68
69 /**
70 * @brief Returns only local-scope variables.
71 */
72 std::vector<VarSpec> GetLocalVariables() const;
73
74 /**
75 * @brief Returns only global-scope variables.
76 */
77 std::vector<VarSpec> GetGlobalVariables() const;
78
79 /**
80 * @brief Formats a display label for a variable.
81 *
82 * Format: "<name> (<TypeName>, <scope>)"
83 * Example: "health (Float, local)"
84 *
85 * @param name Variable key.
86 * @param type Variable type.
87 * @param isGlobal Scope flag.
88 * @return Formatted display label.
89 */
90 static std::string FormatDisplayLabel(const std::string& name,
91 VariableType type,
92 bool isGlobal);
93
94 /**
95 * @brief Returns true if a variable with the given name is registered.
96 * @param name Variable key to look up.
97 */
98 bool HasVariable(const std::string& name) const;
99
100 /**
101 * @brief Returns the number of registered variables.
102 */
103 size_t GetCount() const;
104
105private:
106
107 std::vector<VarSpec> m_vars;
108};
109
110} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Non-singleton registry populated from the active TaskGraphTemplate.
std::vector< VarSpec > GetVariablesByType(VariableType type) const
Returns variables whose type matches type, sorted by name.
std::vector< VarSpec > m_vars
std::vector< VarSpec > GetGlobalVariables() const
Returns only global-scope variables.
void LoadFromTemplate(const TaskGraphTemplate &tmpl)
Rebuilds the registry from the blackboard entries of a template.
static std::string FormatDisplayLabel(const std::string &name, VariableType type, bool isGlobal)
Formats a display label for a variable.
const std::vector< VarSpec > & GetAllVariables() const
Returns all variables (local and global), sorted by name.
size_t GetCount() const
Returns the number of registered variables.
bool HasVariable(const std::string &name) const
Returns true if a variable with the given name is registered.
std::vector< VarSpec > GetLocalVariables() const
Returns only local-scope variables.
Immutable, shareable task graph asset.
< Provides AssetID and INVALID_ASSET_ID
VariableType
Type tags used by TaskValue to identify stored data.
Metadata for a single blackboard variable entry.
VariableType type
Declared type.
std::string name
Variable key (e.g. "health", "target")
std::string displayLabel
Formatted label, e.g. "health (Float, local)".
bool isGlobal
true = global scope, false = local scope