Skip to content

Commit

Permalink
Refactor song handling logic and fix bug in Start.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
jooapa committed Jan 19, 2024
1 parent c79c0e9 commit e178e91
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ public static void AddSong(string song)
return;
}
}
if (!File.Exists(song)) {
AnsiConsole.MarkupLine("[red]Song not found[/]");
return;
}
// add song to current Utils.songs
Array.Resize(ref Utils.songs, Utils.songs.Length + 1);
Utils.songs[Utils.songs.Length - 1] = song;
Expand All @@ -327,9 +323,16 @@ public static void DeleteSong(int index)
ResetMusic();
if (index == Utils.songs.Length)
{
Utils.currentSongIndex = Utils.songs.Length - 1;
if (Utils.songs.Length == 0) {
Utils.songs = new string[] { "" };
}
else {
Utils.currentSongIndex = Utils.songs.Length - 1;
}
}
Start.state = MainStates.playing;

// if no songs left, add "" to Utils.songs
PlaySong(Utils.songs, Utils.currentSongIndex);
}

Expand Down
10 changes: 9 additions & 1 deletion src/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void Run(string[] args)
} else {
state = MainStates.idle;
Debug.dprint("Start Loop");
loopThread = new Thread(Start.Loop);
loopThread = new Thread(Loop);
loopThread.Start();
}
}
Expand All @@ -117,14 +117,22 @@ public static void Loop()

TUI.ClearScreen();
drawOnce = true;

while (true)
{
// if the frist song is "" then there are more songs
if (Utils.songs[0] == "" && Utils.songs.Length > 1) {
state = MainStates.play;
Play.DeleteSong(0);
}

if (consoleWidth != Console.WindowWidth || consoleHeight != Console.WindowHeight) {
consoleHeight = Console.WindowHeight;
consoleWidth = Console.WindowWidth;
TUI.ClearScreen();
TUI.DrawPlayer();
}

switch (state)
{
case MainStates.idle:
Expand Down
2 changes: 1 addition & 1 deletion src/TUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static void PlaylistInput() {
if (songToAdd == "" || songToAdd == null) { break; }
// remove quotes from songToAdd
songToAdd = songToAdd.Replace("\"", "");
songToAdd = Absolute.ConvertToAbsolutePath(songToAdd);
songToAdd = Absolute.Correctify(new string[] { songToAdd })[0];
Play.AddSong(songToAdd);
break;
case "2": // delete current song from playlist
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public struct Utils
public static string jammerPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\jammer\\";
public static bool isDebug = false;
public static string currentPlaylist = "";
public static string version = "1.1.6";
public static string version = "1.1.7";
}
}

0 comments on commit e178e91

Please sign in to comment.