Replace party/boxdata get with more performant use

Read directly from the save file.
Batch Editor no longer updates dex, HT details, or updates acquired counts when placing back in the SAV.
This commit is contained in:
Kurt
2023-03-28 12:49:21 -07:00
parent e6ebd20d83
commit 79ca670044
2 changed files with 18 additions and 17 deletions

View File

@@ -41,16 +41,15 @@ public static void AddFromLocalFile(string file, ConcurrentBag<SlotCache> db, IT
private static void AddBoxData(SaveFile sav, ConcurrentBag<SlotCache> db)
{
var bd = sav.BoxData;
var bc = sav.BoxCount;
var sc = sav.BoxSlotCount;
int ctr = 0;
for (int box = 0; box < bc; box++)
{
for (int slot = 0; slot < sc; slot++, ctr++)
for (int slot = 0; slot < sc; slot++)
{
var ident = new SlotInfoBox(box, slot);
var result = new SlotCache(ident, bd[ctr], sav);
var pk = sav.GetBoxSlotAtIndex(box, slot);
var result = new SlotCache(ident, pk, sav);
db.Add(result);
}
}
@@ -58,10 +57,10 @@ private static void AddBoxData(SaveFile sav, ConcurrentBag<SlotCache> db)
private static void AddPartyData(SaveFile sav, ConcurrentBag<SlotCache> db)
{
var pd = sav.PartyData;
for (var index = 0; index < pd.Count; index++)
var count = sav.PartyCount;
for (var index = 0; index < count; index++)
{
var pk = pd[index];
var pk = sav.GetPartySlotAtIndex(index);
if (pk.Species == 0)
continue;
@@ -116,16 +115,15 @@ public static void AddFromLocalFile(string file, ICollection<SlotCache> db, ITra
public static void AddBoxData(SaveFile sav, ICollection<SlotCache> db)
{
var bd = sav.BoxData;
var bc = sav.BoxCount;
var sc = sav.BoxSlotCount;
int ctr = 0;
for (int box = 0; box < bc; box++)
{
for (int slot = 0; slot < sc; slot++, ctr++)
for (int slot = 0; slot < sc; slot++)
{
var ident = new SlotInfoBox(box, slot);
var result = new SlotCache(ident, bd[ctr], sav);
var pk = sav.GetBoxSlotAtIndex(box, slot);
var result = new SlotCache(ident, pk, sav);
db.Add(result);
}
}
@@ -133,10 +131,10 @@ public static void AddBoxData(SaveFile sav, ICollection<SlotCache> db)
public static void AddPartyData(SaveFile sav, ICollection<SlotCache> db)
{
var pd = sav.PartyData;
for (var index = 0; index < pd.Count; index++)
var count = sav.PartyCount;
for (var index = 0; index < count; index++)
{
var pk = pd[index];
var pk = sav.GetPartySlotAtIndex(index);
if (pk.Species == 0)
continue;

View File

@@ -174,18 +174,21 @@ private void RunBatchEditFolder(IReadOnlyCollection<StringInstructionSet> sets,
private void RunBatchEditSaveFile(IReadOnlyCollection<StringInstructionSet> sets, bool boxes = false, bool party = false)
{
var data = new List<SlotCache>();
if (party)
{
var data = new List<SlotCache>(SAV.PartyCount);
SlotInfoLoader.AddPartyData(SAV, data);
process(data);
SAV.PartyData = data.ConvertAll(z => z.Entity);
foreach (var slot in data)
slot.Source.WriteTo(SAV, slot.Entity, PKMImportSetting.Skip);
}
if (boxes)
{
var data = new List<SlotCache>(SAV.SlotCount);
SlotInfoLoader.AddBoxData(SAV, data);
process(data);
SAV.BoxData = data.ConvertAll(z => z.Entity);
foreach (var slot in data)
slot.Source.WriteTo(SAV, slot.Entity, PKMImportSetting.Skip);
}
void process(IList<SlotCache> d)
{