From cbef4e69e9f5b5cf31871107e92c88f8b10e35c2 Mon Sep 17 00:00:00 2001 From: Caeden117 Date: Mon, 14 Mar 2022 17:59:39 -0700 Subject: [PATCH] Cut counter toggles for arcs/chains --- .../ConfigModels/Counters/CutConfigModel.cs | 8 ++ Counters+/Counters/CutCounter.cs | 120 ++++++++++++------ Counters+/UI/BSML/Config/Cut.bsml | 4 +- Counters+/manifest.json | 2 +- 4 files changed, 90 insertions(+), 44 deletions(-) diff --git a/Counters+/ConfigModels/Counters/CutConfigModel.cs b/Counters+/ConfigModels/Counters/CutConfigModel.cs index a4c55bb..1d5b096 100644 --- a/Counters+/ConfigModels/Counters/CutConfigModel.cs +++ b/Counters+/ConfigModels/Counters/CutConfigModel.cs @@ -15,9 +15,17 @@ internal class CutConfigModel : ConfigModel [UIValue(nameof(SeparateSaberCounts))] public virtual bool SeparateSaberCounts { get; set; } = false; + [UIValue(nameof(SeparateCutValues))] public virtual bool SeparateCutValues { get; set; } = false; + [UIValue(nameof(AveragePrecision))] public virtual int AveragePrecision { get; set; } = 1; + + [UIValue(nameof(IncludeArcs))] + public virtual bool IncludeArcs { get; set; } = false; + + [UIValue(nameof(IncludeChains))] + public virtual bool IncludeChains { get; set; } = false; } } diff --git a/Counters+/Counters/CutCounter.cs b/Counters+/Counters/CutCounter.cs index 94adae7..b505891 100644 --- a/Counters+/Counters/CutCounter.cs +++ b/Counters+/Counters/CutCounter.cs @@ -2,6 +2,7 @@ using CountersPlus.Counters.Interfaces; using System.Collections.Generic; using System.Globalization; +using System.Linq; using TMPro; using UnityEngine; using Zenject; @@ -14,13 +15,12 @@ internal class CutCounter : Counter private TMP_Text cutCounterLeft; private TMP_Text cutCounterRight; - private int totalCutCountLeft = 0; - private int totalCutCountRight = 0; - private int[] totalScoresLeft = new int[] { 0, 0, 0 }; // [0]=beforeCut, [1]=afterCut, [2]=cutDistance - private int[] totalScoresRight = new int[] { 0, 0, 0 }; - // For handling cut calculations - private Dictionary noteCutInfos = new Dictionary(); + // [0] = pre-swing, [1] = post-swing, [2] = accuracy + private int[] cutCountLeft = new int[] { 0, 0, 0 }; + private int[] cutCountRight = new int[] { 0, 0, 0 }; + private int[] totalScoresLeft = new int[] { 0, 0, 0 }; + private int[] totalScoresRight = new int[] { 0, 0, 0 }; public override void CounterInit() { @@ -58,27 +58,61 @@ public override void CounterDestroy() private void ScoreController_scoringForNoteFinishedEvent(ScoringElement scoringElement) { - if (scoringElement is GoodCutScoringElement goodCut && goodCut.noteData.scoringType == NoteData.ScoringType.Normal) + if (scoringElement is GoodCutScoringElement goodCut) { var cutScoreBuffer = goodCut.cutScoreBuffer; var beforeCut = cutScoreBuffer.beforeCutScore; var afterCut = cutScoreBuffer.afterCutScore; var cutDistance = cutScoreBuffer.centerDistanceCutScore; + var fixedScore = cutScoreBuffer.noteScoreDefinition.fixedCutScore; - if (goodCut.noteData.colorType == ColorType.ColorA) - { - totalScoresLeft[0] += beforeCut; - totalScoresLeft[1] += afterCut; - totalScoresLeft[2] += cutDistance; - ++totalCutCountLeft; - } - else + var totalScoresForHand = goodCut.noteData.colorType == ColorType.ColorA + ? totalScoresLeft + : totalScoresRight; + + var cutCountForHand = goodCut.noteData.colorType == ColorType.ColorA + ? cutCountLeft + : cutCountRight; + + switch (goodCut.noteData.scoringType) { - totalScoresRight[0] += beforeCut; - totalScoresRight[1] += afterCut; - totalScoresRight[2] += cutDistance; - ++totalCutCountRight; + case NoteData.ScoringType.Normal: + totalScoresForHand[0] += beforeCut; + totalScoresForHand[1] += afterCut; + totalScoresForHand[2] += cutDistance; + + cutCountForHand[0]++; + cutCountForHand[1]++; + cutCountForHand[2]++; + break; + case NoteData.ScoringType.SliderHead when Settings.IncludeArcs: + totalScoresForHand[0] += beforeCut; + totalScoresForHand[2] += cutDistance; + + cutCountForHand[0]++; + cutCountForHand[2]++; + break; + case NoteData.ScoringType.SliderTail when Settings.IncludeArcs: + totalScoresForHand[1] += afterCut; + totalScoresForHand[2] += cutDistance; + + cutCountForHand[1]++; + cutCountForHand[2]++; + break; + case NoteData.ScoringType.BurstSliderHead when Settings.IncludeChains: + totalScoresForHand[0] += beforeCut; + totalScoresForHand[2] += cutDistance; + + cutCountForHand[0]++; + cutCountForHand[2]++; + break; + + // Chain links are not being tracked at all because they give a fixed 20 score for every hit. + /*case NoteData.ScoringType.BurstSliderElement when Settings.IncludeChains: + totalScoresForHand[2] += fixedScore; + cutCountForHand[2]++; + break;*/ } UpdateLabels(); @@ -93,44 +127,48 @@ private void UpdateLabels() { string[] leftAverages = new string[3] { - FormatLabel(totalScoresLeft[0], totalCutCountLeft, shownDecimals), - FormatLabel(totalScoresLeft[1], totalCutCountLeft, shownDecimals), - FormatLabel(totalScoresLeft[2], totalCutCountLeft, shownDecimals) + FormatLabel(totalScoresLeft[0], cutCountLeft[0], shownDecimals), + FormatLabel(totalScoresLeft[1], cutCountLeft[1], shownDecimals), + FormatLabel(totalScoresLeft[2], cutCountLeft[2], shownDecimals) }; string[] rightAverages = new string[3] { - FormatLabel(totalScoresRight[0], totalCutCountRight, shownDecimals), - FormatLabel(totalScoresRight[1], totalCutCountRight, shownDecimals), - FormatLabel(totalScoresRight[2], totalCutCountRight, shownDecimals) + FormatLabel(totalScoresRight[0], cutCountRight[0], shownDecimals), + FormatLabel(totalScoresRight[1], cutCountRight[1], shownDecimals), + FormatLabel(totalScoresRight[2], cutCountRight[2], shownDecimals) }; cutCounterLeft.text = $"{leftAverages[0]}\n{leftAverages[1]}\n{leftAverages[2]}"; cutCounterRight.text = $"{rightAverages[0]}\n{rightAverages[1]}\n{rightAverages[2]}"; } else if (Settings.SeparateCutValues) // Before/After/Distance, for combined sabers - { - int totalCutCount = totalCutCountLeft + totalCutCountRight; + {; string[] cutValueAverages = new string[3] { - FormatLabel(totalScoresLeft[0] + totalScoresRight[0], totalCutCount, shownDecimals), - FormatLabel(totalScoresLeft[1] + totalScoresRight[1], totalCutCount, shownDecimals), - FormatLabel(totalScoresLeft[2] + totalScoresRight[2], totalCutCount, shownDecimals) + FormatLabel(totalScoresLeft[0] + totalScoresRight[0], cutCountLeft[0] + cutCountRight[0], shownDecimals), + FormatLabel(totalScoresLeft[1] + totalScoresRight[1], cutCountLeft[1] + cutCountRight[1], shownDecimals), + FormatLabel(totalScoresLeft[2] + totalScoresRight[2], cutCountLeft[2] + cutCountRight[2], shownDecimals) }; cutCounterLeft.text = $"{cutValueAverages[0]}\n{cutValueAverages[1]}\n{cutValueAverages[2]}"; } else if (Settings.SeparateSaberCounts) // Combined cut, for separate sabers { - string[] saberAverages = new string[2] - { - FormatLabel(totalScoresLeft[0] + totalScoresLeft[1] + totalScoresLeft[2], totalCutCountLeft, shownDecimals), - FormatLabel(totalScoresRight[0] + totalScoresRight[1] + totalScoresRight[2], totalCutCountRight, shownDecimals) - }; - cutCounterLeft.text = $"{saberAverages[0]}"; - cutCounterRight.text = $"{saberAverages[1]}"; + var totalScoreLeft = SafeDivideScore(totalScoresLeft[0], cutCountLeft[0]) + + SafeDivideScore(totalScoresLeft[1], cutCountLeft[1]) + + SafeDivideScore(totalScoresLeft[2], cutCountLeft[2]); + + var totalScoreRight = SafeDivideScore(totalScoresRight[0], cutCountRight[0]) + + SafeDivideScore(totalScoresRight[1], cutCountRight[1]) + + SafeDivideScore(totalScoresRight[2], cutCountRight[2]); + + cutCounterLeft.text = totalScoreLeft.ToString($"F{shownDecimals}", CultureInfo.InvariantCulture); + cutCounterRight.text = totalScoreRight.ToString($"F{shownDecimals}", CultureInfo.InvariantCulture); } else // Combined cut, for combined sabers { - string averages = FormatLabel(totalScoresLeft[0] + totalScoresLeft[1] + totalScoresLeft[2] + totalScoresRight[0] + totalScoresRight[1] + totalScoresRight[2], totalCutCountLeft + totalCutCountRight, shownDecimals); - cutCounterLeft.text = $"{averages}"; + var aggregateScores = totalScoresLeft.Sum() + totalScoresRight.Sum(); + var aggregateCuts = cutCountLeft.Sum() + cutCountRight.Sum(); + + cutCounterLeft.text = FormatLabel(aggregateScores, aggregateCuts, shownDecimals); } } @@ -141,8 +179,6 @@ private double SafeDivideScore(int total, int count) } private string FormatLabel(int totalScore, int totalCuts, int decimals) - { - return SafeDivideScore(totalScore, totalCuts).ToString($"F{decimals}", CultureInfo.InvariantCulture); - } + => SafeDivideScore(totalScore, totalCuts).ToString($"F{decimals}", CultureInfo.InvariantCulture); } } diff --git a/Counters+/UI/BSML/Config/Cut.bsml b/Counters+/UI/BSML/Config/Cut.bsml index 1b090da..0e825bd 100644 --- a/Counters+/UI/BSML/Config/Cut.bsml +++ b/Counters+/UI/BSML/Config/Cut.bsml @@ -1,5 +1,7 @@  - + + + \ No newline at end of file diff --git a/Counters+/manifest.json b/Counters+/manifest.json index 0211041..2cbc938 100644 --- a/Counters+/manifest.json +++ b/Counters+/manifest.json @@ -6,7 +6,7 @@ "version": "2.2.7", "description": "A suite of enhancements for Beat Saber's UI.", "icon": "CountersPlus.UI.Images.Logo.png", - "gameVersion": "1.19.0", + "gameVersion": "1.20.0", "dependsOn": { "BSIPA": "^4.2.1", "BeatSaberMarkupLanguage": "^1.6.0",