Consolidate pouch load/set

This commit is contained in:
Kurt 2019-03-30 16:10:14 -07:00
parent db7feaa8eb
commit 609db23dc5
16 changed files with 42 additions and 82 deletions

View file

@ -381,14 +381,11 @@ namespace PKHeX.Core
new InventoryPouchGB(InventoryType.Items, legalItems, 99, Offsets.Items, 20),
new InventoryPouchGB(InventoryType.PCItems, legalItems, 99, Offsets.PCItems, 50)
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
return pouch.LoadAll(Data);
}
set
{
foreach (var p in value)
p.SetPouch(Data);
value.SaveAll(Data);
}
}

View file

@ -435,15 +435,9 @@ namespace PKHeX.Core
new InventoryPouchGB(InventoryType.Balls, LegalBalls, 99, Offsets.PouchBall, 12),
new InventoryPouchGB(InventoryType.PCItems, LegalItems.Concat(LegalKeyItems).Concat(LegalBalls).Concat(LegalTMHMs).ToArray(), 99, Offsets.PouchPC, 50)
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
private readonly byte[] DaycareFlags = new byte[2];

View file

@ -600,15 +600,10 @@ namespace PKHeX.Core
{
if (p.Type != InventoryType.PCItems)
((InventoryPouch3)p).SecurityKey = SecurityKey;
p.GetPouch(Data);
}
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
private int DaycareSlotSize => RS ? SIZE_STORED : SIZE_STORED + 0x3C; // 0x38 mail + 4 exp

View file

@ -392,15 +392,9 @@ namespace PKHeX.Core
new InventoryPouch3GC(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry, 46),
new InventoryPouch3GC(InventoryType.Medicine, LegalCologne, 999, OFS_PouchCologne, 3), // Cologne
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
// Daycare Structure:

View file

@ -337,15 +337,9 @@ namespace PKHeX.Core
new InventoryPouch3GC(InventoryType.Medicine, LegalCologne, 999, OFS_PouchCologne, 3), // Cologne
new InventoryPouch3GC(InventoryType.BattleItems, LegalDisc, 999, OFS_PouchDisc, 60)
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch( Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
// Daycare Structure:

View file

@ -333,15 +333,9 @@ namespace PKHeX.Core
new InventoryPouch4(InventoryType.BattleItems, LegalBattleItems, 999, OFS_BattleItems),
new InventoryPouch4(InventoryType.MailItems, LegalMailItems, 999, OFS_MailItems),
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
// Storage

View file

@ -201,15 +201,9 @@ namespace PKHeX.Core
new InventoryPouch4(InventoryType.Medicine, LegalMedicine, 999, OFS_PouchMedicine),
new InventoryPouch4(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry),
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
// Storage

View file

@ -732,15 +732,9 @@ namespace PKHeX.Core
new InventoryPouch4(InventoryType.Medicine, legalMedicine, 999, OFS_PouchMedicine),
new InventoryPouch4(InventoryType.Berries, Legal.Pouch_Berry_XY, 999, OFS_PouchBerry),
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return pouch.LoadAll(Data);
}
set => value.SaveAll(Data);
}
// Storage

View file

@ -837,15 +837,9 @@ namespace PKHeX.Core
get
{
var bag = GetPouches();
foreach (var p in bag)
p.GetPouch(Data);
return bag;
}
set
{
foreach (var p in value)
p.SetPouch(Data);
return bag.LoadAll(Data);
}
set => value.SaveAll(Data);
}
private InventoryPouch[] GetPouches()

View file

@ -26,17 +26,13 @@ namespace PKHeX.Core
new InventoryPouch7b(InventoryType.ZCrystals, Legal.Pouch_PowerUp_GG, 999, PowerUp, PouchSize7b.PowerUp),
new InventoryPouch7b(InventoryType.Candy, Legal.Pouch_Candy_GG, 999, Candy, PouchSize7b.Candy),
};
foreach (var p in pouch)
p.GetPouch(Data);
return pouch;
return pouch.LoadAll(Data);
}
set
{
foreach (var p in value)
{
((InventoryPouch7b)p).SanitizeCounts();
p.SetPouch(Data);
}
value.SaveAll(Data);
}
}
}

View file

@ -221,4 +221,20 @@ namespace PKHeX.Core
return Math.Min(MaxCount, requestVal);
}
}
public static class InventoryPouchExtensions
{
public static InventoryPouch[] LoadAll(this InventoryPouch[] value, byte[] Data)
{
foreach (var p in value)
p.GetPouch(Data);
return value;
}
public static void SaveAll(this InventoryPouch[] value, byte[] Data)
{
foreach (var p in value)
p.SetPouch(Data);
}
}
}

View file

@ -9,12 +9,11 @@ namespace PKHeX.Core
public InventoryPouch3(InventoryType type, ushort[] legal, int maxcount, int offset, int size)
: base(type, legal, maxcount, offset, size)
{
}
public override void GetPouch(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
var items = new InventoryItem[PouchDataSize];
for (int i = 0; i<items.Length; i++)
{
items[i] = new InventoryItem

View file

@ -11,7 +11,7 @@ namespace PKHeX.Core
public override void GetPouch(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
var items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
{
items[i] = new InventoryItem

View file

@ -7,12 +7,11 @@ namespace PKHeX.Core
public InventoryPouch4(InventoryType type, ushort[] legal, int maxcount, int offset)
: base(type, legal, maxcount, offset)
{
}
public override void GetPouch(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
var items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
{
items[i] = new InventoryItem

View file

@ -15,7 +15,7 @@ namespace PKHeX.Core
public override void GetPouch(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
var items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
{
// 10bit itemID

View file

@ -12,7 +12,7 @@ namespace PKHeX.Core
public override void GetPouch(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
var items = new InventoryItem[PouchDataSize];
if (Type == InventoryType.TMHMs)
{
int slot = 0;
@ -85,7 +85,7 @@ namespace PKHeX.Core
case InventoryType.TMHMs:
foreach (InventoryItem t in Items)
{
if (!LegalItems.Any(it => it == t.Index))
if (LegalItems.All(z => z != t.Index))
continue;
int index = Offset + Array.FindIndex(LegalItems, it => t.Index == it);
Data[index] = (byte)t.Count;