Penumbra/Penumbra/Meta/Manipulations/GmpManipulation.cs
2023-12-20 16:39:26 +01:00

55 lines
1.3 KiB
C#

using Newtonsoft.Json;
using Penumbra.GameData.Structs;
using Penumbra.Interop.Structs;
using Penumbra.Meta.Files;
namespace Penumbra.Meta.Manipulations;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public readonly struct GmpManipulation : IMetaManipulation<GmpManipulation>
{
public GmpEntry Entry { get; private init; }
public PrimaryId SetId { get; private init; }
[JsonConstructor]
public GmpManipulation(GmpEntry entry, PrimaryId setId)
{
Entry = entry;
SetId = setId;
}
public GmpManipulation Copy(GmpEntry entry)
=> new(entry, SetId);
public override string ToString()
=> $"Gmp - {SetId}";
public bool Equals(GmpManipulation other)
=> SetId == other.SetId;
public override bool Equals(object? obj)
=> obj is GmpManipulation other && Equals(other);
public override int GetHashCode()
=> SetId.GetHashCode();
public int CompareTo(GmpManipulation other)
=> SetId.Id.CompareTo(other.SetId.Id);
public MetaIndex FileIndex()
=> MetaIndex.Gmp;
public bool Apply(ExpandedGmpFile file)
{
var entry = file[SetId];
if (entry == Entry)
return false;
file[SetId] = Entry;
return true;
}
public bool Validate()
// No known conditions.
=> true;
}