From ffe3a4ba159f1f0d467cfff25ed253e60a81b4ea Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 3 Oct 2019 18:23:40 -0700 Subject: [PATCH] Relocate resource naming for sprite fetch to draw --- PKHeX.Core/Legality/Tables/Tables.cs | 24 ------ PKHeX.Core/PKM/Util/PKX.cs | 30 ------- .../Names}/BoxWallpaper.cs | 74 ++++++++--------- PKHeX.Drawing/Names/SpriteName.cs | 81 +++++++++++++++++++ PKHeX.Drawing/Sprites/SpriteBuilder.cs | 2 +- PKHeX.Drawing/Sprites/SpriteUtil.cs | 2 +- .../Controls/SAV Editor/CryPlayer.cs | 3 +- PKHeX.WinForms/MainWindow/Main.cs | 2 +- 8 files changed, 119 insertions(+), 99 deletions(-) rename {PKHeX.Core/Saves/Substructures => PKHeX.Drawing/Names}/BoxWallpaper.cs (56%) create mode 100644 PKHeX.Drawing/Names/SpriteName.cs diff --git a/PKHeX.Core/Legality/Tables/Tables.cs b/PKHeX.Core/Legality/Tables/Tables.cs index 3d509c460..9900fb9ed 100644 --- a/PKHeX.Core/Legality/Tables/Tables.cs +++ b/PKHeX.Core/Legality/Tables/Tables.cs @@ -37,30 +37,6 @@ public static partial class Legal 358, // Chimecho }; - /// - /// Species that show their default Species sprite regardless of current - /// - public static readonly HashSet SpeciesDefaultFormSprite = new HashSet - { - 414, // Mothim - 493, // Arceus - 664, // Scatterbug - 665, // Spewpa - 773, // Silvally - 778, // Mimikyu - }; - - /// - /// Species that show a specific Sprite - /// - public static readonly HashSet SpeciesGenderedSprite = new HashSet - { - 521, // Unfezant - 592, // Frillish - 593, // Jellicent - 668, // Pyroar - }; - public static readonly HashSet FormChange = new HashSet // Pokémon that can change form and retain it { 386, // Deoxys diff --git a/PKHeX.Core/PKM/Util/PKX.cs b/PKHeX.Core/PKM/Util/PKX.cs index 8e38b5b5f..1901a6651 100644 --- a/PKHeX.Core/PKM/Util/PKX.cs +++ b/PKHeX.Core/PKM/Util/PKX.cs @@ -418,36 +418,6 @@ public static uint GetRandomPID(int species, int cg, int origin, int nature, int } } - // Data Requests - public static string GetResourceStringBall(int ball) => $"_ball{ball}"; - private const string ResourceSeparator = "_"; - private const string ResourcePikachuCosplay = "c"; // osplay - private const string ResourceShiny = "s"; // hiny - private const string ResourceGGStarter = "p"; //artner - public static bool AllowShinySprite { get; set; } - - public static string GetResourceStringSprite(int species, int form, int gender, int generation = Generation, bool shiny = false) - { - if (Legal.SpeciesDefaultFormSprite.Contains(species)) // Species who show their default sprite regardless of Form - form = 0; - - var sb = new System.Text.StringBuilder(); - { sb.Append(ResourceSeparator); sb.Append(species); } - if (form > 0) - { sb.Append(ResourceSeparator); sb.Append(form); } - else if (gender == 1 && Legal.SpeciesGenderedSprite.Contains(species)) // Frillish & Jellicent, Unfezant & Pyroar - { sb.Append(ResourceSeparator); sb.Append(gender); } - - if (species == 25 && form > 0 && generation == 6) // Cosplay Pikachu - sb.Append(ResourcePikachuCosplay); - else if (GameVersion.GG.Contains(PKMConverter.Trainer.Game) && (species == 25 || species == 133) && form != 0) - sb.Append(ResourceGGStarter); - - if (shiny && AllowShinySprite) - sb.Append(ResourceShiny); - return sb.ToString(); - } - /// /// Gets the Unown Forme ID from PID. /// diff --git a/PKHeX.Core/Saves/Substructures/BoxWallpaper.cs b/PKHeX.Drawing/Names/BoxWallpaper.cs similarity index 56% rename from PKHeX.Core/Saves/Substructures/BoxWallpaper.cs rename to PKHeX.Drawing/Names/BoxWallpaper.cs index 1ce060d5b..09617b710 100644 --- a/PKHeX.Core/Saves/Substructures/BoxWallpaper.cs +++ b/PKHeX.Drawing/Names/BoxWallpaper.cs @@ -1,6 +1,8 @@ -using static PKHeX.Core.GameVersion; +using PKHeX.Core; -namespace PKHeX.Core +using static PKHeX.Core.GameVersion; + +namespace PKHeX.Drawing { /// /// Retrieves Box Storage wallpaper metadata. @@ -9,7 +11,7 @@ public static class BoxWallpaper { public static string GetWallpaperResourceName(GameVersion version, int index) { - index++; + index++; // start indexes at 1 var suffix = GetResourceSuffix(version, index); return $"box_wp{index:00}{suffix}"; } @@ -54,52 +56,42 @@ public static bool IsWallpaperRed(GameVersion version, int wallpaperID) case 3: if (CXD.Contains(version)) return wallpaperID == 7; // flame pattern in XD - switch (wallpaperID) + + return wallpaperID switch { - case 5: // Volcano - return true; - case 13: // PokéCenter - return E == version; - default: - return false; - } + 5 => true, // Volcano + 13 => E == version, // PokéCenter + _ => false, + }; case 4: - switch (wallpaperID) + return wallpaperID switch { - case 5: // Volcano - case 12: // Checks - case 13: // PokéCenter - case 22: // Special - return true; - default: - return false; - } + 5 => true, // Volcano + 12 => true, // Checks + 13 => true, // PokéCenter + 22 => true, // Special + _ => false + }; case 5: - switch (wallpaperID) + return wallpaperID switch { - case 5: // Volcano - case 12: // Checks - return true; - case 19: // PWT - case 22: // Reshiram - return B2W2.Contains(version); - case 21: // Zoroark - case 23: // Musical - return BW.Contains(version); - default: - return false; - } + 5 => true, // Volcano + 12 => true, // Checks + 19 => B2W2.Contains(version), // PWT + 22 => B2W2.Contains(version), // Reshiram + 21 => BW.Contains(version), // Zoroark + 23 => BW.Contains(version), // Musical + _ => false + }; case 6: case 7: - switch (wallpaperID) + return wallpaperID switch { - case 5: // Volcano - case 12: // PokéCenter - case 20: // Special5 Flare/Magma - return true; - default: - return false; - } + 5 => true, // Volcano + 12 => true, // PokéCenter + 20 => true, // Special5 Flare/Magma + _ => false + }; case 8: // todo swsh return true; default: diff --git a/PKHeX.Drawing/Names/SpriteName.cs b/PKHeX.Drawing/Names/SpriteName.cs new file mode 100644 index 000000000..889bdae38 --- /dev/null +++ b/PKHeX.Drawing/Names/SpriteName.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; +using System.Text; +using PKHeX.Core; + +namespace PKHeX.Drawing +{ + public static class SpriteName + { + public static bool AllowShinySprite { get; set; } + + private const string Separator = "_"; + private const string Cosplay = "c"; + private const string Shiny = "s"; + private const string GGStarter = "p"; + + /// + /// Gets the resource name of the sprite. + /// + public static string GetResourceStringBall(int ball) => $"_ball{ball}"; + + /// + /// Gets the resource name of the Pokémon sprite. + /// + public static string GetResourceStringSprite(int species, int form, int gender, int generation = PKX.Generation, bool shiny = false) + { + if (SpeciesDefaultFormSprite.Contains(species)) // Species who show their default sprite regardless of Form + form = 0; + + var sb = new StringBuilder(); + { sb.Append(Separator); sb.Append(species); } + + if (form != 0) + { + sb.Append(Separator); sb.Append(form); + + if (species == (int) Species.Pikachu) + { + if (generation == 6) + sb.Append(Cosplay); + else if (form == 8) + sb.Append(GGStarter); + } + else if (species == (int) Species.Eevee) + { + if (form == 1) + sb.Append(GGStarter); + } + } + else if (gender == 1 && SpeciesGenderedSprite.Contains(species)) + { sb.Append(Separator); sb.Append(gender); } + + if (shiny && AllowShinySprite) + sb.Append(Shiny); + return sb.ToString(); + } + + /// + /// Species that show their default Species sprite regardless of current + /// + private static readonly HashSet SpeciesDefaultFormSprite = new HashSet + { + (int)Species.Mothim, + (int)Species.Arceus, + (int)Species.Scatterbug, + (int)Species.Spewpa, + (int)Species.Silvally, + (int)Species.Mimikyu, + }; + + /// + /// Species that show a specific Sprite + /// + private static readonly HashSet SpeciesGenderedSprite = new HashSet + { + (int)Species.Unfezant, + (int)Species.Frillish, + (int)Species.Jellicent, + (int)Species.Pyroar, + }; + } +} diff --git a/PKHeX.Drawing/Sprites/SpriteBuilder.cs b/PKHeX.Drawing/Sprites/SpriteBuilder.cs index 1a8b8d43d..c7fbeaff1 100644 --- a/PKHeX.Drawing/Sprites/SpriteBuilder.cs +++ b/PKHeX.Drawing/Sprites/SpriteBuilder.cs @@ -81,7 +81,7 @@ private static Image GetBaseImageTotem(int species, int form, int gender, bool s private static Image GetBaseImageDefault(int species, int form, int gender, bool shiny, int generation) { - var file = PKX.GetResourceStringSprite(species, form, gender, generation, shiny); + var file = SpriteName.GetResourceStringSprite(species, form, gender, generation, shiny); return (Image)Resources.ResourceManager.GetObject(file); } diff --git a/PKHeX.Drawing/Sprites/SpriteUtil.cs b/PKHeX.Drawing/Sprites/SpriteUtil.cs index 1593d12cf..baac66ee3 100644 --- a/PKHeX.Drawing/Sprites/SpriteUtil.cs +++ b/PKHeX.Drawing/Sprites/SpriteUtil.cs @@ -10,7 +10,7 @@ public static class SpriteUtil public static Image GetBallSprite(int ball) { - string resource = PKX.GetResourceStringBall(ball); + string resource = SpriteName.GetResourceStringBall(ball); return (Image)Resources.ResourceManager.GetObject(resource) ?? Resources._ball4; // Poké Ball (default) } diff --git a/PKHeX.WinForms/Controls/SAV Editor/CryPlayer.cs b/PKHeX.WinForms/Controls/SAV Editor/CryPlayer.cs index cd49592dc..839e5da0b 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/CryPlayer.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/CryPlayer.cs @@ -1,6 +1,7 @@ using System.IO; using System.Media; using PKHeX.Core; +using PKHeX.Drawing; namespace PKHeX.WinForms.Controls { @@ -26,7 +27,7 @@ public void PlayCry(PKM pk) private static string GetCryPath(PKM pk, string cryFolder) { - var name = PKX.GetResourceStringSprite(pk.Species, pk.AltForm, pk.Gender, pk.Format).Replace('_', '-').Substring(1); + var name = SpriteName.GetResourceStringSprite(pk.Species, pk.AltForm, pk.Gender, pk.Format).Replace('_', '-').Substring(1); var path = Path.Combine(cryFolder, $"{name}.wav"); if (!File.Exists(path)) path = Path.Combine(cryFolder, $"{pk.Species}.wav"); diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 04f8bd254..823d71cdb 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -428,7 +428,7 @@ private void ReloadProgramSettings(Settings settings) Draw.LoadBrushes(); PKME_Tabs.Unicode = Unicode = settings.Unicode; PKME_Tabs.UpdateUnicode(GenderSymbols); - PKX.AllowShinySprite = settings.ShinySprites; + SpriteName.AllowShinySprite = settings.ShinySprites; SaveFile.SetUpdateDex = settings.SetUpdateDex ? PKMImportSetting.Update : PKMImportSetting.Skip; SaveFile.SetUpdatePKM = settings.SetUpdatePKM ? PKMImportSetting.Update : PKMImportSetting.Skip; C_SAV.ModifyPKM = PKME_Tabs.ModifyPKM = settings.SetUpdatePKM;