Skip to content

Commit

Permalink
Updated CurrentSong.txt (#152)
Browse files Browse the repository at this point in the history
+ Added more song information in the TXT, JSON still would be really good, but its already possible to do a lot with the .txt and some crops in the Text Source
--- Album
--- Genre
--- Year
--- Source
--- Charter
+ Changed the way the code works to just empty the files when its not in a song, this avoids some errors in OBS if you open the software and its not in a song for example
  • Loading branch information
kaduwaengertner authored Apr 21, 2023
1 parent a233eda commit 19a41c6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Assets/Script/ThirdParty/TwitchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static TwitchController Instance {
private set;
}

// Creates .TXT file witth current song information
public string TextFilePath => Path.Combine(GameManager.PersistentDataPath, "currentSong.txt");

private void Start() {
Expand All @@ -32,13 +33,19 @@ private void Start() {
}

private void CreateEmptySongFile() {
File.Create(TextFilePath).Dispose();
// Open the text file for appending
using var writer = new StreamWriter(TextFilePath, false);

// Make the file blank (Avoid errors in OBS)
writer.Write("");
}

private void DeleteCurrentSongFile() {
if (File.Exists(TextFilePath)) {
File.Delete(TextFilePath);
}
// Open the text file for appending
using var writer = new StreamWriter(TextFilePath, false);

// Make the file blank (Avoid errors in OBS)
writer.Write("");
}

private void OnApplicationQuit() {
Expand All @@ -50,21 +57,23 @@ void OnSongStart(SongInfo song) {
using var writer = new StreamWriter(TextFilePath, false);

// Write two lines of text to the file
writer.Write($"{song.SongName}\n{song.artistName}");
writer.Write($"{song.SongName}\n{song.artistName}\n{song.album}\n{song.genre}\n{song.year}\n{song.SourceFriendlyName}\n{song.charter}");
}

void OnSongEnd(SongInfo song) {
// When the song ends, empty the file
DeleteCurrentSongFile();
CreateEmptySongFile();
// Open the text file for appending
using var writer = new StreamWriter(TextFilePath, false);

// Make the file blank (Avoid errors in OBS)
writer.Write("");
}

private void OnInstrumentSelection(PlayerManager.Player playerInfo) {
// TODO
// Selecting Instrument
}

private void OnPauseToggle(bool pause) {
// TODO
// Game Paused
}
}
}
}

0 comments on commit 19a41c6

Please sign in to comment.