2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-10-09 23:49:18 +08:00
|
|
|
|
using osu.Framework.IO.File;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Formats
|
|
|
|
|
{
|
|
|
|
|
public class LegacyBeatmapDecoder : LegacyDecoder<Beatmap>
|
|
|
|
|
{
|
|
|
|
|
public const int LATEST_VERSION = 14;
|
|
|
|
|
|
|
|
|
|
private Beatmap beatmap;
|
|
|
|
|
|
|
|
|
|
private ConvertHitObjectParser parser;
|
|
|
|
|
|
|
|
|
|
private LegacySampleBank defaultSampleBank;
|
|
|
|
|
private int defaultSampleVolume = 100;
|
|
|
|
|
|
|
|
|
|
public static void Register()
|
|
|
|
|
{
|
2019-03-13 12:56:31 +08:00
|
|
|
|
AddDecoder<Beatmap>(@"osu file format v", m => new LegacyBeatmapDecoder(Parsing.ParseInt(m.Split('v').Last())));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether or not beatmap or runtime offsets should be applied. Defaults on; only disable for testing purposes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ApplyOffsets = true;
|
|
|
|
|
|
2018-05-28 02:00:21 +08:00
|
|
|
|
private readonly int offset;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-08 14:26:27 +08:00
|
|
|
|
public LegacyBeatmapDecoder(int version = LATEST_VERSION)
|
|
|
|
|
: base(version)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
// BeatmapVersion 4 and lower had an incorrect offset (stable has this set as 24ms off)
|
2018-05-28 02:00:21 +08:00
|
|
|
|
offset = FormatVersion < 5 ? 24 : 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ParseStreamInto(StreamReader stream, Beatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
this.beatmap = beatmap;
|
|
|
|
|
this.beatmap.BeatmapInfo.BeatmapVersion = FormatVersion;
|
|
|
|
|
|
|
|
|
|
base.ParseStreamInto(stream, beatmap);
|
|
|
|
|
|
2018-05-16 12:59:51 +08:00
|
|
|
|
// Objects may be out of order *only* if a user has manually edited an .osu file.
|
|
|
|
|
// Unfortunately there are ranked maps in this state (example: https://osu.ppy.sh/s/594828).
|
|
|
|
|
// OrderBy is used to guarantee that the parsing order of hitobjects with equal start times is maintained (stably-sorted)
|
|
|
|
|
// The parsing order of hitobjects matters in mania difficulty calculation
|
2018-05-16 12:30:48 +08:00
|
|
|
|
this.beatmap.HitObjects = this.beatmap.HitObjects.OrderBy(h => h.StartTime).ToList();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
foreach (var hitObject in this.beatmap.HitObjects)
|
|
|
|
|
hitObject.ApplyDefaults(this.beatmap.ControlPointInfo, this.beatmap.BeatmapInfo.BaseDifficulty);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 16:48:47 +08:00
|
|
|
|
protected override bool ShouldSkipLine(string line) => base.ShouldSkipLine(line) || line.StartsWith(" ", StringComparison.Ordinal) || line.StartsWith("_", StringComparison.Ordinal);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
protected override void ParseLine(Beatmap beatmap, Section section, string line)
|
|
|
|
|
{
|
2018-07-16 07:54:20 +08:00
|
|
|
|
var strippedLine = StripComments(line);
|
2018-07-16 07:04:41 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
switch (section)
|
|
|
|
|
{
|
|
|
|
|
case Section.General:
|
2018-07-16 07:54:20 +08:00
|
|
|
|
handleGeneral(strippedLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Section.Editor:
|
2018-07-16 07:54:20 +08:00
|
|
|
|
handleEditor(strippedLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Section.Metadata:
|
|
|
|
|
handleMetadata(line);
|
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Section.Difficulty:
|
2018-07-16 07:54:20 +08:00
|
|
|
|
handleDifficulty(strippedLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Section.Events:
|
2018-07-16 07:54:20 +08:00
|
|
|
|
handleEvent(strippedLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Section.TimingPoints:
|
2018-07-16 07:54:20 +08:00
|
|
|
|
handleTimingPoint(strippedLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case Section.HitObjects:
|
2018-07-16 07:54:20 +08:00
|
|
|
|
handleHitObject(strippedLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.ParseLine(beatmap, section, line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleGeneral(string line)
|
|
|
|
|
{
|
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
|
|
var metadata = beatmap.BeatmapInfo.Metadata;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
switch (pair.Key)
|
|
|
|
|
{
|
|
|
|
|
case @"AudioFilename":
|
2018-10-09 23:49:18 +08:00
|
|
|
|
metadata.AudioFile = FileSafety.PathStandardise(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"AudioLeadIn":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.AudioLeadIn = Parsing.ParseInt(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"PreviewTime":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
metadata.PreviewTime = getOffsetTime(Parsing.ParseInt(pair.Value));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Countdown":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.Countdown = Parsing.ParseInt(pair.Value) == 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"SampleSet":
|
|
|
|
|
defaultSampleBank = (LegacySampleBank)Enum.Parse(typeof(LegacySampleBank), pair.Value);
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"SampleVolume":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
defaultSampleVolume = Parsing.ParseInt(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"StackLeniency":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.StackLeniency = Parsing.ParseFloat(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Mode":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.RulesetID = Parsing.ParseInt(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
switch (beatmap.BeatmapInfo.RulesetID)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2018-08-15 09:24:56 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Osu.ConvertHitObjectParser(getOffsetTime(), FormatVersion);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case 1:
|
2018-08-15 09:24:56 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Taiko.ConvertHitObjectParser(getOffsetTime(), FormatVersion);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case 2:
|
2018-08-15 09:24:56 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Catch.ConvertHitObjectParser(getOffsetTime(), FormatVersion);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case 3:
|
2018-08-15 09:24:56 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Mania.ConvertHitObjectParser(getOffsetTime(), FormatVersion);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-08 14:26:27 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"LetterboxInBreaks":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.LetterboxInBreaks = Parsing.ParseInt(pair.Value) == 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"SpecialStyle":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.SpecialStyle = Parsing.ParseInt(pair.Value) == 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"WidescreenStoryboard":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.WidescreenStoryboard = Parsing.ParseInt(pair.Value) == 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleEditor(string line)
|
|
|
|
|
{
|
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
|
|
switch (pair.Key)
|
|
|
|
|
{
|
|
|
|
|
case @"Bookmarks":
|
|
|
|
|
beatmap.BeatmapInfo.StoredBookmarks = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"DistanceSpacing":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.DistanceSpacing = Math.Max(0, Parsing.ParseDouble(pair.Value));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"BeatDivisor":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.BeatDivisor = Parsing.ParseInt(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"GridSize":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.GridSize = Parsing.ParseInt(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"TimelineZoom":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.TimelineZoom = Math.Max(0, Parsing.ParseDouble(pair.Value));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleMetadata(string line)
|
|
|
|
|
{
|
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
|
|
var metadata = beatmap.BeatmapInfo.Metadata;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
switch (pair.Key)
|
|
|
|
|
{
|
|
|
|
|
case @"Title":
|
|
|
|
|
metadata.Title = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"TitleUnicode":
|
|
|
|
|
metadata.TitleUnicode = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Artist":
|
|
|
|
|
metadata.Artist = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"ArtistUnicode":
|
|
|
|
|
metadata.ArtistUnicode = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Creator":
|
|
|
|
|
metadata.AuthorString = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Version":
|
|
|
|
|
beatmap.BeatmapInfo.Version = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Source":
|
|
|
|
|
beatmap.BeatmapInfo.Metadata.Source = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"Tags":
|
|
|
|
|
beatmap.BeatmapInfo.Metadata.Tags = pair.Value;
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"BeatmapID":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.OnlineBeatmapID = Parsing.ParseInt(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"BeatmapSetID":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
beatmap.BeatmapInfo.BeatmapSet = new BeatmapSetInfo { OnlineBeatmapSetID = Parsing.ParseInt(pair.Value) };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleDifficulty(string line)
|
|
|
|
|
{
|
|
|
|
|
var pair = SplitKeyVal(line);
|
|
|
|
|
|
|
|
|
|
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
switch (pair.Key)
|
|
|
|
|
{
|
|
|
|
|
case @"HPDrainRate":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
difficulty.DrainRate = Parsing.ParseFloat(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"CircleSize":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
difficulty.CircleSize = Parsing.ParseFloat(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"OverallDifficulty":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
difficulty.OverallDifficulty = Parsing.ParseFloat(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"ApproachRate":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
difficulty.ApproachRate = Parsing.ParseFloat(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"SliderMultiplier":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
difficulty.SliderMultiplier = Parsing.ParseDouble(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case @"SliderTickRate":
|
2019-03-13 12:56:31 +08:00
|
|
|
|
difficulty.SliderTickRate = Parsing.ParseDouble(pair.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleEvent(string line)
|
|
|
|
|
{
|
|
|
|
|
string[] split = line.Split(',');
|
|
|
|
|
|
|
|
|
|
EventType type;
|
2019-08-05 18:56:35 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (!Enum.TryParse(split[0], out type))
|
2019-08-08 13:44:04 +08:00
|
|
|
|
throw new InvalidDataException($@"Unknown event type: {split[0]}");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case EventType.Background:
|
2019-08-31 04:19:34 +08:00
|
|
|
|
string bgFilename = split[2].Trim('"');
|
|
|
|
|
beatmap.BeatmapInfo.Metadata.BackgroundFile = FileSafety.PathStandardise(bgFilename);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EventType.Video:
|
|
|
|
|
string videoFilename = split[2].Trim('"');
|
|
|
|
|
beatmap.BeatmapInfo.Metadata.VideoFile = FileSafety.PathStandardise(videoFilename);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case EventType.Break:
|
2019-03-13 12:56:31 +08:00
|
|
|
|
double start = getOffsetTime(Parsing.ParseDouble(split[1]));
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
var breakEvent = new BreakPeriod
|
|
|
|
|
{
|
2019-03-13 12:56:31 +08:00
|
|
|
|
StartTime = start,
|
2019-03-13 13:22:16 +08:00
|
|
|
|
EndTime = Math.Max(start, getOffsetTime(Parsing.ParseDouble(split[2])))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!breakEvent.HasEffect)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
beatmap.Breaks.Add(breakEvent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleTimingPoint(string line)
|
|
|
|
|
{
|
2019-08-08 13:44:04 +08:00
|
|
|
|
string[] split = line.Split(',');
|
|
|
|
|
|
|
|
|
|
double time = getOffsetTime(Parsing.ParseDouble(split[0].Trim()));
|
|
|
|
|
double beatLength = Parsing.ParseDouble(split[1].Trim());
|
|
|
|
|
double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;
|
|
|
|
|
|
|
|
|
|
TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
|
|
|
|
|
if (split.Length >= 3)
|
|
|
|
|
timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)Parsing.ParseInt(split[2]);
|
|
|
|
|
|
|
|
|
|
LegacySampleBank sampleSet = defaultSampleBank;
|
|
|
|
|
if (split.Length >= 4)
|
|
|
|
|
sampleSet = (LegacySampleBank)Parsing.ParseInt(split[3]);
|
|
|
|
|
|
|
|
|
|
int customSampleBank = 0;
|
|
|
|
|
if (split.Length >= 5)
|
|
|
|
|
customSampleBank = Parsing.ParseInt(split[4]);
|
|
|
|
|
|
|
|
|
|
int sampleVolume = defaultSampleVolume;
|
|
|
|
|
if (split.Length >= 6)
|
|
|
|
|
sampleVolume = Parsing.ParseInt(split[5]);
|
|
|
|
|
|
|
|
|
|
bool timingChange = true;
|
|
|
|
|
if (split.Length >= 7)
|
|
|
|
|
timingChange = split[6][0] == '1';
|
|
|
|
|
|
|
|
|
|
bool kiaiMode = false;
|
|
|
|
|
bool omitFirstBarSignature = false;
|
|
|
|
|
|
|
|
|
|
if (split.Length >= 8)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-08-08 13:44:04 +08:00
|
|
|
|
EffectFlags effectFlags = (EffectFlags)Parsing.ParseInt(split[7]);
|
|
|
|
|
kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
|
|
|
|
|
omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2019-08-08 13:44:04 +08:00
|
|
|
|
|
|
|
|
|
string stringSampleSet = sampleSet.ToString().ToLowerInvariant();
|
|
|
|
|
if (stringSampleSet == @"none")
|
|
|
|
|
stringSampleSet = @"normal";
|
|
|
|
|
|
|
|
|
|
if (timingChange)
|
2019-03-13 10:30:33 +08:00
|
|
|
|
{
|
2019-08-08 13:44:04 +08:00
|
|
|
|
var controlPoint = CreateTimingControlPoint();
|
|
|
|
|
controlPoint.Time = time;
|
|
|
|
|
controlPoint.BeatLength = beatLength;
|
|
|
|
|
controlPoint.TimeSignature = timeSignature;
|
|
|
|
|
|
|
|
|
|
handleTimingControlPoint(controlPoint);
|
2019-03-13 10:30:33 +08:00
|
|
|
|
}
|
2019-08-08 13:44:04 +08:00
|
|
|
|
|
|
|
|
|
handleDifficultyControlPoint(new DifficultyControlPoint
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-08-08 13:44:04 +08:00
|
|
|
|
Time = time,
|
|
|
|
|
SpeedMultiplier = speedMultiplier,
|
|
|
|
|
AutoGenerated = timingChange
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
handleEffectControlPoint(new EffectControlPoint
|
|
|
|
|
{
|
|
|
|
|
Time = time,
|
|
|
|
|
KiaiMode = kiaiMode,
|
|
|
|
|
OmitFirstBarLine = omitFirstBarSignature,
|
|
|
|
|
AutoGenerated = timingChange
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
handleSampleControlPoint(new LegacySampleControlPoint
|
|
|
|
|
{
|
|
|
|
|
Time = time,
|
|
|
|
|
SampleBank = stringSampleSet,
|
|
|
|
|
SampleVolume = sampleVolume,
|
|
|
|
|
CustomSampleBank = customSampleBank,
|
|
|
|
|
AutoGenerated = timingChange
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 17:08:46 +08:00
|
|
|
|
private void handleTimingControlPoint(TimingControlPoint newPoint)
|
|
|
|
|
{
|
2018-08-14 10:44:53 +08:00
|
|
|
|
var existing = beatmap.ControlPointInfo.TimingPointAt(newPoint.Time);
|
|
|
|
|
|
|
|
|
|
if (existing.Time == newPoint.Time)
|
2019-05-13 18:04:12 +08:00
|
|
|
|
{
|
|
|
|
|
// autogenerated points should not replace non-autogenerated.
|
|
|
|
|
// this allows for incorrectly ordered timing points to still be correctly handled.
|
|
|
|
|
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
beatmap.ControlPointInfo.TimingPoints.Remove(existing);
|
2019-05-13 18:04:12 +08:00
|
|
|
|
}
|
2018-08-14 10:44:53 +08:00
|
|
|
|
|
2018-06-28 17:08:46 +08:00
|
|
|
|
beatmap.ControlPointInfo.TimingPoints.Add(newPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleDifficultyControlPoint(DifficultyControlPoint newPoint)
|
|
|
|
|
{
|
|
|
|
|
var existing = beatmap.ControlPointInfo.DifficultyPointAt(newPoint.Time);
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
if (existing.Time == newPoint.Time)
|
2019-05-13 18:04:12 +08:00
|
|
|
|
{
|
|
|
|
|
// autogenerated points should not replace non-autogenerated.
|
|
|
|
|
// this allows for incorrectly ordered timing points to still be correctly handled.
|
|
|
|
|
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
beatmap.ControlPointInfo.DifficultyPoints.Remove(existing);
|
2019-05-13 18:04:12 +08:00
|
|
|
|
}
|
2018-08-14 10:44:53 +08:00
|
|
|
|
|
2018-06-28 17:08:46 +08:00
|
|
|
|
beatmap.ControlPointInfo.DifficultyPoints.Add(newPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleEffectControlPoint(EffectControlPoint newPoint)
|
|
|
|
|
{
|
|
|
|
|
var existing = beatmap.ControlPointInfo.EffectPointAt(newPoint.Time);
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
if (existing.Time == newPoint.Time)
|
2019-05-13 18:04:12 +08:00
|
|
|
|
{
|
|
|
|
|
// autogenerated points should not replace non-autogenerated.
|
|
|
|
|
// this allows for incorrectly ordered timing points to still be correctly handled.
|
|
|
|
|
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
beatmap.ControlPointInfo.EffectPoints.Remove(existing);
|
2019-05-13 18:04:12 +08:00
|
|
|
|
}
|
2018-08-14 10:44:53 +08:00
|
|
|
|
|
2018-06-28 17:08:46 +08:00
|
|
|
|
beatmap.ControlPointInfo.EffectPoints.Add(newPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleSampleControlPoint(SampleControlPoint newPoint)
|
|
|
|
|
{
|
|
|
|
|
var existing = beatmap.ControlPointInfo.SamplePointAt(newPoint.Time);
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
if (existing.Time == newPoint.Time)
|
2019-05-13 18:04:12 +08:00
|
|
|
|
{
|
|
|
|
|
// autogenerated points should not replace non-autogenerated.
|
|
|
|
|
// this allows for incorrectly ordered timing points to still be correctly handled.
|
|
|
|
|
if (newPoint.AutoGenerated && !existing.AutoGenerated)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-08-14 10:44:53 +08:00
|
|
|
|
beatmap.ControlPointInfo.SamplePoints.Remove(existing);
|
2019-05-13 18:04:12 +08:00
|
|
|
|
}
|
2018-08-14 10:44:53 +08:00
|
|
|
|
|
2018-06-28 17:08:46 +08:00
|
|
|
|
beatmap.ControlPointInfo.SamplePoints.Add(newPoint);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private void handleHitObject(string line)
|
|
|
|
|
{
|
|
|
|
|
// If the ruleset wasn't specified, assume the osu!standard ruleset.
|
|
|
|
|
if (parser == null)
|
2018-08-15 09:24:56 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Osu.ConvertHitObjectParser(getOffsetTime(), FormatVersion);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-15 09:24:56 +08:00
|
|
|
|
var obj = parser.Parse(line);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (obj != null)
|
|
|
|
|
beatmap.HitObjects.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getOffsetTime(int time) => time + (ApplyOffsets ? offset : 0);
|
|
|
|
|
|
2018-04-30 15:43:32 +08:00
|
|
|
|
private double getOffsetTime() => ApplyOffsets ? offset : 0;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private double getOffsetTime(double time) => time + (ApplyOffsets ? offset : 0);
|
2018-07-16 15:26:37 +08:00
|
|
|
|
|
2018-10-09 10:34:38 +08:00
|
|
|
|
protected virtual TimingControlPoint CreateTimingControlPoint() => new TimingControlPoint();
|
|
|
|
|
|
2018-07-16 15:26:37 +08:00
|
|
|
|
[Flags]
|
|
|
|
|
internal enum EffectFlags
|
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
Kiai = 1,
|
|
|
|
|
OmitFirstBarLine = 8
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|