Skip to content

Commit

Permalink
refactor StarScoreKeeper for easier adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
muskit committed May 7, 2023
1 parent 01c54e9 commit 49306ea
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions Assets/Script/PlayMode/StarScoreKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ public class StarScoreKeeper {
/// <summary>
/// Minimum avg. multipliers to get 1, 2, 3, 4, 5, and gold stars respectively.
/// </summary>
public static readonly Dictionary<string, float[]> instrumentThreshold = new() {
{ "guitar", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "bass", new float[] { .21f, .5f, .9f, 2.77f, 4.62f, 6.78f } },
{ "keys", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "guitarCoop", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "rhythm", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "realGuitar", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "realBass", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "drums", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "realDrums", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "ghDrums", new float[] { .21f, .46f, .77f, 1.85f, 3.08f, 4.52f } },
{ "vocals", new float[] { 4f*0.05f, 4f*0.11f, 4f*0.19f, 4f*0.46f, 4f*0.77f, 4f*1.06f } },
{ "harmVocals", new float[] { 4f*0.05f, 4f*0.11f, 4f*0.19f, 4f*0.46f, 4f*0.77f, 4f*1.06f } }
};
public static readonly float[] starThresholdsDefault = {.21f, .46f, .77f, 1.85f, 3.08f, 4.52f};
/// <summary>
/// Minimum avg. multipliers to get 1, 2, 3, 4, 5, and gold stars on Bass respectively.
/// </summary>
public static readonly float[] starThresholdsBass = { .21f, .5f, .9f, 2.77f, 4.62f, 6.78f };
/// <summary>
/// Minimum avg. multipliers to get 1, 2, 3, 4, 5, and gold stars on Vocals respectively.
/// </summary>
public static readonly float[] starThresholdsVocals = { 4f*0.05f, 4f*0.11f, 4f*0.19f, 4f*0.46f, 4f*0.77f, 4f*1.06f };

// keep track of all instances in Play to calculate the band total
public static List<StarScoreKeeper> instances = new();
Expand Down Expand Up @@ -59,24 +54,24 @@ public static void Reset() {
/// <summary>
/// Minimum points needed to get 1, 2, 3, 4, 5, and gold stars respectively.
/// </summary>
public double[] scoreThreshold;
public double[] scoreThresholds;

/// <summary>
/// How many stars currently earned.
/// </summary>
public double Stars {
get {
int stars = 5;
while (stars >= 0 && scoreKeeper.Score < scoreThreshold[stars]) { --stars; }
while (stars >= 0 && scoreKeeper.Score < scoreThresholds[stars]) { --stars; }
stars += 1; // stars earned, also index of threshold for next star

switch (stars) {
case int s when s == 0:
return scoreKeeper.Score / scoreThreshold[s];
return scoreKeeper.Score / scoreThresholds[s];
case int s when s <= 5:
return (double) s + (scoreKeeper.Score - scoreThreshold[s - 1]) / (scoreThreshold[s] - scoreThreshold[s - 1]);
return (double) s + (scoreKeeper.Score - scoreThresholds[s - 1]) / (scoreThresholds[s] - scoreThresholds[s - 1]);
default: // 6+ stars
return (double) 5 + (scoreKeeper.Score - scoreThreshold[4]) / (scoreThreshold[5] - scoreThreshold[4]);
return (double) 5 + (scoreKeeper.Score - scoreThresholds[4]) / (scoreThresholds[5] - scoreThresholds[4]);
}
}
}
Expand Down Expand Up @@ -108,14 +103,19 @@ public StarScoreKeeper(ScoreKeeper scoreKeeper, string instrument, int noteCount

// populate scoreThreshold
private void SetupScoreThreshold(string instrument) {
scoreThreshold = new double[] {
instrumentThreshold[instrument][0] * BaseScore,
instrumentThreshold[instrument][1] * BaseScore,
instrumentThreshold[instrument][2] * BaseScore,
instrumentThreshold[instrument][3] * BaseScore,
instrumentThreshold[instrument][4] * BaseScore,
instrumentThreshold[instrument][5] * BaseScore
};
float[] curThresholds;
switch (instrument) {
case var i when i.ToLower().Contains("bass"):
curThresholds = starThresholdsBass;
break;
case var i when i.ToLower().Contains("vocal"):
curThresholds = starThresholdsVocals;
break;
default:
curThresholds = starThresholdsDefault;
break;
}
scoreThresholds = (from mul in curThresholds select mul * BaseScore).ToArray();
}
}
}

0 comments on commit 49306ea

Please sign in to comment.