Minor clean

Resolve some messages
This commit is contained in:
Kurt 2020-11-11 21:01:41 -08:00
parent 915727ed67
commit df5ebd1f54
14 changed files with 88 additions and 152 deletions

View File

@ -61,7 +61,7 @@ private static string GetRegionName(int country, int region, int l)
return INVALID;
if (country >= RegionList.Length)
return INVALID;
var regionNames = RegionList[country] ?? (RegionList[country] = GetRegionList(country));
var regionNames = RegionList[country] ??= GetRegionList(country);
if (region >= regionNames.Length)
return INVALID;
var localized = regionNames[region];

View File

@ -10,28 +10,28 @@ namespace PKHeX.Core
public static class EncounterEvent
{
/// <summary>Event Database for Generation 3</summary>
public static WC3[] MGDB_G3 { get; private set; } = Array.Empty<WC3>();
public static IReadOnlyList<WC3> MGDB_G3 { get; private set; } = Array.Empty<WC3>();
/// <summary>Event Database for Generation 4</summary>
public static PCD[] MGDB_G4 { get; private set; } = Array.Empty<PCD>();
public static IReadOnlyList<PCD> MGDB_G4 { get; private set; } = Array.Empty<PCD>();
/// <summary>Event Database for Generation 5</summary>
public static PGF[] MGDB_G5 { get; private set; } = Array.Empty<PGF>();
public static IReadOnlyList<PGF> MGDB_G5 { get; private set; } = Array.Empty<PGF>();
/// <summary>Event Database for Generation 6</summary>
public static WC6[] MGDB_G6 { get; private set; } = Array.Empty<WC6>();
public static IReadOnlyList<WC6> MGDB_G6 { get; private set; } = Array.Empty<WC6>();
/// <summary>Event Database for Generation 7</summary>
public static WC7[] MGDB_G7 { get; private set; } = Array.Empty<WC7>();
public static IReadOnlyList<WC7> MGDB_G7 { get; private set; } = Array.Empty<WC7>();
/// <summary>Event Database for Generation 7 <see cref="GameVersion.GG"/></summary>
public static WB7[] MGDB_G7GG { get; private set; } = Array.Empty<WB7>();
public static IReadOnlyList<WB7> MGDB_G7GG { get; private set; } = Array.Empty<WB7>();
/// <summary>Event Database for Generation 8</summary>
public static WC8[] MGDB_G8 { get; private set; } = Array.Empty<WC8>();
public static IReadOnlyList<WC8> MGDB_G8 { get; private set; } = Array.Empty<WC8>();
/// <summary>Indicates if the databases are initialized.</summary>
public static bool Initialized => MGDB_G3.Length != 0;
public static bool Initialized => MGDB_G3.Count != 0;
private static HashSet<PCD> GetPCDDB(byte[] bin) => new HashSet<PCD>(ArrayUtil.EnumerateSplit(bin, PCD.Size).Select(d => new PCD(d)));
@ -83,7 +83,7 @@ public static void RefreshMGDB(params string[] paths)
public static IEnumerable<MysteryGift> GetAllEvents(bool sorted = true)
{
var regular = new MysteryGift[][]
var regular = new IReadOnlyList<MysteryGift>[]
{
MGDB_G4,
MGDB_G5,

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace PKHeX.Core
@ -66,61 +67,6 @@ public sealed class PL6
public int BattlePoints { get => BitConverter.ToUInt16(Data, 0x4A1); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4A1); }
public int Pokemiles { get => BitConverter.ToUInt16(Data, 0x4A3); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4A3); }
public uint[] Flags
{
get => new[] { Flags_1, Flags_2, Flags_3, Flags_4, Flags_5, Flags_6 }; set
{
if (value.Length > 0) Flags_1 = value[0];
if (value.Length > 1) Flags_2 = value[1];
if (value.Length > 2) Flags_3 = value[2];
if (value.Length > 3) Flags_4 = value[3];
if (value.Length > 4) Flags_5 = value[4];
if (value.Length > 5) Flags_6 = value[5];
}
}
public PL6_PKM[] Pokes
{
get => new[] { Poke_1, Poke_2, Poke_3, Poke_4, Poke_5, Poke_6 };
set
{
if (value.Length > 0) Poke_1 = value[0];
if (value.Length > 1) Poke_2 = value[1];
if (value.Length > 2) Poke_3 = value[2];
if (value.Length > 3) Poke_4 = value[3];
if (value.Length > 4) Poke_5 = value[4];
if (value.Length > 5) Poke_6 = value[5];
}
}
public int[] Items
{
get => new[] { Item_1, Item_2, Item_3, Item_4, Item_5, Item_6 };
set
{
if (value.Length > 0) Item_1 = value[0];
if (value.Length > 1) Item_2 = value[1];
if (value.Length > 2) Item_3 = value[2];
if (value.Length > 3) Item_4 = value[3];
if (value.Length > 4) Item_5 = value[4];
if (value.Length > 5) Item_6 = value[5];
}
}
public int[] Quantities
{
get => new[] { Quantity_1, Quantity_2, Quantity_3, Quantity_4, Quantity_5, Quantity_6 };
set
{
if (value.Length > 0) Quantity_1 = value[0];
if (value.Length > 1) Quantity_2 = value[1];
if (value.Length > 2) Quantity_3 = value[2];
if (value.Length > 3) Quantity_4 = value[3];
if (value.Length > 4) Quantity_5 = value[4];
if (value.Length > 5) Quantity_6 = value[5];
}
}
}
/// <summary>
@ -224,27 +170,27 @@ public string OT
public int LevelMin => MetLevel;
public int LevelMax => MetLevel;
public int[] Moves
public IReadOnlyList<int> Moves
{
get => new[] { Move1, Move2, Move3, Move4 };
set
{
if (value.Length > 0) Move1 = value[0];
if (value.Length > 1) Move2 = value[1];
if (value.Length > 2) Move3 = value[2];
if (value.Length > 3) Move4 = value[3];
if (value.Count > 0) Move1 = value[0];
if (value.Count > 1) Move2 = value[1];
if (value.Count > 2) Move3 = value[2];
if (value.Count > 3) Move4 = value[3];
}
}
public int[] RelearnMoves
public IReadOnlyList<int> RelearnMoves
{
get => new[] { RelearnMove1, RelearnMove2, RelearnMove3, RelearnMove4 };
set
{
if (value.Length > 0) RelearnMove1 = value[0];
if (value.Length > 1) RelearnMove2 = value[1];
if (value.Length > 2) RelearnMove3 = value[2];
if (value.Length > 3) RelearnMove4 = value[3];
if (value.Count > 0) RelearnMove1 = value[0];
if (value.Count > 1) RelearnMove2 = value[1];
if (value.Count > 2) RelearnMove3 = value[2];
if (value.Count > 3) RelearnMove4 = value[3];
}
}
}

