1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 13:23:05 +08:00

Strip comments from everything except metadata

This commit is contained in:
morguldir 2018-07-16 01:04:41 +02:00
parent a9f8c2acb8
commit 6c861a1638
4 changed files with 24 additions and 11 deletions

View File

@ -62,32 +62,34 @@ namespace osu.Game.Beatmaps.Formats
protected override void ParseLine(Beatmap beatmap, Section section, string line) protected override void ParseLine(Beatmap beatmap, Section section, string line)
{ {
var stripped_line = StripComments(line);
switch (section) switch (section)
{ {
case Section.General: case Section.General:
handleGeneral(line); handleGeneral(stripped_line);
return; return;
case Section.Editor: case Section.Editor:
handleEditor(line); handleEditor(stripped_line);
return; return;
case Section.Metadata: case Section.Metadata:
handleMetadata(line); handleMetadata(line);
return; return;
case Section.Difficulty: case Section.Difficulty:
handleDifficulty(line); handleDifficulty(stripped_line);
return; return;
case Section.Events: case Section.Events:
handleEvent(line); handleEvent(stripped_line);
return; return;
case Section.TimingPoints: case Section.TimingPoints:
handleTimingPoint(line); handleTimingPoint(stripped_line);
return; return;
case Section.HitObjects: case Section.HitObjects:
handleHitObject(line); handleHitObject(stripped_line);
return; return;
} }
base.ParseLine(beatmap, section, line); base.ParseLine(beatmap, section, stripped_line);
} }
private void handleGeneral(string line) private void handleGeneral(string line)

View File

@ -58,6 +58,8 @@ namespace osu.Game.Beatmaps.Formats
protected virtual void ParseLine(T output, Section section, string line) protected virtual void ParseLine(T output, Section section, string line)
{ {
line = StripComments(line);
switch (section) switch (section)
{ {
case Section.Colours: case Section.Colours:
@ -65,6 +67,13 @@ namespace osu.Game.Beatmaps.Formats
return; return;
} }
} }
internal string StripComments(string line)
{
var index = line.IndexOf("//");
if (index > 0)
return line.Substring(0, index);
return line;
}
private bool hasComboColours; private bool hasComboColours;
@ -74,12 +83,10 @@ namespace osu.Game.Beatmaps.Formats
bool isCombo = pair.Key.StartsWith(@"Combo"); bool isCombo = pair.Key.StartsWith(@"Combo");
line = Regex.Replace(pair.Value, "[^0-9,]", ""); string[] split = pair.Value.Split(',');
string[] split = line.Split(',');
if (split.Length != 3) if (split.Length != 3)
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {line}"); throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {pair.Value}");
if (!byte.TryParse(split[0], out var r) || !byte.TryParse(split[1], out var g) || !byte.TryParse(split[2], out var b)) if (!byte.TryParse(split[0], out var r) || !byte.TryParse(split[1], out var g) || !byte.TryParse(split[2], out var b))
throw new InvalidOperationException(@"Color must be specified with 8-bit integer components"); throw new InvalidOperationException(@"Color must be specified with 8-bit integer components");

View File

@ -42,6 +42,8 @@ namespace osu.Game.Beatmaps.Formats
protected override void ParseLine(Storyboard storyboard, Section section, string line) protected override void ParseLine(Storyboard storyboard, Section section, string line)
{ {
line = StripComments(line);
switch (section) switch (section)
{ {
case Section.Events: case Section.Events:

View File

@ -14,6 +14,8 @@ namespace osu.Game.Skinning
protected override void ParseLine(SkinConfiguration skin, Section section, string line) protected override void ParseLine(SkinConfiguration skin, Section section, string line)
{ {
line = StripComments(line);
switch (section) switch (section)
{ {
case Section.General: case Section.General: