Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
Selecting an instrument and exiting without selecting a difficulty will no longer break setlistInstruments or setlistDifficulties.
  • Loading branch information
EscapeNumber001 committed Apr 19, 2023
1 parent 96cf745 commit 7986b37
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Assets/Script/UI/DifficultySelect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using TMPro;
Expand All @@ -20,6 +21,9 @@ private enum State {
VOCALS_DIFFICULTY
}

Dictionary<PlayerManager.Player, string> tempInstruments = new();
Dictionary<PlayerManager.Player, Difficulty> tempDifficulties = new();

[SerializeField]
private GenericOption[] options;
[SerializeField]
Expand Down Expand Up @@ -72,6 +76,8 @@ private void OnDisable() {
foreach (var player in PlayerManager.players) {
player.inputStrategy.GenericNavigationEvent -= OnGenericNavigation;
}
tempDifficulties.Clear();
tempInstruments.Clear();
}

private void OnDestroy() {
Expand Down Expand Up @@ -142,6 +148,7 @@ private void ClickOption(GenericOption option) {

public void Next() {
var player = PlayerManager.players[playerIndex];

string instrument = "";
if (state == State.INSTRUMENT) {
if (selected >= instruments.Length) {
Expand All @@ -153,9 +160,9 @@ public void Next() {
|| instrument == "ghDrums";
UpdateDifficulty(showExpertPlus);
}
player.setlistInstruments.Add(instrument);
tempInstruments.Add(player, instrument);
} else if (state == State.DIFFICULTY) {
player.setlistDifficulties.Add((Difficulty) selected);
tempDifficulties.Add(player, (Difficulty) selected);
OnInstrumentSelection?.Invoke(player);
IncreasePlayerIndex();
} else if (state == State.VOCALS) {
Expand Down Expand Up @@ -183,6 +190,22 @@ public void Next() {
}
}

private void WriteTempDiffAndInstrumentToPlayers() {
foreach (KeyValuePair<PlayerManager.Player, string> pair in tempInstruments) {
var player = pair.Key;
var instrument = pair.Value;

player.setlistInstruments.Add(instrument);
}

foreach (KeyValuePair<PlayerManager.Player, Difficulty> pair in tempDifficulties) {
var player = pair.Key;
var difficulty = pair.Value;

player.setlistDifficulties.Add(difficulty);
}
}

private void IncreasePlayerIndex() {
// Next non-mic player
playerIndex++;
Expand All @@ -199,6 +222,8 @@ private void IncreasePlayerIndex() {
speed = 1f;
}

WriteTempDiffAndInstrumentToPlayers();

// Play song (or download then play)

if (!isSetlistMode) {
Expand Down

0 comments on commit 7986b37

Please sign in to comment.