View File

@ -956,7 +956,10 @@ public override ushort[] EventConsts
// Seals
private const byte SealMaxCount = 99;
public byte[] SealCase { get => General.Slice(Seal, (int) Seal4.MAX); set => SetData(General, value, Seal); }
public byte[] GetSealCase() => General.Slice(Seal, (int)Seal4.MAX);
public void SetSealCase(byte[] value) => SetData(General, value, Seal);
public byte GetSealCount(Seal4 id) => General[Seal + (int)id];
public byte SetSealCount(Seal4 id, byte count) => General[Seal + (int)id] = Math.Min(SealMaxCount, count);

View File

@ -190,8 +190,8 @@ public override void SetDaycareHasEgg(int loc, bool hasEgg)
private bool HasJPPEGData => Data[JPEG + 0x54] == 0xFF;
protected override bool[] MysteryGiftReceivedFlags { get => Blocks.MysteryGift.MysteryGiftReceivedFlags; set => Blocks.MysteryGift.MysteryGiftReceivedFlags = value; }
protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.MysteryGift.MysteryGiftCards; set => Blocks.MysteryGift.MysteryGiftCards = value; }
protected override bool[] MysteryGiftReceivedFlags { get => Blocks.MysteryGift.GetReceivedFlags(); set => Blocks.MysteryGift.SetReceivedFlags(value); }
protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.MysteryGift.GetGifts(); set => Blocks.MysteryGift.SetGifts(value); }
public override int CurrentBox { get => Blocks.BoxLayout.CurrentBox; set => Blocks.BoxLayout.CurrentBox = value; }
protected override int GetBoxWallpaperOffset(int box) => Blocks.BoxLayout.GetBoxWallpaperOffset(box);

View File

@ -149,8 +149,8 @@ public override GameVersion Version
}
}
protected override bool[] MysteryGiftReceivedFlags { get => Blocks.MysteryGift.MysteryGiftReceivedFlags; set => Blocks.MysteryGift.MysteryGiftReceivedFlags = value; }
protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.MysteryGift.MysteryGiftCards; set => Blocks.MysteryGift.MysteryGiftCards = value; }
protected override bool[] MysteryGiftReceivedFlags { get => Blocks.MysteryGift.GetReceivedFlags(); set => Blocks.MysteryGift.SetReceivedFlags(value); }
protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.MysteryGift.GetGifts(); set => Blocks.MysteryGift.SetGifts(value); }
public override bool GetCaught(int species) => Blocks.Zukan.GetCaught(species);
public override bool GetSeen(int species) => Blocks.Zukan.GetSeen(species);

View File

