2017-12-02 00:43:33 +08:00
|
|
|
|
// 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
|
|
|
|
|
{
|
2017-12-02 02:11:52 +08:00
|
|
|
|
public abstract class LegacyDecoder : Decoder
|
2017-12-02 00:43:33 +08:00
|
|
|
|
{
|
|
|
|
|
public static void Register()
|
|
|
|
|
{
|
2017-12-02 05:05:01 +08:00
|
|
|
|
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");
|
2017-12-02 00:43:33 +08:00
|
|
|
|
// TODO: differences between versions
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 00:58:11 +08:00
|
|
|
|
protected int BeatmapVersion;
|
|
|
|
|
protected readonly Dictionary<string, string> Variables = new Dictionary<string, string>();
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
2017-12-02 05:05:01 +08:00
|
|
|
|
public override Decoder GetStoryboardDecoder() => new LegacyStoryboardDecoder(BeatmapVersion);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
2017-12-02 05:05:01 +08:00
|
|
|
|
public override Beatmap DecodeBeatmap(StreamReader stream) => new LegacyBeatmap(base.DecodeBeatmap(stream));
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
|
|
|
|
protected override void ParseBeatmap(StreamReader stream, Beatmap beatmap)
|
|
|
|
|
{
|
2017-12-02 05:05:01 +08:00
|
|
|
|
throw new NotImplementedException();
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ParseStoryboard(StreamReader stream, Storyboard storyboard)
|
|
|
|
|
{
|
2017-12-02 05:05:01 +08:00
|
|
|
|
throw new NotImplementedException();
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2017-12-02 05:05:01 +08:00
|
|
|
|
// 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;
|
|
|
|
|
//}
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
|
|
|
|
if (line.StartsWith(@"[") && line.EndsWith(@"]"))
|
|
|
|
|
{
|
|
|
|
|
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
|
|
|
|
|
throw new InvalidDataException($@"Unknown osu section {line}");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 00:58:11 +08:00
|
|
|
|
ProcessSection(section, line);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 02:11:52 +08:00
|
|
|
|
protected abstract void ProcessSection(Section section, string line);
|
2017-12-02 00:43:33 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decodes any beatmap variables present in a line into their real values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="line">The line which may contains variables.</param>
|
2017-12-02 00:58:11 +08:00
|
|
|
|
protected void DecodeVariables(ref string line)
|
2017-12-02 00:43:33 +08:00
|
|
|
|
{
|
|
|
|
|
while (line.IndexOf('$') >= 0)
|
|
|
|
|
{
|
|
|
|
|
string origLine = line;
|
|
|
|
|
string[] split = line.Split(',');
|
|
|
|
|
for (int i = 0; i < split.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = split[i];
|
2017-12-02 00:58:11 +08:00
|
|
|
|
if (item.StartsWith("$") && Variables.ContainsKey(item))
|
|
|
|
|
split[i] = Variables[item];
|
2017-12-02 00:43:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|