Serialization of Pokemon, general fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace PkmnLib.Static;
|
||||
@@ -49,6 +50,16 @@ public record ImmutableStatisticSet<T>
|
||||
SpecialDefense = specialDefense;
|
||||
Speed = speed;
|
||||
}
|
||||
|
||||
public ImmutableStatisticSet(ImmutableStatisticSet<T> set)
|
||||
{
|
||||
Hp = set.Hp;
|
||||
Attack = set.Attack;
|
||||
Defense = set.Defense;
|
||||
SpecialAttack = set.SpecialAttack;
|
||||
SpecialDefense = set.SpecialDefense;
|
||||
Speed = set.Speed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a statistic from the set.
|
||||
@@ -72,7 +83,7 @@ public record ImmutableStatisticSet<T>
|
||||
/// A set of statistics that can be changed.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public record StatisticSet<T> : ImmutableStatisticSet<T>
|
||||
public record StatisticSet<T> : ImmutableStatisticSet<T>, IEnumerable<T>
|
||||
where T : struct
|
||||
{
|
||||
/// <inheritdoc cref="StatisticSet{T}"/>
|
||||
@@ -85,6 +96,10 @@ public record StatisticSet<T> : ImmutableStatisticSet<T>
|
||||
defense, specialAttack, specialDefense, speed)
|
||||
{
|
||||
}
|
||||
|
||||
public StatisticSet(StatisticSet<T> set) : base(set)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper function to add two numerics together.
|
||||
@@ -189,6 +204,23 @@ public record StatisticSet<T> : ImmutableStatisticSet<T>
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
yield return Hp;
|
||||
yield return Attack;
|
||||
yield return Defense;
|
||||
yield return SpecialAttack;
|
||||
yield return SpecialDefense;
|
||||
yield return Speed;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -211,6 +243,10 @@ public abstract record ClampedStatisticSet<T> : StatisticSet<T>
|
||||
SpecialDefense = Clamp(SpecialDefense, Min, Max);
|
||||
Speed = Clamp(Speed, Min, Max);
|
||||
}
|
||||
|
||||
protected ClampedStatisticSet(ClampedStatisticSet<T> set) : base(set)
|
||||
{
|
||||
}
|
||||
|
||||
private static T Clamp(T value, T min, T max)
|
||||
{
|
||||
@@ -304,6 +340,10 @@ public record IndividualValueStatisticSet : ClampedStatisticSet<byte>
|
||||
byte speed) : base(hp, attack, defense, specialAttack, specialDefense, speed)
|
||||
{
|
||||
}
|
||||
|
||||
public IndividualValueStatisticSet(IndividualValueStatisticSet ivs) : base(ivs)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -327,4 +367,8 @@ public record EffortValueStatisticSet : ClampedStatisticSet<byte>
|
||||
byte speed) : base(hp, attack, defense, specialAttack, specialDefense, speed)
|
||||
{
|
||||
}
|
||||
|
||||
public EffortValueStatisticSet(EffortValueStatisticSet evs) : base(evs)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user