1
0
Fork 0
mirror of https://github.com/ppy/osu-tools.git synced 2025-06-08 07:17:01 +09:00
osu-tools/PerformanceCalculator/ProcessorWorkingBeatmap.cs

77 lines
2.6 KiB
C#

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-tools/master/LICENCE
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>
public ProcessorWorkingBeatmap(string file)
: this(File.OpenRead(file))
{
}
/// <summary>
/// Constructs a new <see cref="ProcessorWorkingBeatmap"/> from a stream.
/// </summary>
/// <param name="stream">The stream.</param>
public ProcessorWorkingBeatmap(Stream stream)
: this(new StreamReader(stream))
{
stream.Dispose();
}
/// <summary>
/// Constructs a new <see cref="ProcessorWorkingBeatmap"/> from a stream reader.
/// </summary>
/// <param name="streamReader">The stream reader.</param>
public ProcessorWorkingBeatmap(StreamReader streamReader)
: this(Decoder.GetDecoder<Beatmap>(streamReader).Decode(streamReader))
{
}
private ProcessorWorkingBeatmap(Beatmap beatmap)
: 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;
}
}
protected override IBeatmap GetBeatmap() => beatmap;
protected override Texture GetBackground() => null;
protected override Track GetTrack() => null;
}
}