Skip to content

Commit

Permalink
Cut counter toggles for arcs/chains
Browse files Browse the repository at this point in the history
  • Loading branch information
Caeden117 committed Mar 15, 2022
1 parent 220e1fa commit cbef4e6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 44 deletions.
8 changes: 8 additions & 0 deletions Counters+/ConfigModels/Counters/CutConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
120 changes: 78 additions & 42 deletions Counters+/Counters/CutCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CountersPlus.Counters.Interfaces;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using TMPro;
using UnityEngine;
using Zenject;
Expand All @@ -14,13 +15,12 @@ internal class CutCounter : Counter<CutConfigModel>

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<ISaberSwingRatingCounter, NoteCutInfo> noteCutInfos = new Dictionary<ISaberSwingRatingCounter, NoteCutInfo>();
// [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()
{
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion Counters+/UI/BSML/Config/Cut.bsml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<vertical spacing='1' horizontal-fit='PreferredSize'>
<checkbox-setting text='Separate Saber Cuts' apply-on-change='true' value='SeparateSaberCounts' hover-hint='Shows the average cut for the left and right sabers separately.'/>
<checkbox-setting text='Separate Cut Values' apply-on-change='true' value='SeparateCutValues' hover-hint='Show separate averages for angle before cut (0-70), angle after cut (0-30) and distance to center (0-15).'/>
<checkbox-setting text='Separate Cut Values' apply-on-change='true' value='SeparateCutValues' hover-hint='Show separate averages for pre-swing angle (0-70), post-swing angle (0-30), and accuracy (0-15).'/>
<list-setting text='Average Cut Precision' apply-on-change='true' value='AveragePrecision' options='DecimalPrecisions' hover-hint='How many decimals should be shown on the average cuts?'/>
<checkbox-setting text='Include Arc Notes' apply-on-change='true' value='IncludeArcs' hover-hint='Include arc notes in average cut calculations. These may not have a pre-swing or a post-swing score.'/>
<checkbox-setting text='Include Chain Notes' apply-on-change='true' value='IncludeChains' hover-hint='Include chain notes in average cut calculations. Chains will always give 20 accuracy points.'/>
</vertical>
2 changes: 1 addition & 1 deletion Counters+/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cbef4e6

Please sign in to comment.