Skip to content

Commit 4db4b3e

Browse files
committed
remove invalid runs
1 parent 7648893 commit 4db4b3e

12 files changed

Lines changed: 274 additions & 154 deletions

src/main.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,51 @@ using namespace geode::prelude;
1212

1313
auto graphs = std::vector<DTGraphInfo>{
1414
DTGraphInfo{
15-
.isEnabled = true,
15+
.isEnabled = false,
1616
.coverage = static_cast<DTGraphCoverage>(3),
1717
.type = static_cast<DTGraphType>(0),
1818
.orderPos = 0,
1919
.thickness = 1.0f,
2020
.outlineThickness = 0.75f,
21-
.pointScale = 0.10000000149011612f,
21+
#if defined(GEODE_IS_MOBILE)
22+
.pointScale = 0.175,
23+
#else
24+
.pointScale = 0.1,
25+
#endif
2226
.color = {122, 74, 0, 255},
2327
.outlineColor = {101, 50, 0, 255},
2428
.pointColor = {164, 76, 0, 255},
2529
.name = "session runs"
2630
},
2731
DTGraphInfo{
28-
.isEnabled = true,
32+
.isEnabled = false,
2933
.coverage = static_cast<DTGraphCoverage>(2),
3034
.type = static_cast<DTGraphType>(0),
3135
.orderPos = 1,
3236
.thickness = 1.0f,
3337
.outlineThickness = 0.75f,
34-
.pointScale = 0.10000000149011612f,
38+
#if defined(GEODE_IS_MOBILE)
39+
.pointScale = 0.175,
40+
#else
41+
.pointScale = 0.1,
42+
#endif
3543
.color = {255, 145, 0, 255},
3644
.outlineColor = {170, 104, 16, 255},
3745
.pointColor = {114, 66, 3, 255},
3846
.name = "sess from0"
3947
},
4048
DTGraphInfo{
41-
.isEnabled = true,
49+
.isEnabled = false,
4250
.coverage = static_cast<DTGraphCoverage>(1),
4351
.type = static_cast<DTGraphType>(0),
4452
.orderPos = 2,
4553
.thickness = 0.75f,
4654
.outlineThickness = 0.5f,
47-
.pointScale = 0.07999999821186066f,
55+
#if defined(GEODE_IS_MOBILE)
56+
.pointScale = 0.175,
57+
#else
58+
.pointScale = 0.1,
59+
#endif
4860
.color = {14, 138, 37, 253},
4961
.outlineColor = {11, 96, 32, 255},
5062
.pointColor = {5, 181, 48, 255},
@@ -57,7 +69,11 @@ using namespace geode::prelude;
5769
.orderPos = 3,
5870
.thickness = 1.0f,
5971
.outlineThickness = 0.75f,
60-
.pointScale = 0.10000000149011612f,
72+
#if defined(GEODE_IS_MOBILE)
73+
.pointScale = 0.175,
74+
#else
75+
.pointScale = 0.1,
76+
#endif
6177
.color = {0, 255, 55, 255},
6278
.outlineColor = {18, 162, 53, 255},
6379
.pointColor = {15, 105, 41, 255},

src/managers/StatsManager.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ Result<> StatsManager::setGeneral(const GeneralData& stats, const std::string& l
314314
}
315315

316316
Result<> StatsManager::addBackup(const std::string& levelKey, bool saveLevelStats, std::optional<int> sessionsToSave){
317-
log::info("adding backup for level {} | {} | {}", levelKey, saveLevelStats, sessionsToSave);
317+
//log::info("adding backup for level {} | {} | {}", levelKey, saveLevelStats, sessionsToSave);
318318
auto metaRes = getMetadata(levelKey);
319319
if (metaRes.isErr()) return Err("No level to back up! {}", metaRes.unwrapErr());
320320
auto metadata = metaRes.unwrap();
@@ -536,7 +536,7 @@ void StatsManager::logDeaths(const std::vector<int>& percents) {
536536
}
537537

538538
void StatsManager::logRun(const Run& run, bool instantSave) {
539-
if (currentLevel == nullptr) {
539+
if (currentLevel == nullptr || !run.start.has_value()) {
540540
log::error("Failed to log deaths");
541541
return;
542542
}
@@ -549,15 +549,15 @@ void StatsManager::logRun(const Run& run, bool instantSave) {
549549
}
550550

551551
auto runKey = fmt::format("{}-{}",
552-
run.start,
552+
run.start.value(),
553553
run.end
554554
);
555555

556556
auto session = StatsManager::getCurrentSession();
557557
if (session != nullptr){
558558
session->data.runs[runKey]++;
559559

560-
log::info("logging run {}-{} to session {}", run.start, run.end, session->sessionStartDate);
560+
log::info("logging run {}-{} to session {}", run.start.value(), run.end, session->sessionStartDate);
561561
}
562562

563563
if (currentFrom0.has_value()){
@@ -637,19 +637,26 @@ Result<std::string> StatsManager::getLevelKey(GJGameLevel* const& level) {
637637
}
638638

639639
Result<Run> StatsManager::splitRunKey(const std::string& runKey) {
640+
bool firstNegative = false;
641+
if (runKey.size() && runKey[0] == '-')
642+
firstNegative = true;
643+
640644
auto runKeySplit = StatsManager::splitStr(runKey, "-");
641645

642646
if (runKeySplit.size() == 0 || runKeySplit.size() > 2)
643647
return Err("Invalid run key!");
644648

645-
int start = -1;
649+
std::optional<int> start = std::nullopt;
646650
int end = -1;
647651

648652
if (runKeySplit.size() == 1){
649653
GEODE_UNWRAP_INTO(end, geode::utils::numFromString<int>(runKeySplit[0]));
654+
if (firstNegative)
655+
end *= -1;
650656
}
651657
else{
652-
GEODE_UNWRAP_INTO(start, geode::utils::numFromString<int>(runKeySplit[0]));
658+
GEODE_UNWRAP_INTO(int startRes, geode::utils::numFromString<int>(runKeySplit[0]));
659+
start = startRes * (firstNegative ? -1 : 1);
653660
GEODE_UNWRAP_INTO(end, geode::utils::numFromString<int>(runKeySplit[1]));
654661
}
655662

@@ -661,7 +668,7 @@ Result<Run> StatsManager::splitRunKey(const std::string& runKey) {
661668
}
662669

663670
Result<std::string> StatsManager::createRunKey(const Run& runKey){
664-
if (runKey.start == -1){
671+
if (runKey.start == std::nullopt){
665672
return Ok(std::to_string(runKey.end));
666673
}
667674
else if (runKey.start >= 0){

src/nodes/DTGraphNode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ void DTGraphNode::updateGraphContent(){
100100
auto runStartRes = StatsManager::splitRunKey(death.first);
101101
if (runStartRes.isErr()) continue;
102102
auto start = runStartRes.unwrap().start;
103-
if (start != -1) {
103+
if (start != std::nullopt) {
104104
if (!hasRunStart || start < RunStartPercent) {
105-
RunStartPercent = start;
105+
RunStartPercent = start.value();
106106
hasRunStart = true;
107107
}
108108
}
@@ -124,8 +124,8 @@ void DTGraphNode::updateGraphContent(){
124124
auto runRes = StatsManager::splitRunKey(death.first);
125125
if (runRes.isErr()) continue;
126126

127-
if (runRes.unwrap().start != -1){
128-
if (runRes.unwrap().start == runPercent)
127+
if (runRes.unwrap().start != std::nullopt){
128+
if (runRes.unwrap().start.value() == runPercent)
129129
sortedDeaths[runRes.unwrap()] += death.second;
130130
}
131131
else

src/nodes/GraphPointDisplay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ bool GraphPointDisplay::init(){
3838
}
3939

4040
void GraphPointDisplay::setContent(std::string run, float ratePercent, DTGraphType type, ccColor3B graphInner, ccColor3B graphOuter){
41-
auto runInfo = StatsManager::splitRunKey(run).unwrapOr(Run{-1, -1});
41+
auto runInfo = StatsManager::splitRunKey(run).unwrapOr(Run{std::nullopt, -1});
4242

4343
std::string runSprFormatted;
44-
if (runInfo.start == -1 && runInfo.end == -1)
44+
if (runInfo.start == std::nullopt && runInfo.end == -1)
4545
runSprFormatted = "Error";
46-
else if (runInfo.start == -1)
46+
else if (runInfo.start == std::nullopt)
4747
runSprFormatted = fmt::format("{}%", runInfo.end);
4848
else
4949
runSprFormatted = fmt::format("{}%-{}%", runInfo.start, runInfo.end);

src/nodes/layers/DTLayer.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,28 +1225,29 @@ bool DTLayer::createDeathsString(const Deaths& deaths, const LevelMetadeta& meta
12251225

12261226
auto& runSplit = runSplitRes.unwrap();
12271227

1228-
bool includeRunStart = runSplit.start != -1;
1228+
bool includeRunStart = runSplit.start != std::nullopt;
12291229

12301230
std::string nbDeColor = "";
12311231
std::string nbColor = "";
12321232

12331233
if (includeRunStart && !ignoreExtraSettings){
12341234
if (!meta.showAnyRun && meta.runsToShow.size()){
1235-
if (meta.runsToShow.contains(runSplit.start)){
1236-
if (meta.runsToShow.at(runSplit.start) > runSplit.end)
1235+
if (meta.runsToShow.contains(runSplit.start.value())){
1236+
if (meta.runsToShow.at(runSplit.start.value()) > runSplit.end)
12371237
continue;
12381238
}
12391239
else{
12401240
continue;
12411241
}
12421242
}
12431243
else{
1244-
if (meta.sharedRunToShow > runSplit.end - runSplit.start)
1244+
if (meta.sharedRunToShow > runSplit.end - runSplit.start.value())
12451245
continue;
12461246
}
12471247
}
12481248
else if (!includeRunStart && !ignoreExtraSettings){
1249-
if (meta.hideUpto > runSplit.end)
1249+
log::info("a {}", runSplit.end);
1250+
if (meta.hideUpto > runSplit.end && runSplit.end >= 0)
12501251
continue;
12511252

12521253
if (newBests.has_value() && newBests.value().contains(runSplit.end)){
@@ -1255,16 +1256,16 @@ bool DTLayer::createDeathsString(const Deaths& deaths, const LevelMetadeta& meta
12551256
}
12561257
}
12571258

1258-
if (prevStart != runSplit.start){
1259+
if (prevStart != runSplit.start.value_or(-1)){
12591260
if (prevStart != -2){
12601261
out += "----------{nl}";
12611262
}
1262-
prevStart = runSplit.start;
1263+
prevStart = runSplit.start.value_or(-1);
12631264
}
12641265

12651266
auto format = custom.format;
12661267

1267-
std::string toReplaceWith = includeRunStart ? fmt::format("{}-{}", runSplit.start, runSplit.end) : fmt::format("{}", runSplit.end);
1268+
std::string toReplaceWith = includeRunStart ? fmt::format("{}-{}", runSplit.start.value(), runSplit.end) : fmt::format("{}", runSplit.end);
12681269
format = std::regex_replace(
12691270
format,
12701271
std::regex("\\{per\\}"),
@@ -2265,7 +2266,7 @@ void DTLayer::modifyRun(int startPer, int amount, std::optional<int> sessionNumb
22652266
}
22662267

22672268
auto newNum = data[runStr] + amount;
2268-
log::info("{} | {} | {}", amount, data[runStr], newNum);
2269+
//log::info("{} | {} | {}", amount, data[runStr], newNum);
22692270

22702271
if (newNum <= 0){
22712272
data.erase(runStr);
@@ -2678,10 +2679,10 @@ long long DTLayer::calcPlaytime(const Deaths& deaths){
26782679
if (runSplitRes.isErr()) continue;
26792680

26802681
float runLength;
2681-
if (runSplitRes.unwrap().start == -1)
2682+
if (runSplitRes.unwrap().start == std::nullopt)
26822683
runLength = runSplitRes.unwrap().end;
26832684
else
2684-
runLength = (runSplitRes.unwrap().end - runSplitRes.unwrap().start);
2685+
runLength = (runSplitRes.unwrap().end - runSplitRes.unwrap().start.value());
26852686
// log::info("{} | {} | {}", runLength, runSplitRes.unwrap().end, runSplitRes.unwrap().start);
26862687
// log::info("{}", death.second);
26872688

@@ -2866,10 +2867,12 @@ UpdateFuture DTLayer::onBestRunsKey(){
28662867
if (splitRunRes.isErr()) continue;
28672868
auto splitRun = splitRunRes.unwrap();
28682869

2869-
if (!bestRuns.contains(splitRun.start))
2870-
bestRuns.insert({splitRun.start, splitRun.end});
2871-
else if (bestRuns[splitRun.start] < splitRun.end){
2872-
bestRuns[splitRun.start] = splitRun.end;
2870+
auto realStart = splitRun.start.value_or(-1);
2871+
2872+
if (!bestRuns.contains(realStart))
2873+
bestRuns.insert({realStart, splitRun.end});
2874+
else if (bestRuns[realStart] < splitRun.end){
2875+
bestRuns[realStart] = splitRun.end;
28732876
}
28742877
}
28752878

@@ -2941,10 +2944,12 @@ UpdateFuture DTLayer::onSessionBestRunsKey(){
29412944
if (splitRunRes.isErr()) continue;
29422945
auto splitRun = splitRunRes.unwrap();
29432946

2944-
if (!bestRuns.contains(splitRun.start))
2945-
bestRuns.insert({splitRun.start, splitRun.end});
2946-
else if (bestRuns[splitRun.start] < splitRun.end){
2947-
bestRuns[splitRun.start] = splitRun.end;
2947+
auto realStart = splitRun.start.value_or(-1);
2948+
2949+
if (!bestRuns.contains(realStart))
2950+
bestRuns.insert({realStart, splitRun.end});
2951+
else if (bestRuns[realStart] < splitRun.end){
2952+
bestRuns[realStart] = splitRun.end;
29482953
}
29492954
}
29502955

@@ -3145,7 +3150,7 @@ UpdateFuture DTLayer::onSectionKey(){
31453150
if (splitDeathRes.isErr()) continue;
31463151
auto splitDeath = splitDeathRes.unwrap();
31473152

3148-
if (splitDeath.start == -1){
3153+
if (splitDeath.start == std::nullopt){
31493154
CreateSectioIDForSectionPair(splitDeath, std::nullopt, death.second);
31503155
continue;
31513156
}
@@ -3154,7 +3159,7 @@ UpdateFuture DTLayer::onSectionKey(){
31543159

31553160
for (const auto& section : validSections)
31563161
{
3157-
if (!section.isPercentInSection(splitDeath.start)) continue;
3162+
if (!section.isPercentInSection(splitDeath.start.value_or(-1))) continue;
31583163

31593164
startingSectionsForDeath.push_back(section);
31603165
}
@@ -3224,8 +3229,9 @@ UpdateFuture DTLayer::onLevelRunsKey() {
32243229
auto res = StatsManager::splitRunKey(key);
32253230
if (res.isOk()) {
32263231
Run run = res.unwrap();
3227-
if (run.start <= -1) run.start = 0;
3228-
if (count > 0 && run.end > run.start) {
3232+
auto runStartReal = run.start.value_or(-1);
3233+
if (runStartReal <= -1) runStartReal = 0;
3234+
if (count > 0 && run.end > runStartReal) {
32293235
validRuns.push_back(run);
32303236
}
32313237
}

src/nodes/layers/DTLayer.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class DTLayer : public Popup, public FLAlertLayerProtocol {
120120
void CleanGetStats();
121121

122122
template<class T>
123-
GetTFuture<T> getTFor(geode::Function<T(GeneralData const&)> dataGetter, geode::Function<T(T const&, T const&)> combineFunc, bool session){
123+
GetTFuture<T> getTFor(geode::Function<T(GeneralData const&)> dataGetter, geode::Function<T(T const&, T const&)> combineFunc, bool session, bool localOnly = false){
124124
if (!session){
125125
if (m_MyLevelStats.isErr()) co_return Err("Failed to calculate playtime");
126126
auto myStats = m_MyLevelStats.unwrap();
@@ -136,12 +136,14 @@ class DTLayer : public Popup, public FLAlertLayerProtocol {
136136

137137
T all = dataGetter(myFrom0Stats);
138138

139-
for (const auto& levelData : linkedLevelsCopy)
140-
{
141-
co_await arc::yield();
142-
if (levelData.from0.isErr() || levelData.levelKey == myStats.levelKey) continue;
143-
auto levelFrom0Stats = levelData.from0.unwrap();
144-
all = combineFunc(all, dataGetter(levelFrom0Stats));
139+
if (!localOnly){
140+
for (const auto& levelData : linkedLevelsCopy)
141+
{
142+
co_await arc::yield();
143+
if (levelData.from0.isErr() || levelData.levelKey == myStats.levelKey) continue;
144+
auto levelFrom0Stats = levelData.from0.unwrap();
145+
all = combineFunc(all, dataGetter(levelFrom0Stats));
146+
}
145147
}
146148

147149
co_return Ok(all);

0 commit comments

Comments
 (0)