mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 12:53:11 +08:00
Remove duplicate code by making GetDivisorForBeatIndex
method more general
This commit is contained in:
parent
37a796306d
commit
1b32370c6a
@ -154,12 +154,15 @@ namespace osu.Game.Screens.Edit
|
||||
/// </summary>
|
||||
/// <param name="index">The 0-based beat index.</param>
|
||||
/// <param name="beatDivisor">The beat divisor.</param>
|
||||
/// <param name="validDivisors">The list of valid divisors which can be chosen from. Assumes ordered from low to high.</param>
|
||||
/// <returns>The applicable divisor.</returns>
|
||||
public static int GetDivisorForBeatIndex(int index, int beatDivisor)
|
||||
public static int GetDivisorForBeatIndex(int index, int beatDivisor, int[] validDivisors = null)
|
||||
{
|
||||
validDivisors ??= PREDEFINED_DIVISORS;
|
||||
|
||||
int beat = index % beatDivisor;
|
||||
|
||||
foreach (int divisor in PREDEFINED_DIVISORS)
|
||||
foreach (int divisor in validDivisors)
|
||||
{
|
||||
if ((beat * divisor) % beatDivisor == 0)
|
||||
return divisor;
|
||||
|
@ -401,13 +401,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Max();
|
||||
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
|
||||
{
|
||||
int divisor = largestDivisor;
|
||||
// Find lowest divisor that the tick fits into
|
||||
foreach (int validDivisor in beatDivisor.ValidDivisors.Value.Presets)
|
||||
{
|
||||
if (divisor > validDivisor && (tickIndex * validDivisor) % largestDivisor == 0)
|
||||
divisor = validDivisor;
|
||||
}
|
||||
int divisor = BindableBeatDivisor.GetDivisorForBeatIndex(tickIndex, largestDivisor, (int[])beatDivisor.ValidDivisors.Value.Presets);
|
||||
|
||||
bool isSolidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
|
||||
AddInternal(new Tick(isSolidTick, divisor)
|
||||
|
Loading…
Reference in New Issue
Block a user