Move SAV box sorting to class

This commit is contained in:
Kurt
2015-10-24 12:31:29 -07:00
parent 775dc74287
commit 1b514bc84f
2 changed files with 24 additions and 25 deletions

View File

@@ -439,5 +439,29 @@ public void setParty()
if (battlemem == 0)
BattleBoxLocked = false;
}
public void sortBoxes()
{
const int len = 31 * 30; // amount of pk6's in boxes
// Fetch encrypted box data
byte[][] bdata = new byte[len][];
for (int i = 0; i < len; i++)
bdata[i] = getData(Box + i * PK6.SIZE_STORED, PK6.SIZE_STORED);
// Sorting Method: Data will sort empty slots to the end, then from the filled slots eggs will be last, then species will be sorted.
var query = from i in bdata
let p = new PK6(decryptArray(i))
orderby
p.Species == 0 ascending,
p.IsEgg ascending,
p.Species ascending,
p.IsNicknamed ascending
select i;
byte[][] sorted = query.ToArray();
// Write data back
for (int i = 0; i < len; i++)
setData(sorted[i], Box + i * PK6.SIZE_STORED);
}
}
}

View File

@@ -2812,31 +2812,6 @@ private void getBox(object sender, EventArgs e)
{
setPKXBoxes();
}
private void sortBoxes()
{
const int len = 31*30; // amount of pk6's in boxes
// Fetch encrypted box data
byte[][] bdata = new byte[len][];
for (int i = 0; i < len; i++)
bdata[i] = SAV.getData(SAV.Box + i * PK6.SIZE_STORED, PK6.SIZE_STORED);
// Sorting Method: Data will sort empty slots to the end, then from the filled slots eggs will be last, then species will be sorted.
var query = from i in bdata
let p = new PK6(PKX.decryptArray(i)) orderby
p.Species == 0 ascending,
p.IsEgg ascending,
p.Species ascending,
p.IsNicknamed ascending
select i;
byte[][] sorted = query.ToArray();
// Write data back
for (int i = 0; i < len; i++)
SAV.setData(sorted[i], SAV.Box + i * PK6.SIZE_STORED);
setPKXBoxes();
}
private int DaycareSlot;
private void switchDaycare(object sender, EventArgs e)