Minor tweaks

no functional change
This commit is contained in:
Kurt 2025-08-22 16:32:25 -05:00
parent 5beabb2020
commit dd5d6a4e39
14 changed files with 54 additions and 23 deletions

View File

@ -86,7 +86,7 @@ private void SanitizeResult(BattleTemplateLocalization localization)
Form = ShowdownParsing.GetFormFromString(FormName, localization.Strings, Species, Context);
// Handle edge case with fixed-gender forms.
if (Species is (int)Meowstic or (int)Indeedee or (int)Basculegion or (int)Oinkologne)
if (SpeciesCategory.IsFormGenderSpecific(Species))
ReviseGenderedForms();
}

View File

@ -15,7 +15,7 @@ public void LoadBox(int box)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual((uint)box, (uint)SAV.BoxCount);
SAV.AddBoxData(CurrentContents, box, 0);
SAV.GetBoxData(CurrentContents, box, 0);
CurrentBox = box;
}
@ -42,13 +42,29 @@ public string BoxName
set => (SAV as IBoxDetailName)?.SetBoxName(CurrentBox, value);
}
public int MoveLeft(bool max = false)
/// <summary>
/// Mimics a box viewer Left-Arrow navigation, adjusting to view the previous (n-1) box.
/// </summary>
/// <remarks>
/// If the new index under-flows the box count, it wraps around to the last box.
/// </remarks>
/// <param name="min">Forces the box to the first box in the save, regardless of current box.</param>
/// <returns>Box index that was loaded.</returns>
public int MoveLeft(bool min = false)
{
int newBox = max ? 0 : (CurrentBox + SAV.BoxCount - 1) % SAV.BoxCount;
int newBox = min ? 0 : (CurrentBox + SAV.BoxCount - 1) % SAV.BoxCount;
LoadBox(newBox);
return newBox;
}
/// <summary>
/// Mimics a box viewer Right-Arrow navigation, adjusting to view the next (n+1) box.
/// </summary>
/// <remarks>
/// If the new index over-flows the box count, it wraps around to the first box.
/// </remarks>
/// <param name="max">Forces the box to the last box in the save, regardless of current box.</param>
/// <returns>Box index that was loaded.</returns>
public int MoveRight(bool max = false)
{
int newBox = max ? SAV.BoxCount - 1 : (CurrentBox + 1) % SAV.BoxCount;

View File

@ -93,6 +93,9 @@ private bool DeleteSlot(ISlotInfo slot)
return WriteSlot(slot, pk, SlotTouchType.Delete, settings);
}
/// <summary>
/// Undo the last change made to a slot.
/// </summary>
public void Undo()
{
if (!Changelog.CanUndo)
@ -101,6 +104,9 @@ public void Undo()
NotifySlotChanged(slot, SlotTouchType.Delete, slot.Read(SAV));
}
/// <summary>
/// Redo the last undone change made to a slot.
/// </summary>
public void Redo()
{
if (!Changelog.CanRedo)

View File

@ -78,7 +78,7 @@ internal static class Encounters3Colo
new(24, 06000, Gligar) { Species = 207, Level = 43, Moves = new(185,028,040,163), Location = 133 }, // Gligar: Hunter Frena @ Snagem Hideout
new(25, 06000, First) { Species = 234, Level = 43, Moves = new(310,095,043,036), Location = 058 }, // Stantler: Chaser Liaks @ The Under Subway
new(25, 06000, First) { Species = 234, Level = 43, Moves = new(310,095,043,036), Location = 133 }, // Stantler: Chaser Liaks @ Snagem Hideout
new(25, 06000, First) { Species = 221, Level = 43, Moves = new(203,316,091,059), Location = 058 }, // Piloswine: Bodybuilder Lonia @ The Under Subway
new(26, 06000, First) { Species = 221, Level = 43, Moves = new(203,316,091,059), Location = 058 }, // Piloswine: Bodybuilder Lonia @ The Under Subway
new(26, 06000, First) { Species = 221, Level = 43, Moves = new(203,316,091,059), Location = 134 }, // Piloswine: Bodybuilder Lonia @ Snagem Hideout
new(27, 06000, First) { Species = 215, Level = 43, Moves = new(185,103,154,196), Location = 058 }, // Sneasel: Rider Nelis @ The Under Subway
new(27, 06000, First) { Species = 215, Level = 43, Moves = new(185,103,154,196), Location = 134 }, // Sneasel: Rider Nelis @ Snagem Hideout

View File

@ -40,7 +40,9 @@ private static GameVersion GetOtherGamePair(GameVersion version)
// 26 -> 24 (AS -> X)
// 27 -> 25 (OR -> Y)
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
#pragma warning disable RCS1130, RCS1257 // Bitwise operation on enum without Flags attribute.
return version ^ (GameVersion)2;
#pragma warning restore
}
private static EncounterEgg6 CreateEggEncounter(ushort species, byte form, GameVersion version)

View File

