From df665c3a3cd98744c5381282c124148b60d83cdc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 27 Jan 2020 16:00:51 +0900 Subject: [PATCH] Move beat index colour retrieval to static function --- osu.Game/Screens/Edit/BindableBeatDivisor.cs | 23 ++++++++++++++++++- .../Compose/Components/DistanceSnapGrid.cs | 14 +---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/osu.Game/Screens/Edit/BindableBeatDivisor.cs b/osu.Game/Screens/Edit/BindableBeatDivisor.cs index e8f7c75cc1..be1e121a99 100644 --- a/osu.Game/Screens/Edit/BindableBeatDivisor.cs +++ b/osu.Game/Screens/Edit/BindableBeatDivisor.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -80,5 +80,26 @@ namespace osu.Game.Screens.Edit return Color4.Red; } } + + /// + /// Retrieves the applicable divisor for a specific beat index. + /// + /// The 0-based beat index. + /// The beat divisor. + /// The applicable divisor. + public static int GetDivisorForBeatIndex(int index, int beatDivisor) + { + int beat = index % beatDivisor; + + for (int i = 0; i < BindableBeatDivisor.VALID_DIVISORS.Length; i++) + { + int divisor = BindableBeatDivisor.VALID_DIVISORS[i]; + + if ((beat * divisor) % beatDivisor == 0) + return divisor; + } + + return 0; + } } } diff --git a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs index 53c5cf97fa..3bbccd612b 100644 --- a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs @@ -130,19 +130,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// The applicable colour. protected ColourInfo GetColourForBeatIndex(int index) { - int beat = (index + 1) % beatDivisor.Value; - ColourInfo colour = Colours.Gray5; - - for (int i = 0; i < BindableBeatDivisor.VALID_DIVISORS.Length; i++) - { - int divisor = BindableBeatDivisor.VALID_DIVISORS[i]; - - if ((beat * divisor) % beatDivisor.Value == 0) - { - colour = BindableBeatDivisor.GetColourFor(divisor, Colours); - break; - } - } + var colour = BindableBeatDivisor.GetColourFor(BindableBeatDivisor.GetDivisorForBeatIndex(index + 1, beatDivisor.Value), Colours); int repeatIndex = index / beatDivisor.Value; return colour.MultiplyAlpha(0.5f / (repeatIndex + 1));