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

Add Scroll Speed Factor #193

Merged
merged 2 commits into from
Nov 5, 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
21 changes: 21 additions & 0 deletions Quaver.API/Maps/Qua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ public void Sort()
SortSoundEffects();
SortTimingPoints();
SortSliderVelocities();
SortScrollSpeedFactors();
}

/// <summary>
Expand Down Expand Up @@ -630,6 +631,14 @@ public TimingPointInfo GetTimingPointAt(double time)
public SliderVelocityInfo GetScrollVelocityAt(double time, string timingGroupId = DefaultScrollGroupId) =>
((ScrollGroup)TimingGroups[timingGroupId]).GetScrollVelocityAt(time);

/// <summary>
/// Gets a scroll velocity at a particular time in the map
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public ScrollSpeedFactorInfo GetScrollSpeedFactorAt(double time, string timingGroupId = DefaultScrollGroupId) =>
((ScrollGroup)TimingGroups[timingGroupId]).GetScrollSpeedFactorAt(time);

/// <summary>
/// Finds the length of a timing point.
/// </summary>
Expand Down Expand Up @@ -1019,6 +1028,18 @@ public void MirrorHitObjects()
/// </summary>
public void SortBookmarks() => Bookmarks.HybridSort();

/// <summary>
/// </summary>
public void SortScrollSpeedFactors()
{
foreach (var (_, timingGroup) in TimingGroups)
{
if (!(timingGroup is ScrollGroup scrollGroup))
continue;
scrollGroup.ScrollSpeedFactors.HybridSort();
}
}

/// <summary>
/// </summary>
public void SortHitObjects() => HitObjects.HybridSort();
Expand Down
14 changes: 13 additions & 1 deletion Quaver.API/Maps/Structures/ScrollGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +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 List<SliderVelocityInfo> ScrollVelocities { get; [MoonSharpHidden] set; } =
new List<SliderVelocityInfo>();

/// <summary>
/// Scroll Speed Factor .qua data
/// </summary>
public List<ScrollSpeedFactorInfo> ScrollSpeedFactors { get; [MoonSharpHidden] set; } =
new List<ScrollSpeedFactorInfo>();

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

public ScrollSpeedFactorInfo GetScrollSpeedFactorAt(double time)
{
return ScrollSpeedFactors.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);
ScrollVelocities.SequenceEqual(other.ScrollVelocities, SliderVelocityInfo.ByValueComparer) &&
ScrollSpeedFactors.SequenceEqual(other.ScrollSpeedFactors, ScrollSpeedFactorInfo.ByValueComparer);
}

/// <summary>
Expand Down
107 changes: 107 additions & 0 deletions Quaver.API/Maps/Structures/ScrollSpeedFactorInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Text;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using YamlDotNet.Serialization;

namespace Quaver.API.Maps.Structures
{
/// <summary>
/// ScrollSpeedFactors section of the .qua
/// </summary>
[Serializable]
[MoonSharpUserData]
public class ScrollSpeedFactorInfo : IStartTime
{
/// <summary>
/// The time in milliseconds at which the scroll speed factor will be exactly <see cref="Multiplier"/>
/// </summary>
public float StartTime { get; [MoonSharpHidden] set; }

/// <summary>
/// The multiplier given to the scroll speed.
/// It will be lerped to the next scroll speed factor like keyframes, unless this is the last factor change.
/// </summary>
public float Multiplier { get; [MoonSharpHidden] set; }

/// <summary>
/// Returns if the SSF is allowed to be edited in lua scripts
/// </summary>
[YamlIgnore]
public bool IsEditableInLuaScript
{
get;
[MoonSharpVisible(false)]
set;
}

/// <summary>
/// Sets the start time of the SSF.
/// FOR USE IN LUA SCRIPTS ONLY.
/// </summary>
/// <param name="time"></param>
/// <exception cref="InvalidOperationException"></exception>
public void SetStartTime(float time)
{
ThrowUneditableException();
StartTime = time;
}

/// <summary>
/// Sets the multiplier of the SSF.
/// FOR USE IN LUA SCRIPTS ONLY.
/// </summary>
/// <param name="multiplier"></param>
/// <exception cref="InvalidOperationException"></exception>
public void SetMultiplier(float multiplier)
{
ThrowUneditableException();
Multiplier = multiplier;
}

/// <summary>
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
private void ThrowUneditableException()
{
if (!IsEditableInLuaScript)
throw new InvalidOperationException("Value is not allowed to be edited in lua scripts.");
}

private sealed class StartTimeRelationalComparer : IComparer<ScrollSpeedFactorInfo>
{
public int Compare(ScrollSpeedFactorInfo x, ScrollSpeedFactorInfo y)
{
if (ReferenceEquals(x, y)) return 0;
if (ReferenceEquals(null, y)) return 1;
if (ReferenceEquals(null, x)) return -1;
return x.StartTime.CompareTo(y.StartTime);
}
}

public static IComparer<ScrollSpeedFactorInfo> StartTimeComparer { get; } = new StartTimeRelationalComparer();

/// <summary>
/// By-value comparer, auto-generated by Rider.
/// </summary>
private sealed class ByValueEqualityComparer : IEqualityComparer<ScrollSpeedFactorInfo>
{
public bool Equals(ScrollSpeedFactorInfo x, ScrollSpeedFactorInfo y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.StartTime.Equals(y.StartTime) && x.Multiplier.Equals(y.Multiplier);
}

public int GetHashCode(ScrollSpeedFactorInfo obj)
{
return HashCode.Combine(obj.StartTime, obj.Multiplier);
}
}

public static IEqualityComparer<ScrollSpeedFactorInfo> ByValueComparer { get; } = new ByValueEqualityComparer();
}
}
Loading