1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 09:27:34 +08:00
osu-lazer/osu.Game/Beatmaps/Formats/LegacyDecoder.cs
Aergwyn c466296b14 reverted split at Decoder, moved logic down
I'm done experimenting, sorry
- `Decoder` only returns a "Beatmap"`Decoder` now
- "Storyboard"`Decoder` is retrieved from a "Beatmap"`Decoder`
- moved parse methods down in the hierarchy where I forgot to do that
- renamed `OsuLegacyDecoderTest` to `LegacyDecoderTest`
2017-12-01 22:05:01 +01:00

160 lines
5.1 KiB
C#

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.IO;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Storyboards;
namespace osu.Game.Beatmaps.Formats
{
public abstract class LegacyDecoder : Decoder
{
public static void Register()
{
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v14");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v13");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v12");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v11");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v10");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v9");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v8");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v7");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v6");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v5");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v4");
AddDecoder<LegacyBeatmapDecoder>(@"osu file format v3");
// TODO: differences between versions
}
protected int BeatmapVersion;
protected readonly Dictionary<string, string> Variables = new Dictionary<string, string>();
public override Decoder GetStoryboardDecoder() => new LegacyStoryboardDecoder(BeatmapVersion);
public override Beatmap DecodeBeatmap(StreamReader stream) => new LegacyBeatmap(base.DecodeBeatmap(stream));
protected override void ParseBeatmap(StreamReader stream, Beatmap beatmap)
{
throw new NotImplementedException();
}
protected override void ParseStoryboard(StreamReader stream, Storyboard storyboard)
{
throw new NotImplementedException();
}
protected void ParseContent(StreamReader stream)
{
Section section = Section.None;
string line;
while ((line = stream.ReadLine()) != null)
{
if (string.IsNullOrWhiteSpace(line))
continue;
if (line.StartsWith("//"))
continue;
// It's already set in ParseBeatmap... why do it again?
//if (line.StartsWith(@"osu file format v"))
//{
// Beatmap.BeatmapInfo.BeatmapVersion = int.Parse(line.Substring(17));
// continue;
//}
if (line.StartsWith(@"[") && line.EndsWith(@"]"))
{
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
throw new InvalidDataException($@"Unknown osu section {line}");
continue;
}
ProcessSection(section, line);
}
}
protected abstract void ProcessSection(Section section, string line);
/// <summary>
/// Decodes any beatmap variables present in a line into their real values.
/// </summary>
/// <param name="line">The line which may contains variables.</param>
protected void DecodeVariables(ref string line)
{
while (line.IndexOf('$') >= 0)
{
string origLine = line;
string[] split = line.Split(',');
for (int i = 0; i < split.Length; i++)
{
var item = split[i];
if (item.StartsWith("$") && Variables.ContainsKey(item))
split[i] = Variables[item];
}
line = string.Join(",", split);
if (line == origLine)
break;
}
}
protected enum Section
{
None,
General,
Editor,
Metadata,
Difficulty,
Events,
TimingPoints,
Colours,
HitObjects,
Variables,
}
internal enum LegacySampleBank
{
None = 0,
Normal = 1,
Soft = 2,
Drum = 3
}
internal enum EventType
{
Background = 0,
Video = 1,
Break = 2,
Colour = 3,
Sprite = 4,
Sample = 5,
Animation = 6
}
internal enum LegacyOrigins
{
TopLeft,
Centre,
CentreLeft,
TopRight,
BottomCentre,
TopCentre,
Custom,
CentreRight,
BottomLeft,
BottomRight
};
internal enum StoryLayer
{
Background = 0,
Fail = 1,
Pass = 2,
Foreground = 3
}
}
}