2021-07-29 02:28:56 +00:00
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public static class EntityFileNamer
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Object that converts the <see cref="PKM"/> data into a <see cref="string"/> file name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IFileNamer<PKM> Namer { get; set; } = new DefaultEntityNamer();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the file name (without extension) for the input <see cref="pk"/> data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Input entity to create a file name for.</param>
|
|
|
|
|
/// <returns>File name for the <see cref="pk"/> data</returns>
|
|
|
|
|
public static string GetName(PKM pk) => Namer.GetName(pk);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 07:01:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// PKHeX's default <see cref="PKM"/> file naming logic.
|
|
|
|
|
/// </summary>
|
2021-07-29 02:28:56 +00:00
|
|
|
|
public sealed class DefaultEntityNamer : IFileNamer<PKM>
|
|
|
|
|
{
|
|
|
|
|
public string GetName(PKM obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj is GBPKM gb)
|
|
|
|
|
return GetGBPKM(gb);
|
|
|
|
|
return GetRegular(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetRegular(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
string form = pk.Form > 0 ? $"-{pk.Form:00}" : string.Empty;
|
|
|
|
|
string star = pk.IsShiny ? " ★" : string.Empty;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
var chk = pk is ISanityChecksum s ? s.Checksum : PokeCrypto.GetCHK(pk.Data, pk.SIZE_STORED);
|
|
|
|
|
return $"{pk.Species:000}{form}{star} - {pk.Nickname} - {chk:X4}{pk.EncryptionConstant:X8}";
|
2021-07-29 02:28:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetGBPKM(GBPKM gb)
|
|
|
|
|
{
|
|
|
|
|
string form = gb.Form > 0 ? $"-{gb.Form:00}" : string.Empty;
|
|
|
|
|
string star = gb.IsShiny ? " ★" : string.Empty;
|
|
|
|
|
var raw = gb switch
|
|
|
|
|
{
|
|
|
|
|
PK1 pk1 => new PokeList1(pk1).Write(),
|
|
|
|
|
PK2 pk2 => new PokeList2(pk2).Write(),
|
2021-08-20 20:49:20 +00:00
|
|
|
|
_ => gb.Data,
|
2021-07-29 02:28:56 +00:00
|
|
|
|
};
|
|
|
|
|
var checksum = Checksums.CRC16_CCITT(raw);
|
|
|
|
|
return $"{gb.Species:000}{form}{star} - {gb.Nickname} - {checksum:X4}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 07:01:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Exposes a method to get a file name (no extension) for the type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">Type that the implementer can create a file name for.</typeparam>
|
2021-07-29 02:28:56 +00:00
|
|
|
|
public interface IFileNamer<in T>
|
|
|
|
|
{
|
|
|
|
|
string GetName(T obj);
|
|
|
|
|
}
|
|
|
|
|
}
|