mirror of
https://github.com/ppy/osu-tools.git
synced 2025-06-08 07:17:01 +09:00
51 lines
1.8 KiB
C#
51 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.IO;
|
|
using osu.Framework.Audio.Track;
|
|
using osu.Framework.Graphics.Textures;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Beatmaps.Formats;
|
|
|
|
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;
|
|
|
|
beatmap.BeatmapInfo.Ruleset = LegacyHelper.GetRulesetFromLegacyID(beatmap.BeatmapInfo.RulesetID).RulesetInfo;
|
|
|
|
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;
|
|
}
|
|
}
|