Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed warnings #7

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ib.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
dotnet build
59 changes: 59 additions & 0 deletions src/Keyboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Raylib_cs;
using Spectre.Console;

namespace jammer
{
public partial class Start
{
public static void CheckKeyboard()
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey(true).Key;
switch (key)
{
case ConsoleKey.Spacebar:
if (Raylib.IsMusicReady(Utils.currentMusic) && !Raylib.IsMusicStreamPlaying(Utils.currentMusic))
{
Play.PlaySong();
state = MainStates.playing;
drawOnce = true;
}
else if (Raylib.IsMusicStreamPlaying(Utils.currentMusic))
{
Console.WriteLine("Paused");
state = MainStates.pause;
drawOnce = true;
}
else
//NOTE(ra) Resumed is not called at all. PlaySong resumes after pause.
{
Console.WriteLine("Resumed");
Play.ResumeSong();
}
break;
case ConsoleKey.F12:
Console.WriteLine("CurrentState: " + state);
break;
case ConsoleKey.Q:
Console.WriteLine("Quit");
AnsiConsole.Clear();
Environment.Exit(0);
break;

case ConsoleKey.Escape:
AnsiConsole.Clear();
Console.WriteLine("Quit");
Environment.Exit(0);
break;
case ConsoleKey.RightArrow:
state = MainStates.next;
break;
case ConsoleKey.LeftArrow:
Play.PrevSong();
break;
}
}
}
}
}
18 changes: 9 additions & 9 deletions src/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static public bool GetIsLoop()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.IsLoop;
return settings?.IsLoop ?? false;
}
else
{
Expand All @@ -70,7 +70,7 @@ static public float GetVolume()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.Volume;
return settings?.Volume ?? 0;
}
else
{
Expand All @@ -85,7 +85,7 @@ static public bool GetIsMuted()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.isMuted;
return settings?.isMuted ?? false;
}
else
{
Expand All @@ -100,7 +100,7 @@ static public float GetOldVolume()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.OldVolume;
return settings?.OldVolume ?? 0;
}
else
{
Expand All @@ -115,7 +115,7 @@ static public int GetRefreshTimes()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.refreshTimes;
return settings?.refreshTimes ?? 0;
}
else
{
Expand All @@ -130,7 +130,7 @@ static public int GetForwardSeconds()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.forwardSeconds;
return settings?.forwardSeconds ?? 0;
}
else
{
Expand All @@ -145,7 +145,7 @@ static public int GetRewindSeconds()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.rewindSeconds;
return settings?.rewindSeconds ?? 0;
}
else
{
Expand All @@ -160,7 +160,7 @@ static public float GetChangeVolumeBy()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.changeVolumeBy;
return settings?.changeVolumeBy ?? 0;
}
else
{
Expand All @@ -175,7 +175,7 @@ static public bool GetIsShuffle()
{
string jsonString = System.IO.File.ReadAllText(jammerPath);
Settings? settings = JsonSerializer.Deserialize<Settings>(jsonString);
return settings.isShuffle;
return settings?.isShuffle ?? true;
}
else
{
Expand Down
55 changes: 1 addition & 54 deletions src/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum MainStates
next
}

public class Start
public partial class Start
{
//NOTE(ra) Starting state to playing.
// public static MainStates state = MainStates.idle;
Expand Down Expand Up @@ -136,59 +136,6 @@ static void Loop()
Play.PlaySong(Utils.songs, Utils.currentSongIndex);
state = MainStates.play;
break;


}
}
}

public static void CheckKeyboard()
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey(true).Key;
switch (key)
{
case ConsoleKey.Spacebar:
if (Raylib.IsMusicReady(Utils.currentMusic) && !Raylib.IsMusicStreamPlaying(Utils.currentMusic))
{
Play.PlaySong();
state = MainStates.playing;
drawOnce = true;
}
else if (Raylib.IsMusicStreamPlaying(Utils.currentMusic))
{
Console.WriteLine("Paused");
state = MainStates.pause;
drawOnce = true;
}
else
//NOTE(ra) Resumed is not called at all. PlaySong resumes after pause.
{
Console.WriteLine("Resumed");
Play.ResumeSong();
}
break;
case ConsoleKey.F12:
Console.WriteLine("CurrentState: " + state);
break;
case ConsoleKey.Q:
Console.WriteLine("Quit");
AnsiConsole.Clear();
Environment.Exit(0);
break;

case ConsoleKey.Escape:
AnsiConsole.Clear();
Console.WriteLine("Quit");
Environment.Exit(0);
break;
case ConsoleKey.RightArrow:
state = MainStates.next;
break;
case ConsoleKey.LeftArrow:
Play.PrevSong();
break;
}
}
}
Expand Down