@ -169,8 +169,8 @@ public override GameVersion Version
/// <remarks>Flag is Set (true) or not Set (false)</remarks>
public override void SetEventFlag(int flagNumber, bool value) => Blocks.EventWork.SetFlag(flagNumber, value);
protected override bool[] MysteryGiftReceivedFlags { get => Blocks.GiftRecords.Flags; set => Blocks.GiftRecords.Flags = value; }
protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.GiftRecords.Records; set => Blocks.GiftRecords.Records = (WR7[])value; }
protected override bool[] MysteryGiftReceivedFlags { get => Blocks.GiftRecords.GetFlags(); set => Blocks.GiftRecords.SetFlags(value); }
protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.GiftRecords.GetRecords(); set => Blocks.GiftRecords.SetRecords((WR7[])value); }
public int GameSyncIDSize => MyStatus7b.GameSyncIDSize; // 64 bits
public string GameSyncID { get => Blocks.Status.GameSyncID; set => Blocks.Status.GameSyncID = value; }

View File

@ -13,35 +13,31 @@ public sealed class MysteryBlock6 : SaveBlock
public MysteryBlock6(SAV6XY sav, int offset) : base(sav) => Offset = offset;
public MysteryBlock6(SAV6AO sav, int offset) : base(sav) => Offset = offset;
public bool[] MysteryGiftReceivedFlags
public bool[] GetReceivedFlags() => ArrayUtil.GitBitFlagArray(Data, Offset + FlagStart, MaxReceivedFlag);
public void SetReceivedFlags(bool[] value)
{
get => ArrayUtil.GitBitFlagArray(Data, Offset + FlagStart, MaxReceivedFlag);
set
{
if (value.Length != MaxReceivedFlag)
return;
ArrayUtil.SetBitFlagArray(Data, Offset + FlagStart, value);
SAV.Edited = true;
}
if (value.Length != MaxReceivedFlag)
return;
ArrayUtil.SetBitFlagArray(Data, Offset + FlagStart, value);
SAV.Edited = true;
}
public DataMysteryGift[] MysteryGiftCards
public DataMysteryGift[] GetGifts()
{
get
{
var cards = new DataMysteryGift[MaxCardsPresent];
for (int i = 0; i < cards.Length; i++)
cards[i] = GetGift(i);
return cards;
}
set
{
int count = Math.Min(MaxCardsPresent, value.Length);
for (int i = 0; i < count; i++)
SetGift(value[i], i);
for (int i = value.Length; i < MaxCardsPresent; i++)
SetGift(new WC6(), i);
}
var cards = new DataMysteryGift[MaxCardsPresent];
for (int i = 0; i < cards.Length; i++)
cards[i] = GetGift(i);
return cards;
}
public void SetGifts(DataMysteryGift[] value)
{
int count = Math.Min(MaxCardsPresent, value.Length);
for (int i = 0; i < count; i++)
SetGift(value[i], i);
for (int i = value.Length; i < MaxCardsPresent; i++)
SetGift(new WC6(), i);
}
public DataMysteryGift GetGift(int index)

View File

@ -9,11 +9,8 @@ public sealed class Puff6 : SaveBlock
public Puff6(SaveFile SAV, int offset) : base(SAV) => Offset = offset;
public byte[] Puffs
{
get => SAV.GetData(Offset, PuffSlots);
set => SAV.SetData(value, Offset);
}
public byte[] GetPuffs() => SAV.GetData(Offset, PuffSlots);
public void SetPuffs(byte[] value) => SAV.SetData(value, Offset);
public int PuffCount
{

View File

@ -40,20 +40,18 @@ public void SetRecord(WR7 record, int index)
record.Data.CopyTo(Data, ofs);
}
public WR7[] Records
public WR7[] GetRecords()
{
get
{
var arr = new WR7[RecordMax];
for (int i = 0; i < arr.Length; i++)
arr[i] = GetRecord(i);
return arr;
}
set
{
for (int i = 0; i < value.Length; i++)
SetRecord(value[i], i);
}
var arr = new WR7[RecordMax];
for (int i = 0; i < arr.Length; i++)
arr[i] = GetRecord(i);
return arr;
}
public void SetRecords(WR7[] value)
{
for (int i = 0; i < value.Length; i++)
SetRecord(value[i], i);
}
public bool GetFlag(int flag)
@ -73,20 +71,18 @@ public void SetFlag(int flag, bool value)
Data[ofs] &= (byte)~mask;
}
public bool[] Flags
public bool[] GetFlags()
{
get
{
var value = new bool[FlagCountMax];
for (int i = 0; i < value.Length; i++)
value[i] = GetFlag(i);
return value;
}
set
{
for (int i = 0; i < value.Length; i++)
SetFlag(i, value[i]);
}
var value = new bool[FlagCountMax];
for (int i = 0; i < value.Length; i++)
value[i] = GetFlag(i);
return value;
}
public void SetFlags(bool[] value)
{
for (int i = 0; i < value.Length; i++)
SetFlag(i, value[i]);
}
}
}

