PKHeX/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs
Kurt f632aedd15
Encounter Templates: Searching and Creating (#3955)
We implement simple state machine iterators to iterate through every split type encounter array, and more finely control the path we iterate through. And, by using generics, we can have the compiler generate optimized code to avoid virtual calls.

In addition to this, we shift away from the big-5 encounter types and not inherit from an abstract class. This allows for creating a PK* of a specific type and directly writing properties (no virtual calls). Plus we can now fine-tune each encounter type to call specific code, and not have to worry about future game encounter types bothering the generation routines.
2023-08-12 16:01:16 -07:00

52 lines
1.7 KiB
C#

namespace PKHeX.Core;
/// <summary>
/// Simple record containing trainer data
/// </summary>
public sealed record SimpleTrainerInfo : ITrainerInfo, IRegionOrigin
{
public string OT { get; set; } = "PKHeX";
public ushort TID16 { get; set; } = 12345;
public ushort SID16 { get; set; } = 54321;
public int Gender { get; set; }
public int Language { get; set; } = (int)LanguageID.English;
public uint ID32 { get => (uint)(TID16 | (SID16 << 16)); set => (TID16, SID16) = ((ushort)value, (ushort)(value >> 16)); }
public TrainerIDFormat TrainerIDDisplayFormat => this.GetTrainerIDFormat();
// IRegionOrigin for generation 6/7
public byte ConsoleRegion { get; set; } = 1; // North America
public byte Region { get; set; } = 7; // California
public byte Country { get; set; } = 49; // USA
public int Game { get; }
public int Generation { get; init; } = PKX.Generation;
public EntityContext Context { get; init; } = PKX.Context;
public SimpleTrainerInfo(GameVersion game = PKX.Version)
{
Game = (int) game;
SanityCheckRegionOrigin(game);
}
private void SanityCheckRegionOrigin(GameVersion game)
{
if (GameVersion.Gen7b.Contains(game) || game.GetGeneration() >= 8)
this.ClearRegionOrigin();
}
public SimpleTrainerInfo(ITrainerInfo other) : this((GameVersion)other.Game)
{
OT = other.OT;
TID16 = other.TID16;
SID16 = other.SID16;
Gender = other.Gender;
Language = other.Language;
Generation = other.Generation;
Context = other.Context;
if (other is IRegionOrigin r)
r.CopyRegionOrigin(this);
SanityCheckRegionOrigin((GameVersion)Game);
}
}