mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +00:00
Split go entities and go storage, rename classes
This commit is contained in:
parent
94b924fdfc
commit
5652e76728
2 changed files with 68 additions and 59 deletions
|
@ -1,70 +1,22 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
public sealed class GoParkEntities : SaveBlock, IEnumerable<GoPKM>
|
||||
{
|
||||
public GoParkEntities(SaveFile sav) : base(sav)
|
||||
{
|
||||
Offset = ((SAV7b)sav).GetBlockOffset(BelugaBlockIndex.GoParkEntities);
|
||||
}
|
||||
|
||||
public const int SlotsPerArea = 50;
|
||||
public const int Areas = 20;
|
||||
public const int Count = SlotsPerArea * Areas; // 1000
|
||||
|
||||
public GoPKM this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
Debug.Assert(index < Count);
|
||||
return GoPKM.FromData(Data, Offset + (GoPKM.SIZE * index));
|
||||
}
|
||||
set
|
||||
{
|
||||
Debug.Assert(index < Count);
|
||||
value.WriteTo(Data, Offset + (GoPKM.SIZE * index));
|
||||
}
|
||||
}
|
||||
|
||||
public GoPKM[] AllEntities
|
||||
{
|
||||
get
|
||||
{
|
||||
var value = new GoPKM[Count];
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
value[i] = this[i];
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
Debug.Assert(value?.Length == Count);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
this[i] = value[i];
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> DumpAll(IReadOnlyList<string> speciesNames) => AllEntities.Select((z, i) => new {Index = i, Entry = z}).Where(z => z.Entry.Species > 0).Select(z => z.Entry.Dump(speciesNames, z.Index));
|
||||
|
||||
public IEnumerator<GoPKM> GetEnumerator() => (IEnumerator<GoPKM>)AllEntities.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => AllEntities.GetEnumerator();
|
||||
}
|
||||
|
||||
public class GoPKM
|
||||
/// <summary>
|
||||
/// Go Park Entity transferred to <see cref="GameVersion.GG"/>.
|
||||
/// </summary>
|
||||
public class GP1
|
||||
{
|
||||
public const int SIZE = 0x1B0;
|
||||
public byte[] Data { get; }
|
||||
public GoPKM() => Data = (byte[])Blank.Clone();
|
||||
public GP1() => Data = (byte[])Blank.Clone();
|
||||
public void WriteTo(byte[] data, int offset) => Data.CopyTo(data, offset);
|
||||
|
||||
public static GoPKM FromData(byte[] data, int offset)
|
||||
public static GP1 FromData(byte[] data, int offset)
|
||||
{
|
||||
var gpkm = new GoPKM();
|
||||
var gpkm = new GP1();
|
||||
Array.Copy(data, offset, gpkm.Data, 0, SIZE);
|
||||
return gpkm;
|
||||
}
|
||||
|
@ -101,7 +53,7 @@ namespace PKHeX.Core
|
|||
public int Gender => Data[0x70] - 1; // M=1, F=2, G=3 ;; shift down by 1.
|
||||
|
||||
public bool Flag => Data[0x72] == 1;
|
||||
public bool Shiny => Data[0x73] == 1;
|
||||
public bool IsShiny => Data[0x73] == 1;
|
||||
|
||||
// https://bulbapedia.bulbagarden.net/wiki/List_of_moves_in_Pok%C3%A9mon_GO
|
||||
public int Move1 => BitConverter.ToInt32(Data, 0x74); // uses Go Indexes
|
||||
|
@ -113,8 +65,10 @@ namespace PKHeX.Core
|
|||
|
||||
public static readonly string[] Genders = {"M", "F", "-"};
|
||||
public string GenderString => (uint) Gender >= Genders.Length ? string.Empty : Genders[Gender];
|
||||
public string ShinyString => Shiny ? "SHINY" : string.Empty;
|
||||
public string ShinyString => IsShiny ? "★ " : string.Empty;
|
||||
public string FileName => $"{ShinyString}{Nickname} lv{Level} - {IV1:00}.{IV2:00}.{IV3:00}, Move1 {Move1}, Move2 {Move2}.gp1";
|
||||
|
||||
public string Dump(IReadOnlyList<string> speciesNames, int index) => $"{index:000} {Nickname} ({speciesNames[Species]} {ShinyString} [{GenderString}]) @ lv{Level} - {IV1:00}/{IV2:00}/{IV3:00}, Move1 {Move1}, Move2 {Move2}, Captured in {GeoCityName} by {Username1}.";
|
||||
|
||||
public string Dump(IReadOnlyList<string> speciesNames, int index) => $"{index:000} {Nickname} ({speciesNames[Species]} {ShinyString}[{GenderString}]) @ lv{Level} - {IV1:00}/{IV2:00}/{IV3:00}, Move1 {Move1}, Move2 {Move2}, Captured in {GeoCityName} by {Username1}.";
|
||||
}
|
||||
}
|
55
PKHeX.Core/Saves/Substructures/Gen7/GoParkStorage.cs
Normal file
55
PKHeX.Core/Saves/Substructures/Gen7/GoParkStorage.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
public sealed class GoParkStorage : SaveBlock, IEnumerable<GP1>
|
||||
{
|
||||
public GoParkStorage(SaveFile sav) : base(sav)
|
||||
{
|
||||
Offset = ((SAV7b)sav).GetBlockOffset(BelugaBlockIndex.GoParkEntities);
|
||||
}
|
||||
|
||||
public const int SlotsPerArea = 50;
|
||||
public const int Areas = 20;
|
||||
public const int Count = SlotsPerArea * Areas; // 1000
|
||||
|
||||
public GP1 this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
Debug.Assert(index < Count);
|
||||
return GP1.FromData(Data, Offset + (GP1.SIZE * index));
|
||||
}
|
||||
set
|
||||
{
|
||||
Debug.Assert(index < Count);
|
||||
value.WriteTo(Data, Offset + (GP1.SIZE * index));
|
||||
}
|
||||
}
|
||||
|
||||
public GP1[] AllEntities
|
||||
{
|
||||
get
|
||||
{
|
||||
var value = new GP1[Count];
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
value[i] = this[i];
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
Debug.Assert(value?.Length == Count);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
this[i] = value[i];
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> DumpAll(IReadOnlyList<string> speciesNames) => AllEntities.Select((z, i) => new {Index = i, Entry = z}).Where(z => z.Entry.Species > 0).Select(z => z.Entry.Dump(speciesNames, z.Index));
|
||||
|
||||
public IEnumerator<GP1> GetEnumerator() => (IEnumerator<GP1>)AllEntities.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => AllEntities.GetEnumerator();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue