mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
Consolidate duplicate logic
Reformat g1/2 evolution data binaries for easy loading precomputed count => no unnecessary allocation/resizing
This commit is contained in:
parent
20f023e619
commit
41e066c562
5 changed files with 34 additions and 89 deletions
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core
|
||||
|
@ -7,53 +8,42 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public sealed class EvolutionSet1 : EvolutionSet
|
||||
{
|
||||
private static EvolutionMethod GetMethod(byte[] data, ref int offset)
|
||||
private static EvolutionMethod GetMethod(byte[] data, int offset)
|
||||
{
|
||||
switch (data[offset])
|
||||
{
|
||||
case 1: // Level
|
||||
var m1 = new EvolutionMethod
|
||||
{
|
||||
Method = 1, // Level Up
|
||||
Level = data[offset + 1],
|
||||
Species = data[offset + 2]
|
||||
};
|
||||
offset += 3;
|
||||
return m1;
|
||||
case 2: // Use Item
|
||||
var m2 = new EvolutionMethod
|
||||
{
|
||||
Method = 8, // Use Item
|
||||
Argument = data[offset + 1],
|
||||
// 1
|
||||
Species = data[offset + 3],
|
||||
};
|
||||
offset += 4;
|
||||
return m2;
|
||||
case 3: // Trade
|
||||
var m3 = new EvolutionMethod
|
||||
{
|
||||
Method = 5, // Trade
|
||||
// 1
|
||||
Species = data[offset + 2]
|
||||
};
|
||||
offset += 3;
|
||||
return m3;
|
||||
}
|
||||
return null;
|
||||
int method = data[offset];
|
||||
int species = data[offset + 1];
|
||||
int arg = data[offset + 2];
|
||||
var obj = new EvolutionMethod {Method = method, Species = species};
|
||||
if (method == 1)
|
||||
obj.Level = arg;
|
||||
else
|
||||
obj.Argument = arg;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static List<EvolutionSet> GetArray(byte[] data, int maxSpecies)
|
||||
private static readonly EvolutionSet1 Blank = new EvolutionSet1 {PossibleEvolutions = Array.Empty<EvolutionMethod>()};
|
||||
|
||||
public static IReadOnlyList<EvolutionSet> GetArray(byte[] data, int maxSpecies)
|
||||
{
|
||||
var evos = new List<EvolutionSet>();
|
||||
int offset = 0;
|
||||
for (int i = 0; i <= maxSpecies; i++)
|
||||
var evos = new EvolutionSet[maxSpecies + 1];
|
||||
int ofs = 0;
|
||||
const int bpe = 3;
|
||||
for (int i = 0; i < evos.Length; i++)
|
||||
{
|
||||
var m = new List<EvolutionMethod>();
|
||||
while (data[offset] != 0)
|
||||
m.Add(GetMethod(data, ref offset));
|
||||
++offset;
|
||||
evos.Add(new EvolutionSet1 { PossibleEvolutions = m.ToArray() });
|
||||
int count = data[ofs];
|
||||
ofs++;
|
||||
if (count == 0)
|
||||
{
|
||||
evos[i] = Blank;
|
||||
continue;
|
||||
}
|
||||
var m = new EvolutionMethod[count];
|
||||
for (int j = 0; j < m.Length; j++)
|
||||
{
|
||||
m[j] = GetMethod(data, ofs);
|
||||
ofs += bpe;
|
||||
}
|
||||
evos[i] = new EvolutionSet1 {PossibleEvolutions = m};
|
||||
}
|
||||
return evos;
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Generation 2 Evolution Branch Entries
|
||||
/// </summary>
|
||||
public sealed class EvolutionSet2 : EvolutionSet
|
||||
{
|
||||
private static EvolutionMethod GetMethod(byte[] data, ref int offset)
|
||||
{
|
||||
int method = data[offset];
|
||||
int arg = data[offset + 1];
|
||||
int species = data[offset + 2];
|
||||
offset += 3;
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case 1: /* Level Up */ return new EvolutionMethod { Method = 1, Species = species, Level = arg };
|
||||
case 2: /* Use Item */ return new EvolutionMethod { Method = 8, Species = species, Argument = arg };
|
||||
case 3: /* Trade */ return new EvolutionMethod { Method = 5, Species = species };
|
||||
case 4: /*Friendship*/ return new EvolutionMethod { Method = 1, Species = species };
|
||||
case 5: /* Stats */
|
||||
// species is currently stat ID, we don't care about evo type as stats can be changed after evo
|
||||
return new EvolutionMethod { Method = 1, Species = data[offset++], Level = arg }; // Tyrogue stats
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<EvolutionSet> GetArray(byte[] data, int maxSpecies)
|
||||
{
|
||||
var evos = new List<EvolutionSet>();
|
||||
int offset = 0;
|
||||
for (int i = 0; i <= maxSpecies; i++)
|
||||
{
|
||||
var m = new List<EvolutionMethod>();
|
||||
while (data[offset] != 0)
|
||||
m.Add(GetMethod(data, ref offset));
|
||||
++offset;
|
||||
evos.Add(new EvolutionSet2 { PossibleEvolutions = m.ToArray() });
|
||||
}
|
||||
return evos;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,8 +90,8 @@ namespace PKHeX.Core
|
|||
{
|
||||
switch (Game)
|
||||
{
|
||||
case GameVersion.Gen1: return EvolutionSet1.GetArray(data[0], MaxSpeciesTree);
|
||||
case GameVersion.Gen2: return EvolutionSet2.GetArray(data[0], MaxSpeciesTree);
|
||||
case GameVersion.Gen1:
|
||||
case GameVersion.Gen2: return EvolutionSet1.GetArray(data[0], MaxSpeciesTree);
|
||||
case GameVersion.Gen3: return EvolutionSet3.GetArray(data[0]);
|
||||
case GameVersion.Gen4: return EvolutionSet4.GetArray(data[0]);
|
||||
case GameVersion.Gen5: return EvolutionSet5.GetArray(data[0]);
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue