Skip to content

Commit

Permalink
"Sit Out" option
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Mar 17, 2023
1 parent e09ddab commit 275325d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 54 deletions.
94 changes: 51 additions & 43 deletions Assets/Script/PlayMode/MicPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,57 +95,65 @@ private void Start() {
// Start mics
bool hasMic = false;
foreach (var player in PlayerManager.players) {
if (player.inputStrategy is MicInputStrategy micStrategy) {
// Skip if the player hasn't assigned a mic
if (micStrategy.microphoneIndex == -1 && !micStrategy.botMode) {
continue;
}
// Skip people who are sitting out
if (player.chosenInstrument != "vocals" && player.chosenInstrument != "harmVocals") {
continue;
}

// Skip over non-mic strategy players
if (player.inputStrategy is not MicInputStrategy micStrategy) {
continue;
}

hasMic = true;
// Skip if the player hasn't assigned a mic
if (micStrategy.microphoneIndex == -1 && !micStrategy.botMode) {
continue;
}

// Spawn needle
var needle = Instantiate(needlePrefab, transform);
needle.transform.localPosition = needlePrefab.transform.position;
hasMic = true;

// Spawn var
var bar = Instantiate(barPrefab, barContainer);
bar.transform.localPosition = new(0f, 0f, 0.8f - (barContainer.childCount - 1) * 0.225f);
// Spawn needle
var needle = Instantiate(needlePrefab, transform);
needle.transform.localPosition = needlePrefab.transform.position;

// Create player info
var groups = needle.GetComponentsInChildren<ParticleGroup>();
var playerInfo = new PlayerInfo {
player = player,
// Spawn var
var bar = Instantiate(barPrefab, barContainer);
bar.transform.localPosition = new(0f, 0f, 0.8f - (barContainer.childCount - 1) * 0.225f);

needle = needle.transform,
needleModel = needle.GetComponentInChildren<MeshRenderer>().gameObject,
nonActiveParticles = groups[0],
activeParticles = groups[1],
// Create player info
var groups = needle.GetComponentsInChildren<ParticleGroup>();
var playerInfo = new PlayerInfo {
player = player,

barMesh = bar.GetComponent<MeshRenderer>()
};
needle = needle.transform,
needleModel = needle.GetComponentInChildren<MeshRenderer>().gameObject,
nonActiveParticles = groups[0],
activeParticles = groups[1],

// Add to players
micInputs.Add(playerInfo);

if (!micStrategy.botMode) {
// Add child dummy audio source (for mic input reading)
var go = new GameObject();
go.transform.parent = transform;
var audio = go.AddComponent<AudioSource>();
dummyAudioSources.Add(micStrategy, audio);
audio.outputAudioMixerGroup = silentMixerGroup;
audio.loop = true;

// Start the mic!
var micName = Microphone.devices[micStrategy.microphoneIndex];
audio.clip = Microphone.Start(micName, true, 1, AudioSettings.outputSampleRate);

// Wait for the mic to start, then start the audio
while (Microphone.GetPosition(micName) <= 0) {
// This loop is weird, but it works.
}
audio.Play();
barMesh = bar.GetComponent<MeshRenderer>()
};

// Add to players
micInputs.Add(playerInfo);

if (!micStrategy.botMode) {
// Add child dummy audio source (for mic input reading)
var go = new GameObject();
go.transform.parent = transform;
var audio = go.AddComponent<AudioSource>();
dummyAudioSources.Add(micStrategy, audio);
audio.outputAudioMixerGroup = silentMixerGroup;
audio.loop = true;

// Start the mic!
var micName = Microphone.devices[micStrategy.microphoneIndex];
audio.clip = Microphone.Start(micName, true, 1, AudioSettings.outputSampleRate);

// Wait for the mic to start, then start the audio
while (Microphone.GetPosition(micName) <= 0) {
// This loop is weird, but it works.
}
audio.Play();
}
}

Expand Down
5 changes: 5 additions & 0 deletions Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ private IEnumerator StartSong() {
// Spawn tracks
int i = 0;
foreach (var player in PlayerManager.players) {
if (player.chosenInstrument == null) {
// Skip players that are sitting out
continue;
}

string trackPath = player.inputStrategy.GetTrackPath();

if (trackPath == null) {
Expand Down
38 changes: 27 additions & 11 deletions Assets/Script/UI/DifficultySelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,28 @@ private void Next() {
var player = PlayerManager.players[playerIndex];

if (state == State.INSTRUMENT) {
player.chosenInstrument = instruments[selected];
UpdateDifficulty();
if (selected >= instruments.Length) {
player.chosenInstrument = null;
IncreasePlayerIndex();
} else {
player.chosenInstrument = instruments[selected];
UpdateDifficulty();
}
} else if (state == State.DIFFICULTY) {
player.chosenDifficulty = (Difficulty) selected;
IncreasePlayerIndex();
} else if (state == State.VOCALS) {
foreach (var p in PlayerManager.players) {
p.chosenInstrument = selected == 0 ? "vocals" : "harmVocals";
if (selected == 1) {
foreach (var p in PlayerManager.players) {
p.chosenInstrument = null;
}
IncreasePlayerIndex();
} else {
foreach (var p in PlayerManager.players) {
p.chosenInstrument = selected == 0 ? "vocals" : "harmVocals";
}
UpdateVocalDifficulties();
}
UpdateVocalDifficulties();
} else if (state == State.VOCALS_DIFFICULTY) {
foreach (var p in PlayerManager.players) {
p.chosenDifficulty = (Difficulty) selected;
Expand All @@ -156,8 +168,6 @@ private void Next() {
// Skip over any MicInputStrategy's
playerIndex = -1;
IncreasePlayerIndex();

UpdateInstrument();
}
}

Expand Down Expand Up @@ -210,7 +220,7 @@ private void UpdateInstrument() {

// Get allowed instruments
var allowedInstruments = player.inputStrategy.GetAllowedInstruments();
optionCount = allowedInstruments.Length;
optionCount = allowedInstruments.Length + 1;

// Add to options
string[] ops = new string[6];
Expand All @@ -231,13 +241,14 @@ private void UpdateInstrument() {
_ => "Unknown"
};
}
ops[allowedInstruments.Length] = "Sit Out";

// Set text and sprites
for (int i = 0; i < 6; i++) {
options[i].SetText(ops[i]);
options[i].SetSelected(false);

if (ops[i] != null) {
if (i < instruments.Length) {
var sprite = Addressables.LoadAssetAsync<Sprite>($"FontSprites[{instruments[i]}]").WaitForCompletion();
options[i].SetImage(sprite);
}
Expand Down Expand Up @@ -275,10 +286,10 @@ private void UpdateVocalOptions() {

state = State.VOCALS;

optionCount = 1;
optionCount = 2;
string[] ops = {
"Solo",
null,
"Sit Out (All Vocals)",
null,
null,
null,
Expand All @@ -288,6 +299,11 @@ private void UpdateVocalOptions() {
for (int i = 0; i < 6; i++) {
options[i].SetText(ops[i]);
options[i].SetSelected(false);

if (i == 0) {
var sprite = Addressables.LoadAssetAsync<Sprite>("FontSprites[vocals]").WaitForCompletion();
options[i].SetImage(sprite);
}
}

selected = 0;
Expand Down
6 changes: 6 additions & 0 deletions Assets/Script/UI/ScoreSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public enum ScoreType {
private List<TextMeshProUGUI> text;

public void SetScore(PlayerManager.Player player, ScoreType type) {
if (player.chosenInstrument == null) {
playerName.text = player.DisplayName;
text[0].text = "<color=red>Sat Out</color>";
return;
}

playerName.text = $"<sprite name=\"{player.chosenInstrument}\"> {player.DisplayName}";

if (!player.lastScore.HasValue) {
Expand Down

0 comments on commit 275325d

Please sign in to comment.