From 1ded04377815f3b0ef926982f2f2c93afb7a1d2f Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 17 May 2017 13:07:56 +0900 Subject: [PATCH] Add basic mania-specific beatmap conversion. # Conflicts: # osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs --- .../Beatmaps/LegacyConverter.cs | 72 +++++++++++++++++++ .../Beatmaps/ManiaBeatmapConverter.cs | 41 ++++++----- .../osu.Game.Rulesets.Mania.csproj | 1 + 3 files changed, 95 insertions(+), 19 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Beatmaps/LegacyConverter.cs diff --git a/osu.Game.Rulesets.Mania/Beatmaps/LegacyConverter.cs b/osu.Game.Rulesets.Mania/Beatmaps/LegacyConverter.cs new file mode 100644 index 0000000000..20a3dc612b --- /dev/null +++ b/osu.Game.Rulesets.Mania/Beatmaps/LegacyConverter.cs @@ -0,0 +1,72 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Types; +using SharpNeat.Utility; +using System; +using System.Collections.Generic; + +namespace osu.Game.Rulesets.Mania.Beatmaps +{ + /// + /// Special converter used for converting from osu!stable beatmaps. + /// + internal class LegacyConverter + { + private readonly FastRandom random; + + private readonly int availableColumns; + private readonly float localXDivisor; + + private readonly Beatmap beatmap; + + public LegacyConverter(Beatmap beatmap) + { + this.beatmap = beatmap; + + int seed = (int)Math.Round(beatmap.BeatmapInfo.Difficulty.DrainRate + beatmap.BeatmapInfo.Difficulty.CircleSize) + * 20 + (int)(beatmap.BeatmapInfo.Difficulty.OverallDifficulty * 41.2) + (int)Math.Round(beatmap.BeatmapInfo.Difficulty.ApproachRate); + + availableColumns = (int)Math.Round(beatmap.BeatmapInfo.Difficulty.CircleSize); + localXDivisor = 512.0f / availableColumns; + } + + public IEnumerable Convert(HitObject original) + { + if (beatmap.BeatmapInfo.RulesetID == 3) + yield return generateSpecific(original); + } + + private ManiaHitObject generateSpecific(HitObject original) + { + var endTimeData = original as IHasEndTime; + var positionData = original as IHasPosition; + + int column = getColumn(positionData?.X ?? 0); + + if (endTimeData != null) + { + return new HoldNote + { + StartTime = original.StartTime, + Samples = original.Samples, + Duration = endTimeData.Duration, + Column = column, + }; + } + + return new Note + { + StartTime = original.StartTime, + Samples = original.Samples, + Column = column + }; + } + + private int getColumn(float position) => MathHelper.Clamp((int)Math.Floor(position / localXDivisor), 0, availableColumns - 1); + } +} diff --git a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs index e51bbcdc13..e9dae95782 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs @@ -1,35 +1,38 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Game.Beatmaps; -using osu.Game.Rulesets.Mania.Objects; -using System.Collections.Generic; -using System; -using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Beatmaps; +using osu.Game.Rulesets.Mania.Objects; +using System; +using System.Collections.Generic; +using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects; -using OpenTK; +using osu.Game.Rulesets.Objects.Types; +using System.Linq; namespace osu.Game.Rulesets.Mania.Beatmaps { - internal class ManiaBeatmapConverter : BeatmapConverter + public class ManiaBeatmapConverter : BeatmapConverter { protected override IEnumerable ValidConversionTypes { get; } = new[] { typeof(IHasXPosition) }; + protected override Beatmap ConvertBeatmap(Beatmap original) + { + // Todo: This should be cased when we get better conversion methods + var converter = new LegacyConverter(original); + + return new Beatmap + { + BeatmapInfo = original.BeatmapInfo, + TimingInfo = original.TimingInfo, + HitObjects = original.HitObjects.SelectMany(converter.Convert).ToList() + }; + } + protected override IEnumerable ConvertHitObject(HitObject original, Beatmap beatmap) { - int availableColumns = (int)Math.Round(beatmap.BeatmapInfo.Difficulty.CircleSize); - - var positionData = original as IHasXPosition; - - float localWDivisor = 512.0f / availableColumns; - int column = MathHelper.Clamp((int)Math.Floor((positionData?.X ?? 1) / localWDivisor), 0, availableColumns - 1); - - yield return new Note - { - StartTime = original.StartTime, - Column = column, - }; + // Handled by the LegacyConvereter + yield return null; } } } diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 52396debf5..781dc3e228 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -47,6 +47,7 @@ +