mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:02:57 +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>
|
/// </summary>
|
||||||
/// <param name="index">The 0-based beat index.</param>
|
/// <param name="index">The 0-based beat index.</param>
|
||||||
/// <param name="beatDivisor">The beat divisor.</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>
|
/// <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;
|
int beat = index % beatDivisor;
|
||||||
|
|
||||||
foreach (int divisor in PREDEFINED_DIVISORS)
|
foreach (int divisor in validDivisors)
|
||||||
{
|
{
|
||||||
if ((beat * divisor) % beatDivisor == 0)
|
if ((beat * divisor) % beatDivisor == 0)
|
||||||
return divisor;
|
return divisor;
|
||||||
|
@ -401,13 +401,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Max();
|
int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Max();
|
||||||
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
|
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
|
||||||
{
|
{
|
||||||
int divisor = largestDivisor;
|
int divisor = BindableBeatDivisor.GetDivisorForBeatIndex(tickIndex, largestDivisor, (int[])beatDivisor.ValidDivisors.Value.Presets);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSolidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
|
bool isSolidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
|
||||||
AddInternal(new Tick(isSolidTick, divisor)
|
AddInternal(new Tick(isSolidTick, divisor)
|
||||||
|
Loading…
Reference in New Issue
Block a user