View File

@ -37,10 +37,8 @@ public void SetEditEnvironment(SaveDataEditor<PictureBox> value)
public bool ModifyPKM { private get; set; }
private bool _hideSecret;
public bool HideSecretDetails { private get => _hideSecret; set => ToggleSecrets(SAV, _hideSecret = value); }
#pragma warning disable CA2213
public ToolStripMenuItem Menu_Redo { get; set; } = null!;
public ToolStripMenuItem Menu_Undo { get; set; } = null!;
#pragma warning restore CS8622
private bool FieldsLoaded;
public IList<PictureBox> SlotPictureBoxes { get; }

View File

@ -88,12 +88,12 @@ private void LoadLinkData()
NUD_Item6.Value = LinkInfo.Quantity_6;
// Pokemon slots
TB_PKM1.Text = GameInfo.Strings.specieslist[LinkInfo.Pokes[0].Species];
TB_PKM2.Text = GameInfo.Strings.specieslist[LinkInfo.Pokes[1].Species];
TB_PKM3.Text = GameInfo.Strings.specieslist[LinkInfo.Pokes[2].Species];
TB_PKM4.Text = GameInfo.Strings.specieslist[LinkInfo.Pokes[3].Species];
TB_PKM5.Text = GameInfo.Strings.specieslist[LinkInfo.Pokes[4].Species];
TB_PKM6.Text = GameInfo.Strings.specieslist[LinkInfo.Pokes[5].Species];
TB_PKM1.Text = GameInfo.Strings.specieslist[LinkInfo.Poke_1.Species];
TB_PKM2.Text = GameInfo.Strings.specieslist[LinkInfo.Poke_2.Species];
TB_PKM3.Text = GameInfo.Strings.specieslist[LinkInfo.Poke_3.Species];
TB_PKM4.Text = GameInfo.Strings.specieslist[LinkInfo.Poke_4.Species];
TB_PKM5.Text = GameInfo.Strings.specieslist[LinkInfo.Poke_5.Species];
TB_PKM6.Text = GameInfo.Strings.specieslist[LinkInfo.Poke_6.Species];
}
}
}

View File

@ -15,7 +15,7 @@ public SAV_Pokepuff(SaveFile sav)
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
SAV = (ISaveBlock6Main)sav;
var puffs = SAV.Puff.Puffs;
var puffs = SAV.Puff.GetPuffs();
Setup(puffs.Length);
LoadPuffs(puffs);
@ -85,19 +85,19 @@ private void B_Cancel_Click(object sender, EventArgs e)
private void B_All_Click(object sender, EventArgs e)
{
SAV.Puff.MaxCheat(ModifierKeys == Keys.Control);
LoadPuffs(SAV.Puff.Puffs);
LoadPuffs(SAV.Puff.GetPuffs());
}
private void B_None_Click(object sender, EventArgs e)
{
SAV.Puff.Reset();
LoadPuffs(SAV.Puff.Puffs);
LoadPuffs(SAV.Puff.GetPuffs());
}
private void B_Sort_Click(object sender, EventArgs e)
{
SAV.Puff.Sort(ModifierKeys == Keys.Control);
LoadPuffs(SAV.Puff.Puffs);
LoadPuffs(SAV.Puff.GetPuffs());
}
private byte[] GetPuffs()
@ -115,7 +115,7 @@ private byte[] GetPuffs()
private void B_Save_Click(object sender, EventArgs e)
{
var puffs = GetPuffs();
SAV.Puff.Puffs = puffs;
SAV.Puff.SetPuffs(puffs);
SAV.Puff.PuffCount = puffs.Length;
Close();
}

View File

@ -98,7 +98,7 @@ public void PIDIVMatchingTest3Event()
var pkRS = new PK3 {PID = 0x38CA4EA0, IVs = new[] {00, 20, 28, 11, 19, 00}, TID = 30317, SID = 00000};
var a_pkRS = MethodFinder.Analyze(pkRS);
Assert.Equal(PIDType.BACD_R_S, a_pkRS.Type);
Assert.True(0x0020 == a_pkRS.OriginSeed, "Unable to match PID to BACD-R shiny spread origin seed");
Assert.True(a_pkRS.OriginSeed == 0x0020, "Unable to match PID to BACD-R shiny spread origin seed");
var gkRS = new PK3 { TID = 30317, SID = 00000 };
PIDGenerator.SetValuesFromSeed(gkRS, PIDType.BACD_R_S, a_pkRS.OriginSeed);