1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 18:53:21 +08:00

move variables to StoryboardDecoder

This commit is contained in:
james58899 2018-01-04 19:04:52 +08:00
parent 6e8e82e264
commit dcc4e863ab
No known key found for this signature in database
GPG Key ID: 7F83E3A11DD5192E
3 changed files with 42 additions and 43 deletions

View File

@ -8,7 +8,6 @@ using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using System.Collections.Generic;
namespace osu.Game.Beatmaps.Formats namespace osu.Game.Beatmaps.Formats
{ {
@ -82,9 +81,6 @@ namespace osu.Game.Beatmaps.Formats
case Section.HitObjects: case Section.HitObjects:
handleHitObjects(line); handleHitObjects(line);
break; break;
case Section.Variables:
handleVariables(line);
break;
} }
} }
@ -242,8 +238,6 @@ namespace osu.Game.Beatmaps.Formats
private void handleEvents(string line) private void handleEvents(string line)
{ {
DecodeVariables(ref line);
string[] split = line.Split(','); string[] split = line.Split(',');
EventType type; EventType type;
@ -400,22 +394,5 @@ namespace osu.Game.Beatmaps.Formats
if (obj != null) if (obj != null)
beatmap.HitObjects.Add(obj); beatmap.HitObjects.Add(obj);
} }
private void handleVariables(string line)
{
var pair = splitKeyVal(line, '=');
Variables[pair.Key] = pair.Value;
}
private KeyValuePair<string, string> splitKeyVal(string line, char separator)
{
var split = line.Trim().Split(new[] { separator }, 2);
return new KeyValuePair<string, string>
(
split[0].Trim(),
split.Length > 1 ? split[1].Trim() : string.Empty
);
}
} }
} }

View File

@ -29,7 +29,6 @@ namespace osu.Game.Beatmaps.Formats
} }
protected int BeatmapVersion; protected int BeatmapVersion;
protected readonly Dictionary<string, string> Variables = new Dictionary<string, string>();
public override Decoder GetStoryboardDecoder() => new LegacyStoryboardDecoder(BeatmapVersion); public override Decoder GetStoryboardDecoder() => new LegacyStoryboardDecoder(BeatmapVersion);
@ -82,27 +81,15 @@ namespace osu.Game.Beatmaps.Formats
protected abstract void ProcessSection(Section section, string line); protected abstract void ProcessSection(Section section, string line);
/// <summary> protected KeyValuePair<string, string> splitKeyVal(string line, char separator)
/// Decodes any beatmap variables present in a line into their real values.
/// </summary>
/// <param name="line">The line which may contains variables.</param>
protected void DecodeVariables(ref string line)
{ {
while (line.IndexOf('$') >= 0) var split = line.Trim().Split(new[] { separator }, 2);
{
string origLine = line;
string[] split = line.Split(',');
for (int i = 0; i < split.Length; i++)
{
var item = split[i];
if (item.StartsWith("$") && Variables.ContainsKey(item))
split[i] = Variables[item];
}
line = string.Join(",", split); return new KeyValuePair<string, string>
if (line == origLine) (
break; split[0].Trim(),
} split.Length > 1 ? split[1].Trim() : string.Empty
);
} }
protected enum Section protected enum Section

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using OpenTK; using OpenTK;
@ -19,6 +20,8 @@ namespace osu.Game.Beatmaps.Formats
private StoryboardSprite storyboardSprite; private StoryboardSprite storyboardSprite;
private CommandTimelineGroup timelineGroup; private CommandTimelineGroup timelineGroup;
private readonly Dictionary<string, string> Variables = new Dictionary<string, string>();
public LegacyStoryboardDecoder() public LegacyStoryboardDecoder()
{ {
} }
@ -47,6 +50,9 @@ namespace osu.Game.Beatmaps.Formats
case Section.Events: case Section.Events:
handleEvents(line); handleEvents(line);
break; break;
case Section.Variables:
handleVariables(line);
break;
} }
} }
@ -266,6 +272,35 @@ namespace osu.Game.Beatmaps.Formats
throw new InvalidDataException($@"Unknown origin: {value}"); throw new InvalidDataException($@"Unknown origin: {value}");
} }
private void handleVariables(string line)
{
var pair = splitKeyVal(line, '=');
Variables[pair.Key] = pair.Value;
}
/// <summary>
/// Decodes any beatmap variables present in a line into their real values.
/// </summary>
/// <param name="line">The line which may contains variables.</param>
private void DecodeVariables(ref string line)
{
while (line.IndexOf('$') >= 0)
{
string origLine = line;
string[] split = line.Split(',');
for (int i = 0; i < split.Length; i++)
{
var item = split[i];
if (item.StartsWith("$") && Variables.ContainsKey(item))
split[i] = Variables[item];
}
line = string.Join(",", split);
if (line == origLine)
break;
}
}
private string cleanFilename(string path) => FileSafety.PathSanitise(path.Trim('\"')); private string cleanFilename(string path) => FileSafety.PathSanitise(path.Trim('\"'));
} }
} }