2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-12-02 00:43:33 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Formats
|
|
|
|
|
{
|
2018-03-09 20:23:03 +08:00
|
|
|
|
public abstract class LegacyDecoder<T> : Decoder<T>
|
|
|
|
|
where T : new()
|
2017-12-02 00:43:33 +08:00
|
|
|
|
{
|
2018-03-09 20:23:03 +08:00
|
|
|
|
protected readonly int FormatVersion;
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
2018-03-09 20:23:03 +08:00
|
|
|
|
protected LegacyDecoder(int version)
|
2017-12-02 00:43:33 +08:00
|
|
|
|
{
|
2018-03-09 20:23:03 +08:00
|
|
|
|
FormatVersion = version;
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 20:23:03 +08:00
|
|
|
|
protected override void ParseStreamInto(StreamReader stream, T beatmap)
|
2017-12-02 00:43:33 +08:00
|
|
|
|
{
|
|
|
|
|
Section section = Section.None;
|
|
|
|
|
|
|
|
|
|
string line;
|
|
|
|
|
while ((line = stream.ReadLine()) != null)
|
|
|
|
|
{
|
2017-12-02 23:05:39 +08:00
|
|
|
|
if (ShouldSkipLine(line))
|
2017-12-02 00:43:33 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 20:23:03 +08:00
|
|
|
|
ParseLine(beatmap, section, line);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 20:23:03 +08:00
|
|
|
|
protected virtual bool ShouldSkipLine(string line) => string.IsNullOrWhiteSpace(line) || line.StartsWith("//");
|
2017-12-02 23:05:39 +08:00
|
|
|
|
|
2018-03-09 20:23:03 +08:00
|
|
|
|
protected abstract void ParseLine(T output, Section section, string line);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
2018-01-04 19:23:00 +08:00
|
|
|
|
protected KeyValuePair<string, string> SplitKeyVal(string line, char separator)
|
2017-12-02 00:43:33 +08:00
|
|
|
|
{
|
2018-01-04 19:04:52 +08:00
|
|
|
|
var split = line.Trim().Split(new[] { separator }, 2);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
2018-01-04 19:04:52 +08:00
|
|
|
|
return new KeyValuePair<string, string>
|
|
|
|
|
(
|
|
|
|
|
split[0].Trim(),
|
|
|
|
|
split.Length > 1 ? split[1].Trim() : string.Empty
|
|
|
|
|
);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2018-01-13 02:30:34 +08:00
|
|
|
|
}
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
|
|
|
|
internal enum StoryLayer
|
|
|
|
|
{
|
|
|
|
|
Background = 0,
|
|
|
|
|
Fail = 1,
|
|
|
|
|
Pass = 2,
|
|
|
|
|
Foreground = 3
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|