1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 18:03:11 +08:00

Move combo information updating to an interface level helper method

This commit is contained in:
Dean Herbert 2023-05-17 17:19:07 +09:00
parent e43f2c2c43
commit 8d925c8a8a
2 changed files with 25 additions and 25 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Linq;
using osu.Game.Rulesets.Objects.Types;
@ -22,34 +20,17 @@ namespace osu.Game.Beatmaps
public virtual void PreProcess()
{
IHasComboInformation lastObj = null;
bool isFirst = true;
IHasComboInformation? lastObj = null;
foreach (var obj in Beatmap.HitObjects.OfType<IHasComboInformation>())
{
if (isFirst)
if (lastObj == null)
{
obj.NewCombo = true;
// first hitobject should always be marked as a new combo for sanity.
isFirst = false;
}
obj.ComboIndex = lastObj?.ComboIndex ?? 0;
obj.ComboIndexWithOffsets = lastObj?.ComboIndexWithOffsets ?? 0;
obj.IndexInCurrentCombo = (lastObj?.IndexInCurrentCombo + 1) ?? 0;
if (obj.NewCombo)
{
obj.IndexInCurrentCombo = 0;
obj.ComboIndex++;
obj.ComboIndexWithOffsets += obj.ComboOffset + 1;
if (lastObj != null)
lastObj.LastInCombo = true;
obj.NewCombo = true;
}
obj.UpdateComboInformation(lastObj);
lastObj = obj;
}
}

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Bindables;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -65,5 +63,26 @@ namespace osu.Game.Rulesets.Objects.Types
{
return skin.GetConfig<SkinComboColourLookup, Color4>(new SkinComboColourLookup(comboIndex, combo))?.Value ?? Color4.White;
}
/// <summary>
/// Given the previous object in the beatmap, update relevant combo information.
/// </summary>
/// <param name="lastObj">The previous hitobject, or null if this is the first object in the beatmap.</param>
void UpdateComboInformation(IHasComboInformation? lastObj)
{
ComboIndex = lastObj?.ComboIndex ?? 0;
ComboIndexWithOffsets = lastObj?.ComboIndexWithOffsets ?? 0;
IndexInCurrentCombo = (lastObj?.IndexInCurrentCombo + 1) ?? 0;
if (NewCombo || lastObj == null)
{
IndexInCurrentCombo = 0;
ComboIndex++;
ComboIndexWithOffsets += ComboOffset + 1;
if (lastObj != null)
lastObj.LastInCombo = true;
}
}
}
}