Added public StatValues ctors that take enumerables.

This commit is contained in:
Greg Edwards 2021-07-27 22:40:56 -04:00
parent 133a77d75f
commit 28876be090
5 changed files with 19 additions and 7 deletions

View File

@ -12,9 +12,8 @@ namespace PkmnFoundations.Structures
{
}
protected ByteStatValues(byte[] s) : base(s)
public ByteStatValues(IEnumerable<byte> s) : base(s)
{
}
}
}

View File

@ -12,6 +12,8 @@ namespace PkmnFoundations.Structures
{
}
public IntStatValues(IEnumerable<int> s) : base(s)
{
}
}
}

View File

@ -12,6 +12,14 @@ namespace PkmnFoundations.Structures
{
}
public IvStatValues(IEnumerable<byte> s) : base(s)
{
foreach (byte b in s)
{
if (b > 31) throw new ArgumentOutOfRangeException();
}
}
public IvStatValues(int ivs) : base(new byte[6])
{
for (int x = 0; x < 6; x++)

View File

@ -13,9 +13,8 @@ namespace PkmnFoundations.Structures
}
protected StatValues(T[] s) : base(s)
public StatValues(IEnumerable<T> s) : base(s)
{
if (s.Length != 6) throw new ArgumentException();
}
public T Hp { get { return Stats[0]; } set { Stats[0] = value; } }

View File

@ -7,9 +7,13 @@ namespace PkmnFoundations.Structures
{
public abstract class StatValuesBase<T> where T : struct
{
protected StatValuesBase(T[] s)
protected StatValuesBase(IEnumerable<T> s)
{
Stats = s;
// fail without enumerating if possible
if (s is IList<T> && ((IList<T>)s).Count != 6) throw new ArgumentException("s must have exactly 6 elements.", "s");
var arr = s.ToArray();
if (arr.Length != 6) throw new ArgumentException("s must have exactly 6 elements.", "s");
Stats = arr;
}
protected StatValuesBase(T s0, T s1, T s2, T s3, T s4, T s5)