Skip to content

Commit

Permalink
1.20+
Browse files Browse the repository at this point in the history
  • Loading branch information
kinsi55 committed Apr 1, 2022
1 parent c116cd0 commit 1906494
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class Config {
public virtual List<int> splits { get; set; } = new List<int>() { 115, 114, 110, 100, 0 };

public static IEnumerable<int> FilterSplitsList(IEnumerable<int> splits) {
var x = splits.Where(x => x <= ScoreModel.kMaxCutRawScore && x >= 0).Distinct().OrderByDescending(x => x);
var x = splits.Where(x => x <= 115 && x >= 0).Distinct().OrderByDescending(x => x);

if(!x.Any())
return new[] { 115 };
Expand Down
31 changes: 11 additions & 20 deletions HitscoreCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
using System.Runtime.CompilerServices;
using TMPro;
using UnityEngine;
using Zenject;

namespace HitscoreCounter {
public class HitscoreCounter : BasicCustomCounter, INoteEventHandler, ISaberSwingRatingCounterDidFinishReceiver {
public class HitscoreCounter : BasicCustomCounter {
TMP_Text[] hintLabels;
TMP_Text[] valueLabels;
int[] targets;
int[] values;

[Inject] ScoreController scoreController;

public override void CounterInit() {
var label = CanvasUtility.CreateTextFromSettings(Settings);
label.text = "Hitscores";
Expand Down Expand Up @@ -54,7 +57,7 @@ TMP_Text CreateLabel(TextAlignmentOptions align, Vector3 offset, float fontSize
}
}

var prevValue = ScoreModel.kMaxCutRawScore + 1;
var prevValue = 116;
for(var i = 0; i < countersCount; i++) {
if(!Config.Instance.verticalLayout)
hintLabels[i].fontStyle = FontStyles.Underline;
Expand All @@ -80,13 +83,16 @@ TMP_Text CreateLabel(TextAlignmentOptions align, Vector3 offset, float fontSize
prevValue = Config.Instance.splits[i];
targets[i] = Config.Instance.splits[i] - 1;
}

scoreController.scoringForNoteFinishedEvent += ScoreController_scoringForNoteFinishedEvent;
}

public override void CounterDestroy() {
hintLabels = null;
valueLabels = null;
targets = null;
values = null;
scoreController.scoringForNoteFinishedEvent -= ScoreController_scoringForNoteFinishedEvent;
}

void IncrementValueLabelForHitscore(int hitscore) {
Expand All @@ -98,26 +104,11 @@ void IncrementValueLabelForHitscore(int hitscore) {
}
}

private Dictionary<ISaberSwingRatingCounter, float> noteCutAccs = new Dictionary<ISaberSwingRatingCounter, float>();
public void OnNoteCut(NoteData data, NoteCutInfo info) {
if(!info.allIsOK || data.colorType == ColorType.None)
private void ScoreController_scoringForNoteFinishedEvent(ScoringElement scoringElement) {
if(!(scoringElement is GoodCutScoringElement goodCut && goodCut.noteData.scoringType == NoteData.ScoringType.Normal))
return;

noteCutAccs.Add(info.swingRatingCounter, info.cutDistanceToCenter);
info.swingRatingCounter.RegisterDidFinishReceiver(this);
}

public void OnNoteMiss(NoteData data) { }

public void HandleSaberSwingRatingCounterDidFinish(ISaberSwingRatingCounter saberSwingRatingCounter) {
if(!noteCutAccs.TryGetValue(saberSwingRatingCounter, out var nci))
return;

noteCutAccs.Remove(saberSwingRatingCounter);

ScoreModel.RawScoreWithoutMultiplier(saberSwingRatingCounter, nci, out int beforeCut, out int afterCut, out int cutDistance);

IncrementValueLabelForHitscore(beforeCut + afterCut + cutDistance);
IncrementValueLabelForHitscore(scoringElement.cutScore);
}
}
}
6 changes: 6 additions & 0 deletions HitscoreCounter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
<Reference Include="UnityEngine.VRModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
</Reference>
<Reference Include="Zenject">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
</Reference>
<Reference Include="Zenject-usage">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject-usage.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Images\icon.png" />
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"id": "HitscoreCounter",
"name": "HitscoreCounter",
"author": "Kinsi55",
"version": "0.1.0",
"version": "0.1.1",
"description": "Counter for Counters+ that counts the scores of your cuts grouped into configurable ranges",
"gameVersion": "1.18.3",
"gameVersion": "1.20.0",
"dependsOn": {
"BSIPA": "^4.0.5",
"Counters+": "^2.2.0"
"Counters+": "^2.2.7"
},
"features": {
"CountersPlus.CustomCounter": {
Expand Down

0 comments on commit 1906494

Please sign in to comment.