mirror of
https://github.com/ppy/osu.git
synced 2025-03-13 10:37:19 +08:00
See previous commit for partial rationale. There's an argument to be made about the `NaN`-spreading semantics being desirable because at least something will loudly fail in that case, but I'm not so sure about that these days. It feels like either way if `NaN`s are produced, then things are outside of any control, and chances are the game can probably continue without crashing. And, this move reduces our dependence on osuTK, which has already been living on borrowed time for years now and is only awaiting someone brave to go excise it.
49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Rulesets.Objects;
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
using osu.Game.Rulesets.Pippidon.Objects;
|
|
using osu.Game.Rulesets.Pippidon.UI;
|
|
|
|
namespace osu.Game.Rulesets.Pippidon.Beatmaps
|
|
{
|
|
public class PippidonBeatmapConverter : BeatmapConverter<PippidonHitObject>
|
|
{
|
|
private readonly float minPosition;
|
|
private readonly float maxPosition;
|
|
|
|
public PippidonBeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
|
|
: base(beatmap, ruleset)
|
|
{
|
|
if (beatmap.HitObjects.Any())
|
|
{
|
|
minPosition = beatmap.HitObjects.Min(getUsablePosition);
|
|
maxPosition = beatmap.HitObjects.Max(getUsablePosition);
|
|
}
|
|
}
|
|
|
|
public override bool CanConvert() => Beatmap.HitObjects.All(h => h is IHasXPosition && h is IHasYPosition);
|
|
|
|
protected override IEnumerable<PippidonHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
|
|
{
|
|
yield return new PippidonHitObject
|
|
{
|
|
Samples = original.Samples,
|
|
StartTime = original.StartTime,
|
|
Lane = getLane(original)
|
|
};
|
|
}
|
|
|
|
private int getLane(HitObject hitObject) => (int)Math.Clamp(
|
|
(getUsablePosition(hitObject) - minPosition) / (maxPosition - minPosition) * PippidonPlayfield.LANE_COUNT, 0, PippidonPlayfield.LANE_COUNT - 1);
|
|
|
|
private float getUsablePosition(HitObject h) => (h as IHasYPosition)?.Y ?? ((IHasXPosition)h).X;
|
|
}
|
|
}
|