mirror of
https://github.com/ppy/osu-tools.git
synced 2025-06-07 23:07:01 +09:00
69 lines
2.4 KiB
C#
69 lines
2.4 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.IO;
|
|
using osu.Framework.Audio.Track;
|
|
using osu.Framework.Graphics.Textures;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Beatmaps.Formats;
|
|
using osu.Game.Rulesets.Catch;
|
|
using osu.Game.Rulesets.Mania;
|
|
using osu.Game.Rulesets.Osu;
|
|
using osu.Game.Rulesets.Taiko;
|
|
|
|
namespace PerformanceCalculator
|
|
{
|
|
/// <summary>
|
|
/// A <see cref="WorkingBeatmap"/> which reads from a .osu file.
|
|
/// </summary>
|
|
public class ProcessorWorkingBeatmap : WorkingBeatmap
|
|
{
|
|
private readonly Beatmap beatmap;
|
|
|
|
/// <summary>
|
|
/// Constructs a new <see cref="ProcessorWorkingBeatmap"/> from a .osu file.
|
|
/// </summary>
|
|
/// <param name="file">The .osu file.</param>
|
|
/// <param name="beatmapId">An optional beatmap ID (for cases where .osu file doesn't have one).</param>
|
|
public ProcessorWorkingBeatmap(string file, int? beatmapId = null)
|
|
: this(readFromFile(file), beatmapId)
|
|
{
|
|
}
|
|
|
|
private ProcessorWorkingBeatmap(Beatmap beatmap, int? beatmapId = null)
|
|
: base(beatmap.BeatmapInfo)
|
|
{
|
|
this.beatmap = beatmap;
|
|
|
|
switch (beatmap.BeatmapInfo.RulesetID)
|
|
{
|
|
case 0:
|
|
beatmap.BeatmapInfo.Ruleset = new OsuRuleset().RulesetInfo;
|
|
break;
|
|
case 1:
|
|
beatmap.BeatmapInfo.Ruleset = new TaikoRuleset().RulesetInfo;
|
|
break;
|
|
case 2:
|
|
beatmap.BeatmapInfo.Ruleset = new CatchRuleset().RulesetInfo;
|
|
break;
|
|
case 3:
|
|
beatmap.BeatmapInfo.Ruleset = new ManiaRuleset().RulesetInfo;
|
|
break;
|
|
}
|
|
|
|
if (beatmapId.HasValue)
|
|
beatmap.BeatmapInfo.OnlineBeatmapID = beatmapId;
|
|
}
|
|
|
|
private static Beatmap readFromFile(string filename)
|
|
{
|
|
using (var stream = File.OpenRead(filename))
|
|
using (var streamReader = new StreamReader(stream))
|
|
return Decoder.GetDecoder<Beatmap>(streamReader).Decode(streamReader);
|
|
}
|
|
|
|
protected override IBeatmap GetBeatmap() => beatmap;
|
|
protected override Texture GetBackground() => null;
|
|
protected override Track GetTrack() => null;
|
|
}
|
|
}
|