2016-10-08 03:36:20 +08:00
|
|
|
|
using System;
|
2016-10-08 03:09:52 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using System.IO;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
using osu.Game.Beatmaps.Events;
|
2016-10-08 03:09:52 +08:00
|
|
|
|
using osu.Game.Beatmaps.Objects;
|
2016-10-08 04:19:24 +08:00
|
|
|
|
using osu.Game.Beatmaps.Samples;
|
2016-10-08 03:09:52 +08:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
|
using osu.Game.GameModes.Play;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
|
2016-10-08 03:36:20 +08:00
|
|
|
|
namespace osu.Game.Beatmaps.Formats
|
|
|
|
|
{
|
|
|
|
|
public class OsuLegacyDecoder : BeatmapDecoder
|
|
|
|
|
{
|
|
|
|
|
public static void Register()
|
|
|
|
|
{
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>("osu file format v14");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>("osu file format v13");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>("osu file format v12");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>("osu file format v11");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>("osu file format v10");
|
|
|
|
|
// TODO: Not sure how far back to go, or differences between versions
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
2016-10-08 03:36:20 +08:00
|
|
|
|
|
|
|
|
|
private enum Section
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
General,
|
|
|
|
|
Editor,
|
|
|
|
|
Metadata,
|
|
|
|
|
Difficulty,
|
|
|
|
|
Events,
|
|
|
|
|
TimingPoints,
|
|
|
|
|
Colours,
|
|
|
|
|
HitObjects,
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
2016-10-08 03:36:20 +08:00
|
|
|
|
|
|
|
|
|
private void HandleGeneral(Beatmap beatmap, string key, string val)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case "AudioFilename":
|
2016-10-08 03:09:52 +08:00
|
|
|
|
beatmap.Metadata.AudioFile = val;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "AudioLeadIn":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.AudioLeadIn = int.Parse(val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "PreviewTime":
|
|
|
|
|
beatmap.Metadata.PreviewTime = int.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "Countdown":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.Countdown = int.Parse(val) == 1;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "SampleSet":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.SampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "StackLeniency":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.StackLeniency = float.Parse(val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "Mode":
|
|
|
|
|
beatmap.Mode = (PlayMode)int.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "LetterboxInBreaks":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.LetterboxInBreaks = int.Parse(val) == 1;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "SpecialStyle":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.SpecialStyle = int.Parse(val) == 1;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case "WidescreenStoryboard":
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.WidescreenStoryboard = int.Parse(val) == 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleEditor(Beatmap beatmap, string key, string val)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case "Bookmarks":
|
|
|
|
|
beatmap.StoredBookmarks = val;
|
|
|
|
|
break;
|
|
|
|
|
case "DistanceSpacing":
|
|
|
|
|
beatmap.DistanceSpacing = double.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "BeatDivisor":
|
|
|
|
|
beatmap.BeatDivisor = int.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "GridSize":
|
|
|
|
|
beatmap.GridSize = int.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "TimelineZoom":
|
|
|
|
|
beatmap.TimelineZoom = double.Parse(val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleMetadata(Beatmap beatmap, string key, string val)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case "Title":
|
|
|
|
|
beatmap.Metadata.Title = val;
|
|
|
|
|
break;
|
|
|
|
|
case "TitleUnicode":
|
|
|
|
|
beatmap.Metadata.TitleUnicode = val;
|
|
|
|
|
break;
|
|
|
|
|
case "Artist":
|
|
|
|
|
beatmap.Metadata.Artist = val;
|
|
|
|
|
break;
|
|
|
|
|
case "ArtistUnicode":
|
|
|
|
|
beatmap.Metadata.ArtistUnicode = val;
|
|
|
|
|
break;
|
|
|
|
|
case "Creator":
|
|
|
|
|
beatmap.Metadata.Author = val;
|
|
|
|
|
break;
|
|
|
|
|
case "Version":
|
|
|
|
|
beatmap.Version = val;
|
|
|
|
|
break;
|
|
|
|
|
case "Source":
|
|
|
|
|
beatmap.Metadata.Source = val;
|
|
|
|
|
break;
|
|
|
|
|
case "Tags":
|
|
|
|
|
beatmap.Metadata.Tags = val;
|
|
|
|
|
break;
|
|
|
|
|
case "BeatmapID":
|
|
|
|
|
beatmap.BeatmapID = int.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "BeatmapSetID":
|
|
|
|
|
beatmap.BeatmapSetID = int.Parse(val);
|
|
|
|
|
beatmap.Metadata.BeatmapSetID = int.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 04:19:24 +08:00
|
|
|
|
private void HandleDifficulty(Beatmap beatmap, string key, string val)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case "HPDrainRate":
|
|
|
|
|
beatmap.BaseDifficulty.DrainRate = float.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "CircleSize":
|
|
|
|
|
beatmap.BaseDifficulty.CircleSize = float.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "OverallDifficulty":
|
|
|
|
|
beatmap.BaseDifficulty.OverallDifficulty = float.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "ApproachRate":
|
|
|
|
|
beatmap.BaseDifficulty.ApproachRate = float.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "SliderMultiplier":
|
|
|
|
|
beatmap.BaseDifficulty.SliderMultiplier = float.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
case "SliderTickRate":
|
|
|
|
|
beatmap.BaseDifficulty.SliderTickRate = float.Parse(val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 03:36:20 +08:00
|
|
|
|
private void HandleEvents(Beatmap beatmap, string val)
|
|
|
|
|
{
|
|
|
|
|
if (val.StartsWith("//"))
|
|
|
|
|
return;
|
|
|
|
|
string[] split = val.Split(',');
|
|
|
|
|
EventType type;
|
|
|
|
|
int _type;
|
|
|
|
|
if (!int.TryParse(split[0], out _type))
|
|
|
|
|
{
|
|
|
|
|
if (!Enum.TryParse(split[0], out type))
|
|
|
|
|
throw new InvalidDataException($@"Unknown event type {split[0]}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
type = (EventType)_type;
|
|
|
|
|
// TODO: Parse and store the rest of the event
|
|
|
|
|
if (type == EventType.Background)
|
|
|
|
|
beatmap.Metadata.BackgroundFile = split[2].Trim('"');
|
2016-10-08 03:09:52 +08:00
|
|
|
|
}
|
2016-10-05 04:29:08 +08:00
|
|
|
|
|
2016-10-08 04:19:24 +08:00
|
|
|
|
private void HandleTimingPoints(Beatmap beatmap, string val)
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 04:29:08 +08:00
|
|
|
|
public override Beatmap Decode(TextReader stream)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
|
|
|
|
var beatmap = new Beatmap
|
|
|
|
|
{
|
|
|
|
|
Metadata = new BeatmapMetadata(),
|
|
|
|
|
BaseDifficulty = new BaseDifficulty(),
|
|
|
|
|
HitObjects = new List<HitObject>(),
|
|
|
|
|
ControlPoints = new List<ControlPoint>(),
|
|
|
|
|
};
|
|
|
|
|
var section = Section.None;
|
|
|
|
|
string line;
|
2016-10-08 03:09:52 +08:00
|
|
|
|
while (true)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
|
|
|
|
line = stream.ReadLine();
|
2016-10-08 03:09:52 +08:00
|
|
|
|
if (line == null)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
line = line.Trim();
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string val = line, key = null;
|
|
|
|
|
if (section != Section.Events && section != Section.TimingPoints
|
2016-10-08 03:09:52 +08:00
|
|
|
|
&& section != Section.HitObjects)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
|
|
|
|
key = val.Remove(val.IndexOf(':')).Trim();
|
2016-10-08 03:09:52 +08:00
|
|
|
|
val = val.Substring(val.IndexOf(':') + 1).Trim();
|
2016-10-08 03:36:20 +08:00
|
|
|
|
}
|
|
|
|
|
switch (section)
|
|
|
|
|
{
|
|
|
|
|
case Section.General:
|
|
|
|
|
HandleGeneral(beatmap, key, val);
|
|
|
|
|
break;
|
|
|
|
|
case Section.Editor:
|
2016-10-08 04:19:24 +08:00
|
|
|
|
HandleEditor(beatmap, key, val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.Metadata:
|
|
|
|
|
HandleMetadata(beatmap, key, val);
|
|
|
|
|
break;
|
|
|
|
|
case Section.Difficulty:
|
2016-10-08 04:19:24 +08:00
|
|
|
|
HandleDifficulty(beatmap, key, val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.Events:
|
|
|
|
|
HandleEvents(beatmap, val);
|
|
|
|
|
break;
|
|
|
|
|
case Section.TimingPoints:
|
2016-10-08 04:19:24 +08:00
|
|
|
|
HandleTimingPoints(beatmap, val);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.HitObjects:
|
2016-10-08 04:19:24 +08:00
|
|
|
|
beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val));
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return beatmap;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|