From 5356f6634044ec611e77de5d9ecddb17a12ff7f3 Mon Sep 17 00:00:00 2001 From: EliteAsian Date: Thu, 11 May 2023 18:27:30 -0400 Subject: [PATCH] Fixed Discord and Twitch (and added tag stripping) --- Assets/Script/PlayMode/Play.cs | 6 +++++- Assets/Script/ThirdParty/TwitchController.cs | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Assets/Script/PlayMode/Play.cs b/Assets/Script/PlayMode/Play.cs index 02fd54413..e78aad0da 100644 --- a/Assets/Script/PlayMode/Play.cs +++ b/Assets/Script/PlayMode/Play.cs @@ -101,7 +101,8 @@ public bool Paused { GameUI.Instance.videoPlayer.Play(); } } - OnPauseToggle(_paused); + + OnPauseToggle?.Invoke(_paused); } } @@ -191,6 +192,8 @@ private void StartSong() { break; } } + + OnSongStart?.Invoke(song); } private void LoadBackground() { @@ -493,6 +496,7 @@ public void Exit() { backgroundRenderTexture.ClearTexture(); _tracks.Clear(); + OnSongEnd?.Invoke(song); GameManager.Instance.LoadScene(SceneIndex.MENU); } diff --git a/Assets/Script/ThirdParty/TwitchController.cs b/Assets/Script/ThirdParty/TwitchController.cs index ac88f62a9..61376f179 100644 --- a/Assets/Script/ThirdParty/TwitchController.cs +++ b/Assets/Script/ThirdParty/TwitchController.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Text.RegularExpressions; using UnityEngine; using YARG.Data; using YARG.PlayMode; @@ -7,6 +8,8 @@ namespace YARG { public class TwitchController : MonoBehaviour { + private static Regex TagRegex = new(@"<[^>]*>", RegexOptions.Compiled); + public static TwitchController Instance { get; private set; @@ -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) {