Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare Qua.TimingGroups properly #190

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Quaver.API.Tests/Quaver/TestCaseQua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ public void StableSorting()
Assert.Equal(unsorted.Bookmarks, sorted.Bookmarks, BookmarkInfo.ByValueComparer);
}

[Fact]
public void TimingGroupsComparison()
{
var q1 = new Qua();
var q2 = new Qua();
Assert.True(q1.EqualByValue(q2));

q2.TimingGroups["a"] = new ScrollGroup();
Assert.False(q1.EqualByValue(q2));

q1.TimingGroups["a"] = new ScrollGroup();
Assert.True(q1.EqualByValue(q2));

((ScrollGroup)q2.TimingGroups["a"]).ScrollVelocities.Add(new SliderVelocityInfo {Multiplier = 2});
Assert.False(q1.EqualByValue(q2));

((ScrollGroup)q1.TimingGroups["a"]).ScrollVelocities.Add(new SliderVelocityInfo {Multiplier = 2});
Assert.True(q1.EqualByValue(q2));
}

[Fact]
public void SVNormalization()
{
Expand Down
15 changes: 14 additions & 1 deletion Quaver.API/Maps/Qua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public bool EqualByValue(Qua other) =>
TimingPoints.SequenceEqual(other.TimingPoints, TimingPointInfo.ByValueComparer) &&
SliderVelocities.SequenceEqual(other.SliderVelocities, SliderVelocityInfo.ByValueComparer) &&
InitialScrollVelocity == other.InitialScrollVelocity &&
TimingGroups.SequenceEqual(other.TimingGroups) &&
CompareTimingGroups(other.TimingGroups) &&
BPMDoesNotAffectScrollVelocity == other.BPMDoesNotAffectScrollVelocity &&
LegacyLNRendering == other.LegacyLNRendering &&
HasScratchKey == other.HasScratchKey &&
Expand All @@ -270,6 +270,19 @@ public bool EqualByValue(Qua other) =>
Bookmarks.SequenceEqual(other.Bookmarks, BookmarkInfo.ByValueComparer) &&
RandomizeModifierSeed == other.RandomizeModifierSeed;

private bool CompareTimingGroups(Dictionary<string, TimingGroup> other)
{
if (TimingGroups == null || other == null || TimingGroups.Count != other.Count)
return false;
foreach (var (key, value) in TimingGroups)
{
if (!other.TryGetValue(key, out var otherGroup) || !otherGroup.Equals(value))
return false;
}

return true;
}

private static IDeserializer Deserializer =>
new DeserializerBuilder()
.IgnoreUnmatchedProperties()
Expand Down
36 changes: 26 additions & 10 deletions Quaver.API/Maps/Structures/ScrollGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using MoonSharp.Interpreter;
using Quaver.API.Helpers;
using YamlDotNet.Serialization;
Expand All @@ -11,23 +12,38 @@
/// (<see cref="Qua.SliderVelocities"/>)
/// </summary>
[MoonSharpUserData]
public class ScrollGroup : TimingGroup

Check warning on line 15 in Quaver.API/Maps/Structures/ScrollGroup.cs

View workflow job for this annotation

GitHub Actions / build

'ScrollGroup' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 15 in Quaver.API/Maps/Structures/ScrollGroup.cs

View workflow job for this annotation

GitHub Actions / build

'ScrollGroup' overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
public float InitialScrollVelocity
{
get;
[MoonSharpHidden] set;
} = 1;
public float InitialScrollVelocity { get; [MoonSharpHidden] set; } = 1;

public List<SliderVelocityInfo> ScrollVelocities
{
get;
[MoonSharpHidden] set;
} = new List<SliderVelocityInfo>();
public List<SliderVelocityInfo> ScrollVelocities { get; [MoonSharpHidden] set; } =
new List<SliderVelocityInfo>();

public SliderVelocityInfo GetScrollVelocityAt(double time)
{
return ScrollVelocities.AtTime((float)time);
}

/// <summary>
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
protected bool Equals(ScrollGroup other)
{
return base.Equals(other) && InitialScrollVelocity.Equals(other.InitialScrollVelocity) &&
ScrollVelocities.SequenceEqual(other.ScrollVelocities, SliderVelocityInfo.ByValueComparer);
}

/// <summary>
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((ScrollGroup)obj);
}
}
}
21 changes: 21 additions & 0 deletions Quaver.API/Maps/Structures/TimingGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/// to the <see cref="Id"/> of the desired <see cref="TimingGroup"/>.
/// </summary>
[MoonSharpUserData]
public abstract class TimingGroup

Check warning on line 19 in Quaver.API/Maps/Structures/TimingGroup.cs

View workflow job for this annotation

GitHub Actions / build

'TimingGroup' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 19 in Quaver.API/Maps/Structures/TimingGroup.cs

View workflow job for this annotation

GitHub Actions / build

'TimingGroup' overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
/// <summary>
/// The color of the layer (default is white)
Expand All @@ -35,5 +35,26 @@
byte.TryParse(tb, out var b)
? Color.FromArgb(r, g, b)
: Color.White;

/// <summary>
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
protected bool Equals(TimingGroup other)
{
return ColorRgb == other.ColorRgb;
}

/// <summary>
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((TimingGroup)obj);
}
}
}
Loading