2017-02-07 12:59:30 +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
|
2016-12-06 17:56:20 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2017-05-27 12:55:34 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-13 01:26:09 +08:00
|
|
|
|
using System.Globalization;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using System.IO;
|
2016-10-11 01:00:16 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2016-10-08 03:09:52 +08:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2017-03-17 13:24:46 +08:00
|
|
|
|
using osu.Game.Beatmaps.Legacy;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
2017-05-23 12:55:18 +08:00
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
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()
|
|
|
|
|
{
|
2016-10-13 01:36:10 +08:00
|
|
|
|
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");
|
2016-10-14 01:49:44 +08:00
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v9");
|
2016-12-21 16:29:57 +08:00
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v8");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v7");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v6");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v5");
|
2017-08-10 10:21:43 +08:00
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v4");
|
|
|
|
|
AddDecoder<OsuLegacyDecoder>(@"osu file format v3");
|
|
|
|
|
// TODO: differences between versions
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
2016-10-08 03:36:20 +08:00
|
|
|
|
|
2017-04-22 20:33:11 +08:00
|
|
|
|
private ConvertHitObjectParser parser;
|
2017-04-17 16:23:11 +08:00
|
|
|
|
|
2017-05-27 13:13:46 +08:00
|
|
|
|
private readonly Dictionary<string, string> variables = new Dictionary<string, string>();
|
2017-05-27 12:55:34 +08:00
|
|
|
|
|
2017-04-05 20:59:40 +08:00
|
|
|
|
private LegacySampleBank defaultSampleBank;
|
2017-04-04 13:31:50 +08:00
|
|
|
|
private int defaultSampleVolume = 100;
|
2017-04-04 12:11:04 +08:00
|
|
|
|
|
2017-04-03 19:26:46 +08:00
|
|
|
|
private readonly int beatmapVersion;
|
|
|
|
|
|
|
|
|
|
public OsuLegacyDecoder()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OsuLegacyDecoder(string header)
|
|
|
|
|
{
|
|
|
|
|
beatmapVersion = int.Parse(header.Substring(17));
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 03:36:20 +08:00
|
|
|
|
private enum Section
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
General,
|
|
|
|
|
Editor,
|
|
|
|
|
Metadata,
|
|
|
|
|
Difficulty,
|
|
|
|
|
Events,
|
|
|
|
|
TimingPoints,
|
|
|
|
|
Colours,
|
|
|
|
|
HitObjects,
|
2017-05-27 12:55:34 +08:00
|
|
|
|
Variables,
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
2016-10-08 03:36:20 +08:00
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private void handleGeneral(Beatmap beatmap, string line)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2017-05-30 19:59:46 +08:00
|
|
|
|
var pair = splitKeyVal(line, ':');
|
|
|
|
|
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var metadata = beatmap.BeatmapInfo.Metadata;
|
2017-05-30 19:59:46 +08:00
|
|
|
|
switch (pair.Key)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"AudioFilename":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.AudioFile = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"AudioLeadIn":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.AudioLeadIn = int.Parse(pair.Value);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"PreviewTime":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.PreviewTime = int.Parse(pair.Value);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Countdown":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.Countdown = int.Parse(pair.Value) == 1;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"SampleSet":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
defaultSampleBank = (LegacySampleBank)Enum.Parse(typeof(LegacySampleBank), pair.Value);
|
2017-04-04 12:11:04 +08:00
|
|
|
|
break;
|
|
|
|
|
case @"SampleVolume":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
defaultSampleVolume = int.Parse(pair.Value);
|
2017-04-04 12:11:04 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"StackLeniency":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.StackLeniency = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Mode":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.RulesetID = int.Parse(pair.Value);
|
2017-04-17 16:23:11 +08:00
|
|
|
|
|
2017-04-18 08:00:53 +08:00
|
|
|
|
switch (beatmap.BeatmapInfo.RulesetID)
|
2017-04-17 16:23:11 +08:00
|
|
|
|
{
|
|
|
|
|
case 0:
|
2017-04-22 20:33:11 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Osu.ConvertHitObjectParser();
|
2017-04-17 16:23:11 +08:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2017-04-22 20:33:11 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Taiko.ConvertHitObjectParser();
|
2017-04-17 16:23:11 +08:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2017-04-22 20:33:11 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Catch.ConvertHitObjectParser();
|
2017-04-17 16:23:11 +08:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2017-04-22 20:33:11 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Mania.ConvertHitObjectParser();
|
2017-04-17 16:23:11 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"LetterboxInBreaks":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.LetterboxInBreaks = int.Parse(pair.Value) == 1;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"SpecialStyle":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.SpecialStyle = int.Parse(pair.Value) == 1;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"WidescreenStoryboard":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.WidescreenStoryboard = int.Parse(pair.Value) == 1;
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private void handleEditor(Beatmap beatmap, string line)
|
2016-10-08 04:19:24 +08:00
|
|
|
|
{
|
2017-05-30 19:59:46 +08:00
|
|
|
|
var pair = splitKeyVal(line, ':');
|
|
|
|
|
|
|
|
|
|
switch (pair.Key)
|
2016-10-08 04:19:24 +08:00
|
|
|
|
{
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Bookmarks":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.StoredBookmarks = pair.Value;
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"DistanceSpacing":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.DistanceSpacing = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"BeatDivisor":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.BeatDivisor = int.Parse(pair.Value);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"GridSize":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.GridSize = int.Parse(pair.Value);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"TimelineZoom":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.TimelineZoom = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private void handleMetadata(Beatmap beatmap, string line)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2017-05-30 19:59:46 +08:00
|
|
|
|
var pair = splitKeyVal(line, ':');
|
|
|
|
|
|
2016-10-19 01:35:01 +08:00
|
|
|
|
var metadata = beatmap.BeatmapInfo.Metadata;
|
2017-05-30 19:59:46 +08:00
|
|
|
|
switch (pair.Key)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Title":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.Title = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"TitleUnicode":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.TitleUnicode = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Artist":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.Artist = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"ArtistUnicode":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.ArtistUnicode = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Creator":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
metadata.Author = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Version":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.Version = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Source":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.Metadata.Source = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"Tags":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.Metadata.Tags = pair.Value;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"BeatmapID":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.OnlineBeatmapID = int.Parse(pair.Value);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"BeatmapSetID":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.OnlineBeatmapSetID = int.Parse(pair.Value);
|
|
|
|
|
metadata.OnlineBeatmapSetID = int.Parse(pair.Value);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private void handleDifficulty(Beatmap beatmap, string line)
|
2016-10-08 04:19:24 +08:00
|
|
|
|
{
|
2017-05-30 19:59:46 +08:00
|
|
|
|
var pair = splitKeyVal(line, ':');
|
|
|
|
|
|
2017-03-16 22:18:02 +08:00
|
|
|
|
var difficulty = beatmap.BeatmapInfo.Difficulty;
|
2017-05-30 19:59:46 +08:00
|
|
|
|
switch (pair.Key)
|
2016-10-08 04:19:24 +08:00
|
|
|
|
{
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"HPDrainRate":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
difficulty.DrainRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"CircleSize":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
difficulty.CircleSize = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"OverallDifficulty":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
difficulty.OverallDifficulty = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"ApproachRate":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
difficulty.ApproachRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"SliderMultiplier":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
difficulty.SliderMultiplier = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
2016-10-13 01:36:10 +08:00
|
|
|
|
case @"SliderTickRate":
|
2017-05-30 19:59:46 +08:00
|
|
|
|
difficulty.SliderTickRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo);
|
2016-10-08 04:19:24 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 18:52:21 +08:00
|
|
|
|
/// <summary>
|
2017-05-30 18:52:43 +08:00
|
|
|
|
/// Decodes any beatmap variables present in a line into their real values.
|
2017-05-30 18:52:21 +08:00
|
|
|
|
/// </summary>
|
2017-05-30 18:52:43 +08:00
|
|
|
|
/// <param name="line">The line which may contains variables.</param>
|
|
|
|
|
private void decodeVariables(ref string line)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2017-08-13 13:40:05 +08:00
|
|
|
|
while (line.IndexOf('$') >= 0)
|
2017-05-27 13:20:19 +08:00
|
|
|
|
{
|
2017-08-13 13:40:05 +08:00
|
|
|
|
string origLine = line;
|
2017-05-30 18:52:43 +08:00
|
|
|
|
string[] split = line.Split(',');
|
2017-05-30 18:52:21 +08:00
|
|
|
|
for (int i = 0; i < split.Length; i++)
|
2017-05-27 13:20:19 +08:00
|
|
|
|
{
|
2017-05-30 18:52:21 +08:00
|
|
|
|
var item = split[i];
|
|
|
|
|
if (item.StartsWith("$") && variables.ContainsKey(item))
|
2017-05-30 19:26:39 +08:00
|
|
|
|
split[i] = variables[item];
|
2017-05-27 13:20:19 +08:00
|
|
|
|
}
|
2017-05-30 18:52:21 +08:00
|
|
|
|
|
2017-05-30 18:52:43 +08:00
|
|
|
|
line = string.Join(",", split);
|
2017-08-13 13:40:05 +08:00
|
|
|
|
if (line == origLine) break;
|
2017-05-30 18:52:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 18:52:43 +08:00
|
|
|
|
private void handleEvents(Beatmap beatmap, string line)
|
2017-05-30 18:52:21 +08:00
|
|
|
|
{
|
2017-05-30 18:52:43 +08:00
|
|
|
|
decodeVariables(ref line);
|
2017-05-27 13:20:19 +08:00
|
|
|
|
|
2017-05-30 18:52:43 +08:00
|
|
|
|
string[] split = line.Split(',');
|
2017-05-17 17:42:48 +08:00
|
|
|
|
|
2016-10-08 03:36:20 +08:00
|
|
|
|
EventType type;
|
2017-05-17 17:42:48 +08:00
|
|
|
|
if (!Enum.TryParse(split[0], out type))
|
|
|
|
|
throw new InvalidDataException($@"Unknown event type {split[0]}");
|
|
|
|
|
|
|
|
|
|
// Todo: Implement the rest
|
|
|
|
|
switch (type)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2017-05-17 17:42:48 +08:00
|
|
|
|
case EventType.Video:
|
|
|
|
|
case EventType.Background:
|
|
|
|
|
string filename = split[2].Trim('"');
|
|
|
|
|
|
|
|
|
|
if (type == EventType.Background)
|
|
|
|
|
beatmap.BeatmapInfo.Metadata.BackgroundFile = filename;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case EventType.Break:
|
2017-05-22 09:12:33 +08:00
|
|
|
|
var breakEvent = new BreakPeriod
|
2017-05-17 17:42:48 +08:00
|
|
|
|
{
|
|
|
|
|
StartTime = double.Parse(split[1], NumberFormatInfo.InvariantInfo),
|
|
|
|
|
EndTime = double.Parse(split[2], NumberFormatInfo.InvariantInfo)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!breakEvent.HasEffect)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-05-22 09:12:33 +08:00
|
|
|
|
beatmap.Breaks.Add(breakEvent);
|
2017-05-17 17:42:48 +08:00
|
|
|
|
break;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
}
|
2016-10-08 03:09:52 +08:00
|
|
|
|
}
|
2016-10-05 04:29:08 +08:00
|
|
|
|
|
2017-05-30 18:52:43 +08:00
|
|
|
|
private void handleTimingPoints(Beatmap beatmap, string line)
|
2016-10-08 04:19:24 +08:00
|
|
|
|
{
|
2017-05-30 18:52:43 +08:00
|
|
|
|
string[] split = line.Split(',');
|
2016-11-28 14:12:11 +08:00
|
|
|
|
|
2017-04-04 12:11:04 +08:00
|
|
|
|
double time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo);
|
|
|
|
|
double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);
|
2017-08-21 10:45:57 +08:00
|
|
|
|
double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;
|
2017-04-04 12:11:04 +08:00
|
|
|
|
|
|
|
|
|
TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
|
|
|
|
|
if (split.Length >= 3)
|
|
|
|
|
timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]);
|
|
|
|
|
|
2017-04-05 20:59:40 +08:00
|
|
|
|
LegacySampleBank sampleSet = defaultSampleBank;
|
2017-04-04 12:11:04 +08:00
|
|
|
|
if (split.Length >= 4)
|
2017-04-05 20:59:40 +08:00
|
|
|
|
sampleSet = (LegacySampleBank)int.Parse(split[3]);
|
2017-04-04 12:11:04 +08:00
|
|
|
|
|
2017-04-05 20:59:40 +08:00
|
|
|
|
//SampleBank sampleBank = SampleBank.Default;
|
|
|
|
|
//if (split.Length >= 5)
|
|
|
|
|
// sampleBank = (SampleBank)int.Parse(split[4]);
|
2017-04-04 12:11:04 +08:00
|
|
|
|
|
|
|
|
|
int sampleVolume = defaultSampleVolume;
|
|
|
|
|
if (split.Length >= 6)
|
|
|
|
|
sampleVolume = int.Parse(split[5]);
|
|
|
|
|
|
|
|
|
|
bool timingChange = true;
|
|
|
|
|
if (split.Length >= 7)
|
|
|
|
|
timingChange = split[6][0] == '1';
|
|
|
|
|
|
|
|
|
|
bool kiaiMode = false;
|
|
|
|
|
bool omitFirstBarSignature = false;
|
|
|
|
|
if (split.Length >= 8)
|
2016-11-28 14:12:11 +08:00
|
|
|
|
{
|
2017-04-04 12:11:04 +08:00
|
|
|
|
int effectFlags = int.Parse(split[7]);
|
|
|
|
|
kiaiMode = (effectFlags & 1) > 0;
|
|
|
|
|
omitFirstBarSignature = (effectFlags & 8) > 0;
|
2016-11-28 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 10:41:16 +08:00
|
|
|
|
string stringSampleSet = sampleSet.ToString().ToLower();
|
2017-04-06 10:54:11 +08:00
|
|
|
|
if (stringSampleSet == @"none")
|
|
|
|
|
stringSampleSet = @"normal";
|
2017-04-06 10:41:16 +08:00
|
|
|
|
|
2017-05-23 12:55:18 +08:00
|
|
|
|
DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time);
|
|
|
|
|
SoundControlPoint soundPoint = beatmap.ControlPointInfo.SoundPointAt(time);
|
|
|
|
|
EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time);
|
|
|
|
|
|
2017-05-23 14:26:07 +08:00
|
|
|
|
if (timingChange)
|
2017-05-23 12:55:18 +08:00
|
|
|
|
{
|
2017-05-23 14:20:32 +08:00
|
|
|
|
beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint
|
2017-05-23 12:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
Time = time,
|
|
|
|
|
BeatLength = beatLength,
|
|
|
|
|
TimeSignature = timeSignature
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (speedMultiplier != difficultyPoint.SpeedMultiplier)
|
2017-04-04 12:11:04 +08:00
|
|
|
|
{
|
2017-08-17 21:58:26 +08:00
|
|
|
|
beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == time);
|
2017-05-23 14:20:32 +08:00
|
|
|
|
beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint
|
2017-05-23 12:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
Time = time,
|
|
|
|
|
SpeedMultiplier = speedMultiplier
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stringSampleSet != soundPoint.SampleBank || sampleVolume != soundPoint.SampleVolume)
|
|
|
|
|
{
|
2017-05-23 14:20:32 +08:00
|
|
|
|
beatmap.ControlPointInfo.SoundPoints.Add(new SoundControlPoint
|
2017-05-23 12:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
Time = time,
|
|
|
|
|
SampleBank = stringSampleSet,
|
|
|
|
|
SampleVolume = sampleVolume
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine)
|
|
|
|
|
{
|
2017-05-23 14:20:32 +08:00
|
|
|
|
beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint
|
2017-05-23 12:55:18 +08:00
|
|
|
|
{
|
|
|
|
|
Time = time,
|
|
|
|
|
KiaiMode = kiaiMode,
|
|
|
|
|
OmitFirstBarLine = omitFirstBarSignature
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-08 04:19:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private void handleColours(Beatmap beatmap, string line, ref bool hasCustomColours)
|
2016-10-11 01:00:16 +08:00
|
|
|
|
{
|
2017-05-30 19:59:46 +08:00
|
|
|
|
var pair = splitKeyVal(line, ':');
|
|
|
|
|
|
|
|
|
|
string[] split = pair.Value.Split(',');
|
2017-03-14 13:48:32 +08:00
|
|
|
|
|
2016-10-11 01:00:16 +08:00
|
|
|
|
if (split.Length != 3)
|
2017-05-30 19:59:46 +08:00
|
|
|
|
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {pair.Value}");
|
2017-03-14 13:48:32 +08:00
|
|
|
|
|
2016-10-11 01:00:16 +08:00
|
|
|
|
byte r, g, b;
|
|
|
|
|
if (!byte.TryParse(split[0], out r) || !byte.TryParse(split[1], out g) || !byte.TryParse(split[2], out b))
|
2017-03-07 09:59:19 +08:00
|
|
|
|
throw new InvalidOperationException(@"Color must be specified with 8-bit integer components");
|
2017-03-14 13:48:32 +08:00
|
|
|
|
|
|
|
|
|
if (!hasCustomColours)
|
|
|
|
|
{
|
|
|
|
|
beatmap.ComboColors.Clear();
|
|
|
|
|
hasCustomColours = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 01:00:16 +08:00
|
|
|
|
// Note: the combo index specified in the beatmap is discarded
|
2017-05-30 19:59:46 +08:00
|
|
|
|
if (pair.Key.StartsWith(@"Combo"))
|
2016-10-11 01:00:16 +08:00
|
|
|
|
{
|
2017-03-07 09:59:19 +08:00
|
|
|
|
beatmap.ComboColors.Add(new Color4
|
|
|
|
|
{
|
|
|
|
|
R = r / 255f,
|
|
|
|
|
G = g / 255f,
|
|
|
|
|
B = b / 255f,
|
|
|
|
|
A = 1f,
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-11 01:00:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private void handleVariables(string line)
|
|
|
|
|
{
|
|
|
|
|
var pair = splitKeyVal(line, '=');
|
|
|
|
|
variables[pair.Key] = pair.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 19:26:46 +08:00
|
|
|
|
protected override Beatmap ParseFile(StreamReader stream)
|
2017-03-17 13:24:46 +08:00
|
|
|
|
{
|
|
|
|
|
return new LegacyBeatmap(base.ParseFile(stream));
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 19:26:46 +08:00
|
|
|
|
public override Beatmap Decode(StreamReader stream)
|
2017-03-17 13:24:46 +08:00
|
|
|
|
{
|
|
|
|
|
return new LegacyBeatmap(base.Decode(stream));
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 19:26:46 +08:00
|
|
|
|
protected override void ParseFile(StreamReader stream, Beatmap beatmap)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
2017-04-03 19:26:46 +08:00
|
|
|
|
beatmap.BeatmapInfo.BeatmapVersion = beatmapVersion;
|
|
|
|
|
|
2017-04-03 19:33:10 +08:00
|
|
|
|
Section section = Section.None;
|
2017-03-14 13:48:32 +08:00
|
|
|
|
bool hasCustomColours = false;
|
|
|
|
|
|
2017-04-03 19:33:10 +08:00
|
|
|
|
string line;
|
2017-04-03 19:26:46 +08:00
|
|
|
|
while ((line = stream.ReadLine()) != null)
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
2017-04-03 19:26:46 +08:00
|
|
|
|
|
2017-05-17 17:42:48 +08:00
|
|
|
|
if (line.StartsWith(" ") || line.StartsWith("_") || line.StartsWith("//"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-10-13 01:36:10 +08:00
|
|
|
|
if (line.StartsWith(@"osu file format v"))
|
2017-04-03 19:26:46 +08:00
|
|
|
|
{
|
|
|
|
|
beatmap.BeatmapInfo.BeatmapVersion = int.Parse(line.Substring(17));
|
2016-10-10 22:17:18 +08:00
|
|
|
|
continue;
|
2017-04-03 19:26:46 +08:00
|
|
|
|
}
|
2016-11-14 21:03:39 +08:00
|
|
|
|
|
2016-10-13 01:36:10 +08:00
|
|
|
|
if (line.StartsWith(@"[") && line.EndsWith(@"]"))
|
2016-10-08 03:36:20 +08:00
|
|
|
|
{
|
|
|
|
|
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
|
|
|
|
|
throw new InvalidDataException($@"Unknown osu section {line}");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-11-14 21:03:39 +08:00
|
|
|
|
|
2016-10-08 03:36:20 +08:00
|
|
|
|
switch (section)
|
|
|
|
|
{
|
|
|
|
|
case Section.General:
|
2017-05-30 19:59:46 +08:00
|
|
|
|
handleGeneral(beatmap, line);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.Editor:
|
2017-05-30 19:59:46 +08:00
|
|
|
|
handleEditor(beatmap, line);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.Metadata:
|
2017-05-30 19:59:46 +08:00
|
|
|
|
handleMetadata(beatmap, line);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.Difficulty:
|
2017-05-30 19:59:46 +08:00
|
|
|
|
handleDifficulty(beatmap, line);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.Events:
|
2017-05-30 18:52:21 +08:00
|
|
|
|
handleEvents(beatmap, line);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case Section.TimingPoints:
|
2017-05-30 18:52:21 +08:00
|
|
|
|
handleTimingPoints(beatmap, line);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2016-10-11 01:00:16 +08:00
|
|
|
|
case Section.Colours:
|
2017-05-30 19:59:46 +08:00
|
|
|
|
handleColours(beatmap, line, ref hasCustomColours);
|
2016-10-11 01:00:16 +08:00
|
|
|
|
break;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
case Section.HitObjects:
|
2017-08-02 22:05:09 +08:00
|
|
|
|
|
|
|
|
|
// If the ruleset wasn't specified, assume the osu!standard ruleset.
|
2017-08-02 22:17:33 +08:00
|
|
|
|
if (parser == null)
|
2017-08-02 22:05:09 +08:00
|
|
|
|
parser = new Rulesets.Objects.Legacy.Osu.ConvertHitObjectParser();
|
|
|
|
|
|
2017-05-30 18:52:21 +08:00
|
|
|
|
var obj = parser.Parse(line);
|
2016-11-28 14:31:54 +08:00
|
|
|
|
|
2016-11-14 21:03:39 +08:00
|
|
|
|
if (obj != null)
|
|
|
|
|
beatmap.HitObjects.Add(obj);
|
2017-03-14 13:48:32 +08:00
|
|
|
|
|
2016-10-08 03:36:20 +08:00
|
|
|
|
break;
|
2017-05-27 12:55:34 +08:00
|
|
|
|
case Section.Variables:
|
2017-05-30 19:59:46 +08:00
|
|
|
|
handleVariables(line);
|
2017-05-27 12:55:34 +08:00
|
|
|
|
break;
|
2016-10-08 03:36:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-29 11:10:29 +08:00
|
|
|
|
|
|
|
|
|
foreach (var hitObject in beatmap.HitObjects)
|
|
|
|
|
hitObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.Difficulty);
|
2016-10-08 03:36:20 +08:00
|
|
|
|
}
|
2017-04-05 20:59:40 +08:00
|
|
|
|
|
2017-05-30 19:59:46 +08:00
|
|
|
|
private KeyValuePair<string, string> splitKeyVal(string line, char separator)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<string, string>
|
|
|
|
|
(
|
|
|
|
|
line.Remove(line.IndexOf(separator)).Trim(),
|
|
|
|
|
line.Substring(line.IndexOf(separator) + 1).Trim()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 08:43:47 +08:00
|
|
|
|
internal enum LegacySampleBank
|
2017-04-05 20:59:40 +08:00
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
Normal = 1,
|
|
|
|
|
Soft = 2,
|
|
|
|
|
Drum = 3
|
|
|
|
|
}
|
2017-05-17 17:42:48 +08:00
|
|
|
|
|
|
|
|
|
internal enum EventType
|
|
|
|
|
{
|
|
|
|
|
Background = 0,
|
|
|
|
|
Video = 1,
|
|
|
|
|
Break = 2,
|
|
|
|
|
Colour = 3,
|
|
|
|
|
Sprite = 4,
|
|
|
|
|
Sample = 5,
|
|
|
|
|
Animation = 6
|
|
|
|
|
}
|
2016-10-08 03:36:20 +08:00
|
|
|
|
}
|
2016-10-12 01:52:16 +08:00
|
|
|
|
}
|