Continued refactoring

removing null results as indicators of no data (c# 8 sooooon)
This commit is contained in:
Kurt 2019-02-01 23:26:43 -08:00
parent aa022fad40
commit 6ed9f979de
11 changed files with 42 additions and 49 deletions

View file

@ -259,7 +259,7 @@ namespace PKHeX.Core
case 6: return GetMovesLevelUp6(species, form, lvl, version);
case 7: return GetMovesLevelUp7(species, form, lvl, MoveReminder, version);
}
return null;
return Array.Empty<int>();
}
private static bool LearnMovesNew2Disallowed(this PKM pkm) => pkm.Format == 1 || (pkm.Format >= 7 && pkm.VC);

View file

@ -34,9 +34,6 @@ namespace PKHeX.Core
protected byte[] GetData(int Offset, int Length)
{
if (Offset + Length > Data.Length)
return null;
byte[] data = new byte[Length];
Array.Copy(Data, Offset, data, 0, Length);
return data;

View file

@ -306,7 +306,7 @@ namespace PKHeX.Core
private byte[] ReadSaveGameData()
{
if (EntrySelected == -1)
return null; // No entry selected
return Array.Empty<byte>(); // No entry selected
int offset = (DirectoryBlock_Used * BLOCK_SIZE) + (EntrySelected * DENTRY_SIZE);
int FirstBlock = BigEndian.ToUInt16(Data, offset + 0x36);

View file

@ -83,7 +83,7 @@ namespace PKHeX.Core
return new[] {new[] {0x0000, 0xF618, 0xF626}, new[] {0xF700, 0x21A00, 0x21A0E}};
default:
return null;
throw new ArgumentException(nameof(g));
}
}
@ -691,7 +691,7 @@ namespace PKHeX.Core
private int[] MatchMysteryGifts(MysteryGift[] value)
{
if (value == null)
return null;
return Array.Empty<int>();
int[] cardMatch = new int[8];
for (int i = 0; i < 8; i++)
@ -773,7 +773,7 @@ namespace PKHeX.Core
get
{
if (WondercardData < 0 || WondercardFlags < 0)
return null;
return Array.Empty<bool>();
bool[] r = new bool[GiftFlagMax];
for (int i = 0; i < r.Length; i++)
@ -806,7 +806,7 @@ namespace PKHeX.Core
get
{
if (Version != GameVersion.DP)
return null;
return Array.Empty<bool>();
int ofs = WondercardFlags + 0x100; // skip over flags
bool[] active = new bool[GiftCountMax]; // 8 PGT, 3 PCD
@ -848,7 +848,7 @@ namespace PKHeX.Core
return;
var Matches = MatchMysteryGifts(value); // automatically applied
if (Matches == null)
if (Matches.Length == 0)
return;
for (int i = 0; i < 8; i++) // 8 PGT
@ -928,7 +928,7 @@ namespace PKHeX.Core
int FormOffset1 = PokeDex + 4 + (brSize * 4) + 4;
var forms = GetForms(pkm.Species);
if (forms != null)
if (forms.Length > 0)
{
if (pkm.Species == 201) // Unown
{
@ -1028,7 +1028,7 @@ namespace PKHeX.Core
return GetData(FormOffset1 + 4, 0x1C).Select(i => (int)i).ToArray();
}
if (DP)
return null;
return Array.Empty<int>();
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
int FormOffset2 = PokeDexLanguageFlags + 0x1F4;
@ -1040,13 +1040,11 @@ namespace PKHeX.Core
return GetDexFormValues(Data[FormOffset2 + 4], 1, 2);
case 487: // Giratina
return GetDexFormValues(Data[FormOffset2 + 5], 1, 2);
case 172:
if (!HGSS)
return null;
case 172 when HGSS: // Pichu
return GetDexFormValues(Data[FormOffset2 + 6], 2, 3);
}
return null;
return Array.Empty<int>();
}
public void SetForms(int spec, int[] forms)
@ -1102,9 +1100,7 @@ namespace PKHeX.Core
case 487: // Giratina
Data[FormOffset2 + 5] = (byte)SetDexFormValues(forms, 1, 2);
return;
case 172: // Pichu
if (!HGSS)
return;
case 172 when HGSS: // Pichu
Data[FormOffset2 + 6] = (byte)SetDexFormValues(forms, 2, 3);
return;
}

View file

@ -328,7 +328,7 @@ namespace PKHeX.Core
}
}
protected override bool[] MysteryGiftReceivedFlags { get => null; set { } }
protected override bool[] MysteryGiftReceivedFlags { get => Array.Empty<bool>(); set { } }
protected override MysteryGift[] MysteryGiftCards { get => Array.Empty<MysteryGift>(); set { } }
// Trainer Info

View file

