PKHeX/PKHeX.Core/MysteryGifts/DataMysteryGift.cs
Kurt 50b15cd740 Use range/index
More in line with modernizing the codebase with latest c# syntax

improve web-qr decode speed slightly (no linq skiptake)
get money/coin mask without a temporary string (lol performance)
2021-05-14 15:30:55 -07:00

41 lines
1.2 KiB
C#

using System;
namespace PKHeX.Core
{
/// <summary>
/// Mystery Gift backed by serialized fields from ROM/SAV data, rather than observed specifications.
/// </summary>
public abstract class DataMysteryGift : MysteryGift
{
public readonly byte[] Data;
protected DataMysteryGift(byte[] data) => Data = data;
/// <summary>
/// Returns an array for exporting outside the program (to disk, etc).
/// </summary>
public virtual byte[] Write() => Data;
public override int GetHashCode()
{
int hash = 17;
foreach (var b in Data)
hash = (hash * 31) + b;
return hash;
}
/// <summary>
/// Creates a deep copy of the <see cref="MysteryGift"/> object data.
/// </summary>
public override MysteryGift Clone()
{
byte[] data = (byte[])Data.Clone();
var result = GetMysteryGift(data);
if (result == null)
throw new ArgumentException(nameof(MysteryGift));
return result;
}
public override bool Empty => new ReadOnlySpan<byte>(Data).IsRangeEmpty();
}
}