More abilities, implemented support for form inheritance
All checks were successful
Build / Build (push) Successful in 49s

This commit is contained in:
2025-06-13 12:24:03 +02:00
parent 6d71de375e
commit 8363b955af
16 changed files with 504 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
@@ -111,11 +112,40 @@ public class SerializedForm
/// </summary>
public bool IsBattleOnly { get; set; }
public string? InheritFrom { get; set; }
/// <summary>
/// Additional data that is not part of the standard form data.
/// </summary>
[JsonExtensionData]
public Dictionary<string, JsonElement>? ExtensionData { get; set; }
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract"),
SuppressMessage("ReSharper", "NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract")]
internal void MakeInheritFrom(SerializedForm other)
{
Abilities ??= other.Abilities.ToArray();
HiddenAbilities ??= other.HiddenAbilities.ToArray();
BaseStats ??= other.BaseStats.Copy();
EVReward ??= other.EVReward.Copy();
Types ??= other.Types.ToArray();
if (Height == 0)
Height = other.Height;
if (Weight == 0)
Weight = other.Weight;
if (BaseExp == 0)
BaseExp = other.BaseExp;
Moves ??= new SerializedMoves();
if (Moves.LevelMoves == null || Moves.LevelMoves.Length == 0)
Moves.LevelMoves = other.Moves.LevelMoves?.ToArray();
if (Moves.EggMoves == null || Moves.EggMoves.Length == 0)
Moves.EggMoves = other.Moves.EggMoves?.ToArray();
if (Moves.TutorMoves == null || Moves.TutorMoves.Length == 0)
Moves.TutorMoves = other.Moves.TutorMoves?.ToArray();
if (Moves.Machine == null || Moves.Machine.Length == 0)
Moves.Machine = other.Moves.Machine?.ToArray();
Flags ??= other.Flags.ToArray();
}
}
/// <summary>
@@ -159,6 +189,17 @@ public record SerializedStats
/// <inheritdoc cref="PkmnLib.Static.ImmutableStatisticSet{T}.Speed"/>
public ushort Speed { get; set; }
public SerializedStats Copy() =>
new()
{
Hp = Hp,
Attack = Attack,
Defense = Defense,
SpecialAttack = SpecialAttack,
SpecialDefense = SpecialDefense,
Speed = Speed,
};
}
/// <summary>

View File

@@ -76,6 +76,20 @@ public static class SpeciesDataLoader
$"Egg cycles for species {id} is invalid: {serialized.EggCycles}. Must be greater than or equal to 0.");
}
foreach (var form in serialized.Formes)
{
if (!string.IsNullOrEmpty(form.Value.InheritFrom))
{
var inheritedForm = serialized.Formes.GetValueOrDefault(form.Value.InheritFrom);
if (inheritedForm == null)
{
throw new InvalidDataException(
$"Form {form.Key} inherits from {form.Value.InheritFrom}, but that form does not exist.");
}
form.Value.MakeInheritFrom(inheritedForm);
}
}
var forms = serialized.Formes.ToDictionary(x => (StringKey)x.Key,
x => DeserializeForm(x.Key, x.Value, typeLibrary));
var evolutions = serialized.Evolutions.Select(DeserializeEvolution).ToList();