Minor tweaks

This commit is contained in:
Kurt 2022-05-07 11:47:01 -07:00
parent 51a8dbaeac
commit 178069f889
8 changed files with 39 additions and 49 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
@ -6,6 +7,7 @@ namespace PKHeX.Core;
/// <summary>
/// Unpacks a BinLinkerAccessor generated file container into individual arrays.
/// </summary>
[DebuggerDisplay($"{{{nameof(Identifier)},nq}}[{{{nameof(Length)},nq}}]")]
public readonly ref struct BinLinkerAccessor
{
/// <summary> Backing data object </summary>
@ -42,8 +44,8 @@ public readonly ref struct BinLinkerAccessor
{
var result = new BinLinkerAccessor(data);
#if DEBUG
System.Diagnostics.Debug.Assert(data.Length > 4);
System.Diagnostics.Debug.Assert(identifier[0] == data[0] && identifier[1] == data[1]);
Debug.Assert(data.Length > 4);
Debug.Assert(identifier[0] == data[0] && identifier[1] == data[1]);
#endif
return result;
}

View file

@ -202,17 +202,26 @@ namespace PKHeX.Core
private static readonly ushort[] Arceus_PlateIDs = { 303, 306, 304, 305, 309, 308, 310, 313, 298, 299, 301, 300, 307, 302, 311, 312, 644 };
private static readonly ushort[] Arceus_ZCrystal = { 782, 785, 783, 784, 788, 787, 789, 792, 777, 778, 780, 779, 786, 781, 790, 791, 793 };
public static int GetArceusFormFromHeldItem(int item, int format)
public static int GetArceusFormFromHeldItem(int item, int format) => item switch
{
if (item is >= 777 and <= 793)
return Array.IndexOf(Arceus_ZCrystal, (ushort)item) + 1;
>= 777 and <= 793 => GetArceusFormFromZCrystal(item),
>= 298 and <= 313 or 644 => GetArceusFormFromPlate(item, format),
_ => 0,
};
int form = 0;
if (item is >= 298 and <= 313 or 644)
form = Array.IndexOf(Arceus_PlateIDs, (ushort)item) + 1;
if (format == 4 && form >= 9)
return form + 1; // ??? type Form shifts everything by 1
return form;
private static int GetArceusFormFromZCrystal(int item)
{
return Array.IndexOf(Arceus_ZCrystal, (ushort)item) + 1;
}
private static int GetArceusFormFromPlate(int item, int format)
{
int form = Array.IndexOf(Arceus_PlateIDs, (ushort)item) + 1;
if (format != 4) // No need to consider Curse type
return form;
if (form < 9)
return form;
return form + 1; // ??? type Form shifts everything by 1
}
public static int GetSilvallyFormFromHeldItem(int item)

View file

@ -72,7 +72,8 @@ public static class EntityConverter
private static PKM? ConvertPKM(PKM pk, Type destType, Type srcType, out EntityConverterResult result)
{
if (IsNotTransferable(pk, out result))
result = CheckTransfer(pk);
if (result != Success)
return null;
Debug.WriteLine($"Trying to convert {srcType.Name} to {destType.Name}.");
@ -138,23 +139,15 @@ public static class EntityConverter
/// Checks to see if a PKM is transferable relative to in-game restrictions and <see cref="PKM.Form"/>.
/// </summary>
/// <param name="pk">PKM to convert</param>
/// <param name="result">Comment indicating why the <see cref="PKM"/> is not transferable.</param>
/// <returns>Indication if Not Transferable</returns>
private static bool IsNotTransferable(PKM pk, out EntityConverterResult result)
private static EntityConverterResult CheckTransfer(PKM pk) => pk switch
{
switch (pk)
{
case PK4 { Species: (int)Species.Pichu } pk4 when pk4.Form != 0:
case PK6 { Species: (int)Species.Pikachu } pk6 when pk6.Form != 0:
case PB7 { Species: (int)Species.Pikachu } pika when pika.Form != 0:
case PB7 { Species: (int)Species.Eevee } eevee when eevee.Form != 0:
result = IncompatibleForm;
return true;
default:
result = Success;
return false;
}
}
PK4 { Species: (int)Species.Pichu, Form: not 0 } => IncompatibleForm,
PK6 { Species: (int)Species.Pikachu, Form: not 0 } => IncompatibleForm,
PB7 { Species: (int)Species.Pikachu, Form: not 0 } => IncompatibleForm,
PB7 { Species: (int)Species.Eevee, Form: not 0 } => IncompatibleForm,
_ => Success,
};
/// <summary>
/// Checks if the <see cref="PKM"/> is compatible with the input <see cref="PKM"/>, and makes any necessary modifications to force compatibility.

View file

@ -8,15 +8,8 @@ public static class EffortValues
/// <summary>
/// Gets randomized EVs for a given generation format
/// </summary>
/// <param name="evs">Array containing randomized EVs (H/A/B/S/C/D)</param>
/// <param name="generation">Generation specific formatting option</param>
/// <returns>Array containing randomized EVs (H/A/B/S/C/D)</returns>
public static int[] GetRandom(int generation = PKX.Generation)
{
var evs = new int[6];
SetRandom(evs, generation);
return evs;
}
public static void SetRandom(Span<int> evs, int generation)
{
var rnd = Util.Rand;

View file

@ -17,8 +17,9 @@ public static class EntityFileExtension
/// <returns>Valid <see cref="PKM"/> file extensions.</returns>
public static string[] GetExtensions(int maxGeneration = PKX.Generation)
{
var result = new List<string>();
int min = maxGeneration is <= 2 or >= 7 ? 1 : 3;
int size = maxGeneration - min + 1 + 6;
var result = new List<string>(size);
for (int i = min; i <= maxGeneration; i++)
result.Add($"pk{i}");
@ -47,7 +48,7 @@ public static class EntityFileExtension
/// <returns>Format hint that the file is.</returns>
public static int GetFormatFromExtension(string ext, int prefer)
{
if (string.IsNullOrEmpty(ext))
if (ext.Length == 0)
return prefer;
return GetFormatFromExtension(ext[^1], prefer);
}

View file

@ -1,8 +1,8 @@
using System;
using System.Linq;
using static PKHeX.Core.PokeCrypto;
using static System.Buffers.Binary.BinaryPrimitives;
using static PKHeX.Core.EntityFormatDetected;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;

View file

@ -383,14 +383,6 @@ namespace PKHeX.WinForms.Controls
}
}
private static string ReloadGender(string text, IReadOnlyList<string> genders)
{
var index = EntityGender.GetFromString(text);
if (index >= 2)
return text;
return genders[index];
}
internal void UpdateSprite()
{
if (FieldsLoaded && !forceValidation)
@ -1684,7 +1676,7 @@ namespace PKHeX.WinForms.Controls
else
{
// Shouldn't hit here.
throw new ArgumentException(nameof(sender));
throw new InvalidOperationException();
}
UpdateLegality(skipMoveRepop: true);
}

View file

@ -50,7 +50,7 @@ public static class Wild8aRNGTests
};
var xoro = new Xoroshiro128Plus(s0);
var result = Overworld8aRNG.ApplyDetails(test, param, true, ref xoro);
var (EntitySeed, _) = Overworld8aRNG.ApplyDetails(test, param, true, ref xoro);
test.IV_HP.Should().Be(31);
test.IV_ATK.Should().Be(31);
@ -61,7 +61,7 @@ public static class Wild8aRNGTests
test.AlphaMove.Should().Be((ushort)Move.Flamethrower);
var verify = Overworld8aRNG.Verify(test, result.EntitySeed, param);
var verify = Overworld8aRNG.Verify(test, EntitySeed, param);
verify.Should().BeTrue();
}
}