Refactoring

improve speed for resource fetch, add optional Shiny parameter
(currently unused)
#1735
This commit is contained in:
Kurt 2018-01-02 16:53:39 -08:00
parent 0f21fc2217
commit 6a9e2ed4b9
2 changed files with 38 additions and 10 deletions

View File

@ -35,6 +35,28 @@ public static partial class Legal
315, 407, // Roselia
358, // Chimecho
};
/// <summary>
/// Species that show their default Species sprite regardless of current <see cref="PKM.AltForm"/>
/// </summary>
public static readonly HashSet<int> SpeciesDefaultFormSprite = new HashSet<int>
{
414, // Mothim
493, // Arceus
664, // Scatterbug
665, // Spewpa
773, // Silvally
778, // Mimikyu
};
/// <summary>
/// Species that show a <see cref="PKM.Gender"/> specific Sprite
/// </summary>
public static readonly HashSet<int> SpeciesGenderedSprite = new HashSet<int>
{
521, // Unfezant
592, // Frillish
593, // Jellicent
668, // Pyroar
};
public static readonly HashSet<int> FormChange = new HashSet<int> // Pokémon that can change form and retain it
{
386, // Deoxys

View File

@ -568,21 +568,27 @@ public static uint GetRandomPID(int species, int cg, int origin, int nature, int
// Data Requests
public static string GetResourceStringBall(int ball) => $"_ball{ball}";
public static string GetResourceStringSprite(int species, int form, int gender, int generation = Generation)
private const string ResourceSeparator = "_";
private const string ResourcePikachuCap = "c";
private const string ResourceShiny = "s";
public static bool AllowShinySprite = false;
public static string GetResourceStringSprite(int species, int form, int gender, int generation = Generation, bool shiny = false)
{
if (new[] { 778, 664, 665, 414, 493, 773 }.Contains(species)) // Species who show their default sprite regardless of Form
if (Legal.SpeciesDefaultFormSprite.Contains(species)) // Species who show their default sprite regardless of Form
form = 0;
string file = $"_{species}";
if (form > 0) // Alt Form Handling
file += $"_{form}";
else if (gender == 1 && new[] { 592, 593, 521, 668 }.Contains(species)) // Frillish & Jellicent, Unfezant & Pyroar
file += $"_{gender}";
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 >= 7) // Pikachu
file += "c"; // Cap
return file;
sb.Append(ResourcePikachuCap);
if (shiny && AllowShinySprite)
sb.Append(ResourceShiny);
return sb.ToString();
}
/// <summary>