@ -1073,7 +1073,7 @@ namespace PKHeX.Core
get
{
if (SUBE < 0 || ORASDEMO)
return null; // no gym data
return Array.Empty<ushort[]>(); // no gym data
const int teamsize = 2 * 6; // 2byte/species, 6species/team
const int size = teamsize * 8; // 8 gyms

View file

@ -1411,7 +1411,7 @@ namespace PKHeX.Core
get
{
if (WondercardData < 0 || WondercardFlags < 0)
return null;
return Array.Empty<bool>();
bool[] r = new bool[(WondercardData-WondercardFlags)*8];
for (int i = 0; i < r.Length; i++)
@ -1442,7 +1442,7 @@ namespace PKHeX.Core
get
{
if (WondercardData < 0)
return null;
return Array.Empty<MysteryGift>();
MysteryGift[] cards = new MysteryGift[GiftCountMax];
for (int i = 0; i < cards.Length; i++)
cards[i] = GetWC7(i);
@ -1466,9 +1466,9 @@ namespace PKHeX.Core
private WC7 GetWC7(int index)
{
if (WondercardData < 0)
return null;
throw new ArgumentException(nameof(WondercardData));
if (index < 0 || index > GiftCountMax)
return null;
throw new ArgumentException(nameof(index));
return new WC7(GetData(WondercardData + (index * WC7.Size), WC7.Size));
}

View file

@ -105,7 +105,7 @@ namespace PKHeX.Core
public bool HasSecretBase => SecretBase > -1;
public bool HasPSS => PSS > -1;
public bool HasOPower => OPower > -1;
public bool HasJPEG => JPEGData != null;
public bool HasJPEG => JPEGData.Length > 0;
public bool HasBox => Box > -1;
public virtual bool HasParty => Party > -1;
public bool HasBattleBox => BattleBox > -1;
@ -116,7 +116,7 @@ namespace PKHeX.Core
public virtual bool HasBoxWallpapers => GetBoxWallpaperOffset(0) > -1;
public virtual bool HasNamableBoxes => HasBoxWallpapers;
public bool HasPokeBlock => ORAS && !ORASDEMO;
public virtual bool HasEvents => EventFlags != null;
public virtual bool HasEvents => EventFlags.Length != 0;
public bool HasLink => (ORAS && !ORASDEMO) || XY;
// Counts
@ -263,7 +263,7 @@ namespace PKHeX.Core
get
{
if (EventFlagMax < 0)
return null;
return Array.Empty<bool>();
bool[] Flags = new bool[EventFlagMax];
for (int i = 0; i < Flags.Length; i++)
@ -287,7 +287,7 @@ namespace PKHeX.Core
get
{
if (EventConstMax < 0)
return null;
return Array.Empty<ushort>();
ushort[] Constants = new ushort[EventConstMax];
for (int i = 0; i < Constants.Length; i++)
@ -371,8 +371,8 @@ namespace PKHeX.Core
protected int OFS_PouchZCrystals { get; set; } = int.MinValue;
// Mystery Gift
protected virtual bool[] MysteryGiftReceivedFlags { get => null; set { } }
protected virtual MysteryGift[] MysteryGiftCards { get => null; set { } }
protected virtual bool[] MysteryGiftReceivedFlags { get => Array.Empty<bool>(); set { } }
protected virtual MysteryGift[] MysteryGiftCards { get => Array.Empty<MysteryGift>(); set { } }
public virtual MysteryGiftAlbum GiftAlbum
{
@ -389,8 +389,8 @@ namespace PKHeX.Core
}
public virtual bool BattleBoxLocked { get => false; set { } }
public virtual string JPEGTitle => null;
public virtual byte[] JPEGData => null;
public virtual string JPEGTitle => string.Empty;
public virtual byte[] JPEGData => Array.Empty<byte>();
public virtual int Country { get => -1; set { } }
public virtual int ConsoleRegion { get => -1; set { } }
public virtual int SubRegion { get => -1; set { } }
@ -450,7 +450,7 @@ namespace PKHeX.Core
// Storage
public virtual int BoxSlotCount => 30;
public virtual int BoxesUnlocked { get => -1; set { } }
public virtual byte[] BoxFlags { get => null; set { } }
public virtual byte[] BoxFlags { get => Array.Empty<byte>(); set { } }
public virtual int CurrentBox { get; set; }
protected int[] TeamSlots = Array.Empty<int>();
protected virtual IList<int>[] SlotPointers => new[] {TeamSlots};

View file

@ -103,18 +103,14 @@ namespace PKHeX.Core
public static string[] GetNulledStringArray(string[] SimpleStringList)
{
try
int len = ToInt32(SimpleStringList.Last().Split(',')[0]) + 1;
string[] newlist = new string[len];
for (int i = 1; i < SimpleStringList.Length; i++)
{
int len = ToInt32(SimpleStringList.Last().Split(',')[0]) + 1;
string[] newlist = new string[len];
for (int i = 1; i < SimpleStringList.Length; i++)
{
var split = SimpleStringList[i].Split(',');
newlist[ToInt32(split[0])] = split[1];
}
return newlist;
var split = SimpleStringList[i].Split(',');
newlist[ToInt32(split[0])] = split[1];
}
catch { return null; }
return newlist;
}
public static byte[] GetBinaryResource(string name)

View file

@ -673,11 +673,15 @@ namespace PKHeX.WinForms.Controls
private void B_JPEG_Click(object sender, EventArgs e)
{
byte[] jpeg = SAV.JPEGData;
if (SAV.JPEGData == null)
{ WinFormsUtil.Alert(MsgSaveJPEGExportFail); return; }
if (SAV.JPEGData.Length == 0)
{
WinFormsUtil.Alert(MsgSaveJPEGExportFail);
return;
}
string filename = SAV.JPEGTitle + "'s picture";
SaveFileDialog sfd = new SaveFileDialog { FileName = filename, Filter = "JPEG|*.jpeg" };
if (sfd.ShowDialog() != DialogResult.OK) return;
var sfd = new SaveFileDialog { FileName = filename, Filter = "JPEG|*.jpeg" };
if (sfd.ShowDialog() != DialogResult.OK)
return;
File.WriteAllBytes(sfd.FileName, jpeg);
}

View file

@ -139,7 +139,7 @@ namespace PKHeX.WinForms
LB_NForm.Items.Clear();
var forms = SAV.GetForms(species);
if (forms == null)
if (forms.Length == 0)
return;
string[] formNames = GetFormNames4Dex(species);