6#include "Etterna/Singletons/ThemeManager.h"
15 virtual void Read() = 0;
16 virtual void Clear() = 0;
62 mutable T m_currentValue;
63 bool m_bCallEachTime{
false };
70 ThemeMetric(std::string sGroup =
"", std::string sName =
"")
75 ThemeManager::Subscribe(
this);
86 m_bCallEachTime =
false;
87 ThemeManager::Subscribe(
this);
90 ~ThemeMetric()
override { ThemeManager::Unsubscribe(
this); }
95 void Load(
const std::string& sGroup,
const std::string& sName)
102 void ChangeGroup(
const std::string& sGroup)
111 if (!
m_sName.empty() && (THEME !=
nullptr) && THEME->IsThemeLoaded()) {
115 LuaHelpers::FromStack(L, m_currentValue, -1);
121 m_Value.GetLuaType() == LUA_TFUNCTION;
124 m_bCallEachTime =
false;
128 void PushSelf(Lua* L)
134 void Clear()
override {
m_Value.Unset(); }
153 if (m_bCallEachTime) {
159 LuaHelpers::RunScriptOnStack(L, error, 0, 1,
true);
160 if (!lua_isnil(L, -1)) {
161 LuaHelpers::Pop(L, m_currentValue);
168 return m_currentValue;
171 operator const T&()
const {
return GetValue(); }
173 auto IsLoaded() const ->
bool {
return m_Value.
IsSet(); }
182 auto operator==(
const T& input)
const ->
bool
188using MetricName1D = std::string (*)(size_t);
194 std::vector<ThemeMetricT> m_metric;
197 ThemeMetric1D(
const std::string& sGroup, MetricName1D pfn,
size_t N)
199 Load(sGroup, pfn, N);
202 void Load(
const std::string& sGroup, MetricName1D pfn,
size_t N)
205 for (
unsigned i = 0; i < N; i++) {
206 m_metric[i].Load(sGroup, pfn(i));
211 for (
unsigned i = 0; i < m_metric.size(); i++) {
215 void Clear()
override
217 for (
unsigned i = 0; i < m_metric.size(); i++) {
222 [[nodiscard]]
auto GetValue(
size_t i)
const ->
const T&
224 return m_metric[i].GetValue();
228using MetricName2D = std::string (*)(size_t, size_t);
234 using ThemeMetricTVector = std::vector<ThemeMetricT>;
235 std::vector<ThemeMetricTVector> m_metric;
239 MetricName2D pfn =
nullptr,
243 Load(sGroup, pfn, N, M);
245 void Load(
const std::string& sGroup, MetricName2D pfn,
size_t N,
size_t M)
248 for (
unsigned i = 0; i < N; i++) {
249 m_metric[i].resize(M);
250 for (
unsigned j = 0; j < M; j++)
251 m_metric[i][j].Load(sGroup, pfn(i, j));
256 for (
unsigned i = 0; i < m_metric.size(); i++)
257 for (
unsigned j = 0; j < m_metric[i].size(); j++)
258 m_metric[i][j].Read();
260 void Clear()
override
262 for (
unsigned i = 0; i < m_metric.size(); i++)
263 for (
unsigned j = 0; j < m_metric[i].size(); j++)
264 m_metric[i][j].Clear();
266 auto GetValue(
size_t i,
size_t j)
const ->
const T&
268 return m_metric[i][j].GetValue();
272using MetricNameMap = std::string (*)(std::string);
278 std::map<std::string, ThemeMetricT> m_metric;
282 const std::string& sGroup =
"",
283 MetricNameMap pfn =
nullptr,
284 const std::vector<std::string>& vsValueNames = std::vector<std::string>())
286 Load(sGroup, pfn, vsValueNames);
288 void Load(
const std::string& sGroup,
290 const std::vector<std::string>& vsValueNames)
293 for (
auto& s : vsValueNames) {
294 m_metric[s].Load(sGroup, pfn(s));
308 void Clear()
override
317 [[nodiscard]]
auto GetValue(
const std::string& s)
const ->
const T&
321 typename std::map<std::string, ThemeMetric<T>>::const_iterator iter =
323 ASSERT(iter != m_metric.end());
324 return iter->second.GetValue();
The general interface for reading ThemeMetrics.
Definition ThemeMetric.h:12
A self-cleaning Lua reference.
Definition LuaReference.h:10
auto IsSet() const -> bool
Determine if the reference is set.
Definition LuaReference.cpp:97
Definition ThemeMetric.h:192
Definition ThemeMetric.h:232
Definition ThemeMetric.h:276
The theme specific data.
Definition ThemeMetric.h:52
auto GetName() const -> const std::string &
Retrieve the metric's name.
Definition ThemeMetric.h:139
LuaReference m_Value
the metric's value.
Definition ThemeMetric.h:61
auto GetGroup() const -> const std::string &
Retrieve the metric's group.
Definition ThemeMetric.h:143
void Read() override
Actually read the metric and get its data.
Definition ThemeMetric.h:109
std::string m_sName
the metric's name.
Definition ThemeMetric.h:59
std::string m_sGroup
the metric's group.
Definition ThemeMetric.h:57
auto GetValue() const -> const T &
Retrieve the metric's value.
Definition ThemeMetric.h:148
void Load(const std::string &sGroup, const std::string &sName)
Load the chosen metric from the .ini file.
Definition ThemeMetric.h:95
Definition ThemeMetric.h:21