Skip to content

Commit

Permalink
allow defaulting NOTESKIN->GetMetric
Browse files Browse the repository at this point in the history
this is definitely a thing somewhere and i didnt look hard enough
  • Loading branch information
poco0317 committed Dec 13, 2022
1 parent c3e0ccf commit b7fa469
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Etterna/Singletons/NoteSkinManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,62 @@ NoteSkinManager::GetMetric(const std::string& sButtonName,
return sReturn;
}

std::string
NoteSkinManager::GetMetric(const std::string& sButtonName,
const std::string& sValue, const std::string& sFallbackValue)
{
if (m_sCurrentNoteSkin.empty()) {
LuaHelpers::ReportScriptError(
"NOTESKIN:GetMetric: No noteskin currently set.", "NOTESKIN_ERROR");
return "";
}
auto sNoteSkinName = make_lower(m_sCurrentNoteSkin);
map<std::string, NoteSkinData>::const_iterator it =
g_mapNameToData.find(sNoteSkinName);
ASSERT_M(it != g_mapNameToData.end(),
sNoteSkinName); // this NoteSkin doesn't exist!
const auto& data = it->second;

std::string sReturn;
if (data.metrics.GetValue(sButtonName, sValue, sReturn))
return sReturn;
if (!data.metrics.GetValue("NoteDisplay", sValue, sReturn)) {
// dont report an error
return sFallbackValue;
}
return sReturn;
}

int
NoteSkinManager::GetMetricI(const std::string& sButtonName,
const std::string& sValueName)
{
return StringToInt(GetMetric(sButtonName, sValueName));
}

int
NoteSkinManager::GetMetricI(const std::string& sButtonName,
const std::string& sValueName,
const std::string& sDefaultValue)
{
return StringToInt(GetMetric(sButtonName, sValueName, sDefaultValue));
}

float
NoteSkinManager::GetMetricF(const std::string& sButtonName,
const std::string& sValueName)
{
return StringToFloat(GetMetric(sButtonName, sValueName));
}

float
NoteSkinManager::GetMetricF(const std::string& sButtonName,
const std::string& sValueName,
const std::string& sDefaultValue)
{
return StringToFloat(GetMetric(sButtonName, sValueName, sDefaultValue));
}

bool
NoteSkinManager::GetMetricB(const std::string& sButtonName,
const std::string& sValueName)
Expand All @@ -371,6 +413,15 @@ NoteSkinManager::GetMetricB(const std::string& sButtonName,
return StringToInt(GetMetric(sButtonName, sValueName)) != 0;
}

bool
NoteSkinManager::GetMetricB(const std::string& sButtonName,
const std::string& sValueName,
const std::string& sDefaultValue)
{
// Could also call GetMetricI here...hmm.
return StringToInt(GetMetric(sButtonName, sValueName, sDefaultValue)) != 0;
}

apActorCommands
NoteSkinManager::GetMetricA(const std::string& sButtonName,
const std::string& sValueName)
Expand Down
12 changes: 12 additions & 0 deletions src/Etterna/Singletons/NoteSkinManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ class NoteSkinManager

auto GetMetric(const std::string& sButtonName, const std::string& sValue)
-> std::string;
auto GetMetric(const std::string& sButtonName,
const std::string& sValue,
const std::string& sFallbackValue) -> std::string;
auto GetMetricI(const std::string& sButtonName,
const std::string& sValueName) -> int;
auto GetMetricI(const std::string& sButtonName,
const std::string& sValueName,
const std::string& sDefaultValue) -> int;
auto GetMetricF(const std::string& sButtonName,
const std::string& sValueName) -> float;
auto GetMetricF(const std::string& sButtonName,
const std::string& sValueName,
const std::string& sDefaultValue) -> float;
auto GetMetricB(const std::string& sButtonName,
const std::string& sValueName) -> bool;
auto GetMetricB(const std::string& sButtonName,
const std::string& sValueName,
const std::string& sDefaultValue) -> bool;
auto GetMetricA(const std::string& sButtonName,
const std::string& sValueName) -> apActorCommands;

Expand Down

0 comments on commit b7fa469

Please sign in to comment.