PKHeX/PKHeX.WinForms/Controls/Slots/CryPlayer.cs
Kurt fc754b346b
File scoped namespaces (#3529)
[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces)

Updates all the files, one less level of indentation.

Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
2022-06-18 11:04:24 -07:00

56 lines
1.6 KiB
C#

using System.Diagnostics;
using System.IO;
using System.Media;
using PKHeX.Core;
using PKHeX.Drawing.PokeSprite;
namespace PKHeX.WinForms.Controls;
public sealed class CryPlayer
{
private readonly SoundPlayer Sounds = new();
public void PlayCry(ISpeciesForm pk, int format)
{
if (pk.Species == 0)
return;
string path = GetCryPath(pk, Main.CryPath, format);
if (!File.Exists(path))
return;
Sounds.SoundLocation = path;
try { Sounds.Play(); }
catch { Debug.WriteLine("Failed to play sound."); }
}
public void Stop()
{
if (string.IsNullOrWhiteSpace(Sounds.SoundLocation))
return;
try { Sounds.Stop(); }
catch { Debug.WriteLine("Failed to stop sound."); }
}
private static string GetCryPath(ISpeciesForm pk, string cryFolder, int format)
{
var name = GetCryFileName(pk, format);
var path = Path.Combine(cryFolder, $"{name}.wav");
if (!File.Exists(path))
path = Path.Combine(cryFolder, $"{pk.Species}.wav");
return path;
}
private static string GetCryFileName(ISpeciesForm pk, int format)
{
if (pk.Species == (int)Species.Urshifu && pk.Form == 1) // same sprite for both forms, but different cries
return "892-1";
// don't grab sprite of pk, no gender specific cries
var res = SpriteName.GetResourceStringSprite(pk.Species, pk.Form, 0, 0, format);
// people like - instead of _ file names ;)
return res.Replace('_', '-')[1..]; // skip leading underscore
}
}