Skip to content

Commit

Permalink
Fixed Discord and Twitch (and added tag stripping)
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed May 11, 2023
1 parent 1165d59 commit 5356f66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Assets/Script/PlayMode/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public bool Paused {
GameUI.Instance.videoPlayer.Play();
}
}
OnPauseToggle(_paused);

OnPauseToggle?.Invoke(_paused);
}
}

Expand Down Expand Up @@ -191,6 +192,8 @@ private void StartSong() {
break;
}
}

OnSongStart?.Invoke(song);
}

private void LoadBackground() {
Expand Down Expand Up @@ -493,6 +496,7 @@ public void Exit() {
backgroundRenderTexture.ClearTexture();
_tracks.Clear();

OnSongEnd?.Invoke(song);
GameManager.Instance.LoadScene(SceneIndex.MENU);
}

Expand Down
17 changes: 14 additions & 3 deletions Assets/Script/ThirdParty/TwitchController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using YARG.Data;
using YARG.PlayMode;
Expand All @@ -7,6 +8,8 @@

namespace YARG {
public class TwitchController : MonoBehaviour {
private static Regex TagRegex = new(@"<[^>]*>", RegexOptions.Compiled);

public static TwitchController Instance {
get;
private set;
Expand Down Expand Up @@ -57,9 +60,17 @@ void OnSongStart(SongEntry song) {
// Open the text file for appending
using var writer = new StreamWriter(TextFilePath, false);

// Write two lines of text to the file
writer.Write($"{song.Name}\n{song.Artist}\n{song.Album}\n{song.Genre}\n" +
$"{song.Year}\n{SongSources.SourceToGameName(song.Source)}\n{song.Charter}");
// Get the input
string str = $"{song.Name}\n{song.Artist}\n{song.Album}\n{song.Genre}\n" +
$"{song.Year}\n{SongSources.SourceToGameName(song.Source)}\n{song.Charter}";

// Strip tags
if (TagRegex.IsMatch(str)) {
str = TagRegex.Replace(str, string.Empty);
}

// Write text to the file
writer.Write(str);
}

void OnSongEnd(SongEntry song) {
Expand Down

0 comments on commit 5356f66

Please sign in to comment.