using System.Collections.Generic; using osu.Game.Rulesets.Difficulty.Preprocessing; namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing { public class ColourEncoding { /// /// Amount consecutive notes of the same colour /// public int MonoRunLength = 1; /// /// Amount of consecutive encoding with the same /// public int EncodingRunLength = 1; /// /// Beginning index in the data that this encodes /// public int StartIndex = 0; public bool isIdenticalTo(ColourEncoding other) { return other.MonoRunLength == MonoRunLength && other.EncodingRunLength == EncodingRunLength; } public static List Encode(List data) { // Encoding mono lengths List firstPass = new List(); ColourEncoding? lastEncoded = null; for (int i = 0; i < data.Count; i++) { TaikoDifficultyHitObject taikoObject = (TaikoDifficultyHitObject)data[i]; // This ignores all non-note objects, which may or may not be the desired behaviour TaikoDifficultyHitObject previousObject = (TaikoDifficultyHitObject)taikoObject.PreviousNote(0); if (previousObject == null || lastEncoded == null || taikoObject.HitType != previousObject.HitType) { lastEncoded = new ColourEncoding(); lastEncoded.StartIndex = i; firstPass.Add(lastEncoded); continue; } lastEncoded.MonoRunLength += 1; } // Encode encoding lengths List secondPass = new List(); lastEncoded = null; for (int i = 0; i < firstPass.Count; i++) { if (i == 0 || lastEncoded == null || firstPass[i].MonoRunLength != firstPass[i - 1].MonoRunLength) { lastEncoded = firstPass[i]; secondPass.Add(firstPass[i]); continue; } lastEncoded.EncodingRunLength += 1; } return secondPass; } } }