2022-07-15 19:07:01 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
2022-07-15 19:07:01 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
2022-07-14 16:29:23 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Utility class to perform various encodings. This is separated out from the encoding classes to prevent circular
|
|
|
|
/// dependencies.
|
|
|
|
/// </summary>
|
|
|
|
public class TaikoColourDifficultyPreprocessor
|
|
|
|
{
|
|
|
|
/// <summary>
|
2022-07-21 08:52:41 +08:00
|
|
|
/// Processes and encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="TaikoDifficultyHitObjectColour"/>s,
|
|
|
|
/// assigning the appropriate <see cref="TaikoDifficultyHitObjectColour"/>s to each <see cref="TaikoDifficultyHitObject"/>,
|
|
|
|
/// and pre-evaluating colour difficulty of each <see cref="TaikoDifficultyHitObject"/>.
|
2022-07-14 16:29:23 +08:00
|
|
|
/// </summary>
|
|
|
|
public static List<TaikoDifficultyHitObjectColour> ProcessAndAssign(List<DifficultyHitObject> hitObjects)
|
|
|
|
{
|
|
|
|
List<TaikoDifficultyHitObjectColour> colours = new List<TaikoDifficultyHitObjectColour>();
|
|
|
|
List<CoupledColourEncoding> encodings = Encode(hitObjects);
|
|
|
|
|
2022-07-21 19:15:22 +08:00
|
|
|
// Assign indexing and encoding data to all relevant objects. Only the first note of each encoding type is
|
|
|
|
// assigned with the relevant encodings.
|
2022-07-14 16:29:23 +08:00
|
|
|
encodings.ForEach(coupledEncoding =>
|
|
|
|
{
|
2022-07-21 19:15:22 +08:00
|
|
|
coupledEncoding.Payload[0].Payload[0].EncodedData[0].Colour.CoupledColourEncoding = coupledEncoding;
|
|
|
|
|
|
|
|
// The outermost loop is kept a ForEach loop since it doesn't need index information, and we want to
|
|
|
|
// keep i and j for ColourEncoding's and MonoEncoding's index respectively, to keep it in line with
|
|
|
|
// documentation.
|
|
|
|
for (int i = 0; i < coupledEncoding.Payload.Count; ++i)
|
2022-07-14 16:29:23 +08:00
|
|
|
{
|
2022-07-21 19:15:22 +08:00
|
|
|
ColourEncoding colourEncoding = coupledEncoding.Payload[i];
|
|
|
|
colourEncoding.Parent = coupledEncoding;
|
|
|
|
colourEncoding.Index = i;
|
|
|
|
colourEncoding.Payload[0].EncodedData[0].Colour.ColourEncoding = colourEncoding;
|
|
|
|
|
|
|
|
for (int j = 0; j < colourEncoding.Payload.Count; ++j)
|
2022-07-14 16:29:23 +08:00
|
|
|
{
|
2022-07-21 19:15:22 +08:00
|
|
|
MonoEncoding monoEncoding = colourEncoding.Payload[j];
|
|
|
|
monoEncoding.Parent = colourEncoding;
|
|
|
|
monoEncoding.Index = j;
|
|
|
|
monoEncoding.EncodedData[0].Colour.MonoEncoding = monoEncoding;
|
|
|
|
}
|
|
|
|
}
|
2022-07-14 16:29:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return colours;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="MonoEncoding"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public static List<MonoEncoding> EncodeMono(List<DifficultyHitObject> data)
|
|
|
|
{
|
|
|
|
List<MonoEncoding> encoded = new List<MonoEncoding>();
|
|
|
|
|
|
|
|
MonoEncoding? lastEncoded = null;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
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
|
2022-07-15 19:07:01 +08:00
|
|
|
TaikoDifficultyHitObject? previousObject = taikoObject.PreviousNote(0);
|
2022-07-14 16:29:23 +08:00
|
|
|
|
2022-07-21 08:52:41 +08:00
|
|
|
// If the colour changed or if this is the first object in the run, create a new mono encoding
|
2022-07-15 19:07:01 +08:00
|
|
|
if
|
|
|
|
(
|
2022-07-14 16:29:23 +08:00
|
|
|
previousObject == null || // First object in the list
|
2022-07-15 19:07:01 +08:00
|
|
|
(taikoObject.BaseObject as Hit)?.Type != (previousObject.BaseObject as Hit)?.Type
|
|
|
|
)
|
2022-07-14 16:29:23 +08:00
|
|
|
{
|
|
|
|
lastEncoded = new MonoEncoding();
|
|
|
|
lastEncoded.EncodedData.Add(taikoObject);
|
|
|
|
encoded.Add(lastEncoded);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-21 08:52:41 +08:00
|
|
|
// If we're here, we're in the same encoding as the previous object, thus lastEncoded is not null.
|
|
|
|
// Add the current object to the encoded payload.
|
2022-07-14 16:29:23 +08:00
|
|
|
lastEncoded!.EncodedData.Add(taikoObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Encodes a list of <see cref="MonoEncoding"/>s into a list of <see cref="ColourEncoding"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public static List<ColourEncoding> EncodeColour(List<MonoEncoding> data)
|
|
|
|
{
|
|
|
|
List<ColourEncoding> encoded = new List<ColourEncoding>();
|
|
|
|
ColourEncoding? lastEncoded = null;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
for (int i = 0; i < data.Count; i++)
|
|
|
|
{
|
|
|
|
// Starts a new ColourEncoding if the previous MonoEncoding has a different mono length, or if this is
|
|
|
|
// the first MonoEncoding in the list.
|
|
|
|
if (lastEncoded == null || data[i].RunLength != data[i - 1].RunLength)
|
|
|
|
{
|
|
|
|
lastEncoded = new ColourEncoding();
|
|
|
|
lastEncoded.Payload.Add(data[i]);
|
|
|
|
encoded.Add(lastEncoded);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're here, we're in the same encoding as the previous object. Add the current MonoEncoding to the
|
|
|
|
// encoded payload.
|
|
|
|
lastEncoded.Payload.Add(data[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Encodes a list of <see cref="ColourEncoding"/>s into a list of <see cref="CoupledColourEncoding"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public static List<CoupledColourEncoding> EncodeCoupledColour(List<ColourEncoding> data)
|
|
|
|
{
|
|
|
|
List<CoupledColourEncoding> encoded = new List<CoupledColourEncoding>();
|
|
|
|
CoupledColourEncoding? lastEncoded = null;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
for (int i = 0; i < data.Count; i++)
|
|
|
|
{
|
|
|
|
// Starts a new CoupledColourEncoding. ColourEncodings that should be grouped together will be handled
|
|
|
|
// later within this loop.
|
2022-07-15 19:07:01 +08:00
|
|
|
lastEncoded = new CoupledColourEncoding
|
2022-07-14 16:29:23 +08:00
|
|
|
{
|
|
|
|
Previous = lastEncoded
|
|
|
|
};
|
|
|
|
|
|
|
|
// Determine if future ColourEncodings should be grouped.
|
2022-07-15 19:07:01 +08:00
|
|
|
bool isCoupled = i < data.Count - 2 && data[i].IsRepetitionOf(data[i + 2]);
|
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
if (!isCoupled)
|
|
|
|
{
|
|
|
|
// If not, add the current ColourEncoding to the encoded payload and continue.
|
|
|
|
lastEncoded.Payload.Add(data[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-15 19:07:01 +08:00
|
|
|
// If so, add the current ColourEncoding to the encoded payload and start repeatedly checking if the
|
|
|
|
// subsequent ColourEncodings should be grouped by increasing i and doing the appropriate isCoupled check.
|
2022-07-14 16:29:23 +08:00
|
|
|
while (isCoupled)
|
|
|
|
{
|
|
|
|
lastEncoded.Payload.Add(data[i]);
|
|
|
|
i++;
|
2022-07-15 19:07:01 +08:00
|
|
|
isCoupled = i < data.Count - 2 && data[i].IsRepetitionOf(data[i + 2]);
|
2022-07-14 16:29:23 +08:00
|
|
|
}
|
|
|
|
|
2022-07-21 08:52:41 +08:00
|
|
|
// Skip over viewed data and add the rest to the payload
|
2022-07-14 16:29:23 +08:00
|
|
|
lastEncoded.Payload.Add(data[i]);
|
|
|
|
lastEncoded.Payload.Add(data[i + 1]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
encoded.Add(lastEncoded);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final pass to find repetition intervals
|
|
|
|
for (int i = 0; i < encoded.Count; i++)
|
|
|
|
{
|
|
|
|
encoded[i].FindRepetitionInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoded;
|
|
|
|
}
|
2022-07-21 19:15:22 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="CoupledColourEncoding"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public static List<CoupledColourEncoding> Encode(List<DifficultyHitObject> data)
|
|
|
|
{
|
|
|
|
List<MonoEncoding> firstPass = EncodeMono(data);
|
|
|
|
List<ColourEncoding> secondPass = EncodeColour(firstPass);
|
|
|
|
List<CoupledColourEncoding> thirdPass = EncodeCoupledColour(secondPass);
|
|
|
|
|
|
|
|
return thirdPass;
|
|
|
|
}
|
2022-07-14 16:29:23 +08:00
|
|
|
}
|
2022-07-15 19:07:01 +08:00
|
|
|
}
|