@ -119,9 +119,9 @@ private static GameVersion GetOtherGamePair(GameVersion version)
// 32 -> 30 (US -> SN)
// 33 -> 31 (UM -> MN)
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
#pragma warning disable RCS1130 // Bitwise operation on enum without Flags attribute.
#pragma warning disable RCS1130, RCS1257 // Bitwise operation on enum without Flags attribute.
return version ^ (GameVersion)0b111110;
#pragma warning restore RCS1130 // Bitwise operation on enum without Flags attribute.
#pragma warning restore
}
private static EncounterEgg7 CreateEggEncounter(ushort species, byte form, GameVersion version)

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
@ -15,7 +16,7 @@ public static class EvolutionSet
/// </summary>
/// <param name="data">Container data to unpack.</param>
/// <param name="levelUp">Level up amount required to trigger a level up evolution. Is 0 for games like <see cref="GameVersion.PLA"/> which can trigger manually when satisfied.</param>
public static EvolutionMethod[][] GetArray(BinLinkerAccessor16 data, byte levelUp = 1)
public static EvolutionMethod[][] GetArray(BinLinkerAccessor16 data, [ConstantExpected] byte levelUp = 1)
{
var result = new EvolutionMethod[data.Length][];
for (int i = 0; i < result.Length; i++)
@ -23,7 +24,7 @@ public static EvolutionMethod[][] GetArray(BinLinkerAccessor16 data, byte levelU
return result;
}
private static EvolutionMethod[] GetEntry(ReadOnlySpan<byte> data, byte levelUp)
private static EvolutionMethod[] GetEntry(ReadOnlySpan<byte> data, [ConstantExpected] byte levelUp)
{
if (data.Length == 0)
return [];
@ -34,7 +35,7 @@ private static EvolutionMethod[] GetEntry(ReadOnlySpan<byte> data, byte levelUp)
return result;
}
private static EvolutionMethod GetMethod(ReadOnlySpan<byte> entry, byte levelUp)
private static EvolutionMethod GetMethod(ReadOnlySpan<byte> entry, [ConstantExpected] byte levelUp)
{
var type = (EvolutionType)entry[0];
var arg = ReadUInt16LittleEndian(entry[2..]);

View File

@ -25,14 +25,15 @@ namespace PKHeX.Core;
/// <inheritdoc cref="Insert(LeadSeed,TEnc)"/>
private void Insert(LeadEncounter<TEnc> toInsert)
{
for (int i = 0; i < List.Count; i++)
var list = List;
for (int i = 0; i < list.Count; i++)
{
if (!toInsert.IsBetterThan(List[i]))
if (!toInsert.IsBetterThan(list[i]))
continue;
List.Insert(i, toInsert);
list.Insert(i, toInsert);
return;
}
List.Add(toInsert);
list.Add(toInsert);
}
}

View File

@ -13,7 +13,7 @@ public static class Encounter9RNG
/// </summary>
/// <returns>True if the generated data matches the <see cref="criteria"/>.</returns>
public static bool TryApply32<TEnc>(this TEnc enc, PK9 pk, in ulong init, in GenerateParam9 param, in EncounterCriteria criteria)
where TEnc : IEncounterTemplate, ITeraRaid9
where TEnc : IEncounterTemplate, ITeraRaid9
{
const int maxCtr = 100_000;
var rand = new Xoroshiro128Plus(init);

View File

@ -155,7 +155,7 @@ private void CheckHandlingTrainerEquals(LegalityAnalysis data, PKM pk, ITrainerI
private static bool IsUntradeableEncounter(IEncounterTemplate enc) => enc switch
{
EncounterStatic7b { Location: 28 } => true, // LGP/E Starter
EncounterStatic9 { Species: 998 or 999, Level: 68 } => true, // S/V Ride legend
EncounterStatic9 { StarterBoxLegend: true } => true, // S/V Ride legend
_ => false,
};

View File

@ -149,7 +149,7 @@ public static int SetStringUnicode(ReadOnlySpan<char> value, Span<byte> destBuff
private const ushort Null = 0x0000;
private const char NullChar = (char)Null;
private const char VariableChar = '\xFFFF';
private const char ProportionalChar = '\x0013';
private const char PokemonNameChar = '\x0015';

View File

@ -424,7 +424,7 @@ public IList<PKM> BoxData
{
PKM[] data = new PKM[BoxCount * BoxSlotCount];
for (int box = 0; box < BoxCount; box++)
AddBoxData(data, box, box * BoxSlotCount);
GetBoxData(data, box, box * BoxSlotCount);
return data;
}
set
@ -454,11 +454,17 @@ public int SetBoxData(IList<PKM> value, int box, int index = 0)
public PKM[] GetBoxData(int box)
{
var data = new PKM[BoxSlotCount];
AddBoxData(data, box, 0);
GetBoxData(data, box, 0);
return data;
}
public void AddBoxData(IList<PKM> data, int box, int index)
/// <summary>
/// Populates the specified list with data from a specific box starting at the given index.
/// </summary>
/// <param name="data">The list to populate with box data. The list must have sufficient capacity to hold the data.</param>
/// <param name="box">The zero-based index of the box to retrieve data from.</param>
/// <param name="index">The starting index in the <paramref name="data"/> list where the box data will be placed.</param>
public void GetBoxData(IList<PKM> data, int box, int index)
{
for (int slot = 0; slot < BoxSlotCount; slot++)
{

View File

@ -119,7 +119,7 @@ private List<ComboItem> GetTrainerTitles()
{
if (counts[titles1[i]] > 1)
{
var model = CharacterStyles[i / (titles1.Length / 6) + 1];
var model = CharacterStyles[(i / (titles1.Length / 6) + 1)];
titles1[i] += $" ({model})";
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Core;
@ -234,7 +233,7 @@ private void SetUGScores()
private static string[] SanitizeList(string[] inputlist)
{
string[] listSorted = inputlist.Where(x => !string.IsNullOrEmpty(x)).ToArray();
string[] listSorted = Array.FindAll(inputlist, x => !string.IsNullOrEmpty(x));
Array.Sort(listSorted);
return listSorted;