Fix RoleLoadout equality (#28737)
* Fix RoleLoadout equality Knew it was janky but thought SequenceEqual was better than it is so we just do it manually. * Also implement this
This commit is contained in:
@@ -7,8 +7,25 @@ namespace Content.Shared.Preferences.Loadouts;
|
|||||||
/// Specifies the selected prototype and custom data for a loadout.
|
/// Specifies the selected prototype and custom data for a loadout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable, NetSerializable, DataDefinition]
|
[Serializable, NetSerializable, DataDefinition]
|
||||||
public sealed partial class Loadout
|
public sealed partial class Loadout : IEquatable<Loadout>
|
||||||
{
|
{
|
||||||
[DataField]
|
[DataField]
|
||||||
public ProtoId<LoadoutPrototype> Prototype;
|
public ProtoId<LoadoutPrototype> Prototype;
|
||||||
|
|
||||||
|
public bool Equals(Loadout? other)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
return Prototype.Equals(other.Prototype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
return ReferenceEquals(this, obj) || obj is Loadout other && Equals(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Prototype.GetHashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,25 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
|
|||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other)) return false;
|
||||||
if (ReferenceEquals(this, other)) return true;
|
if (ReferenceEquals(this, other)) return true;
|
||||||
return Role.Equals(other.Role) && SelectedLoadouts.SequenceEqual(other.SelectedLoadouts) && Points == other.Points;
|
|
||||||
|
if (!Role.Equals(other.Role) ||
|
||||||
|
SelectedLoadouts.Count != other.SelectedLoadouts.Count ||
|
||||||
|
Points != other.Points)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tried using SequenceEqual but it stinky so.
|
||||||
|
foreach (var (key, value) in SelectedLoadouts)
|
||||||
|
{
|
||||||
|
if (!other.SelectedLoadouts.TryGetValue(key, out var otherValue) ||
|
||||||
|
!otherValue.SequenceEqual(value))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user