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

Deep clone map when (de)normalizing SVs #195

Merged
merged 3 commits into from
Nov 17, 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
8 changes: 7 additions & 1 deletion Quaver.API.Tests/Quaver/TestCaseQua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,30 @@ public void SVNormalization()
var pathDenormalized = $"./Quaver/Resources/{test}-normalized.qua";

var quaDenormalized = Qua.Parse(pathNormalized, false);
var quaDenormalizedDeepClone = quaDenormalized.DeepClone();
var quaNormalized = Qua.Parse(pathDenormalized, false);
var quaNormalizedDeepClone = quaNormalized.DeepClone();

// Check that the normalization gives the correct result.
var quaDenormalizedNormalized = quaDenormalized.WithNormalizedSVs();
Assert.True(quaDenormalized.EqualByValue(quaDenormalizedDeepClone), $"Expected normalization in {test} to not change the original content.");
Assert.True(quaDenormalizedNormalized.EqualByValue(quaNormalized), $"Expected {test} to normalize correctly.");

// Denormalization can move the first SV (it doesn't matter where to put the InitialScrollVelocity SV).
// So check back-and-forth instead of just denormalization.
var quaNormalizedDenormalizedNormalized = quaNormalized.WithDenormalizedSVs().WithNormalizedSVs();
Assert.True(quaNormalizedDenormalizedNormalized.EqualByValue(quaNormalized), $"Expected {test} to remain the same after denormalization and subsequent normalization.");
Assert.True(quaNormalized.EqualByValue(quaNormalizedDeepClone), $"Expected denormalization in {test} to not change the original content.");
Assert.True(quaNormalizedDenormalizedNormalized.EqualByValue(quaNormalizedDeepClone), $"Expected {test} to remain the same after denormalization and subsequent normalization.");

// Check that serializing and parsing the result does not change it.
var bufferDenormalized = Encoding.UTF8.GetBytes(quaDenormalized.Serialize());
var quaDenormalized2 = Qua.Parse(bufferDenormalized, false);
Assert.True(quaDenormalizedDeepClone.EqualByValue(quaDenormalized2), $"Expected {test} denormalized to not change the original content.");
Assert.True(quaDenormalized.EqualByValue(quaDenormalized2), $"Expected {test} denormalized to remain the same after serialization and parsing.");

var bufferNormalized = Encoding.UTF8.GetBytes(quaNormalized.Serialize());
var quaNormalized2 = Qua.Parse(bufferNormalized, false);
Assert.True(quaNormalizedDeepClone.EqualByValue(quaNormalized2), $"Expected {test} normalized to not change the original content.");
Assert.True(quaNormalized.EqualByValue(quaNormalized2), $"Expected {test} to normalized to remain the same after serialization and parsing.");
}
}
Expand Down
6 changes: 2 additions & 4 deletions Quaver.API/Maps/Qua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,7 @@ public void DenormalizeSVs()
/// <returns></returns>
public Qua WithNormalizedSVs()
{
var qua = (Qua)MemberwiseClone();
// Relies on NormalizeSVs not changing anything within the by-reference members (but rather creating a new List).
var qua = this.DeepClone();
qua.NormalizeSVs();
return qua;
}
Expand All @@ -1453,8 +1452,7 @@ public Qua WithNormalizedSVs()
/// <returns></returns>
public Qua WithDenormalizedSVs()
{
var qua = (Qua)MemberwiseClone();
// Relies on DenormalizeSVs not changing anything within the by-reference members (but rather creating a new List).
var qua = this.DeepClone();
qua.DenormalizeSVs();
return qua;
}
Expand Down
2 changes: 1 addition & 1 deletion Quaver.API/Maps/Structures/ScrollGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
/// (<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; }

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