1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02:54 +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.Rulesets.Objects.Legacy;
using osu.Game.Beatmaps.ControlPoints;
using System.Collections.Generic;
namespace osu.Game.Beatmaps.Formats
{
@ -82,9 +81,6 @@ namespace osu.Game.Beatmaps.Formats
case Section.HitObjects:
handleHitObjects(line);
break;
case Section.Variables:
handleVariables(line);
break;
}
}
@ -242,8 +238,6 @@ namespace osu.Game.Beatmaps.Formats
private void handleEvents(string line)
{
DecodeVariables(ref line);
string[] split = line.Split(',');
EventType type;
@ -400,22 +394,5 @@ namespace osu.Game.Beatmaps.Formats
if (obj != null)
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 readonly Dictionary<string, string> Variables = new Dictionary<string, string>();
public override Decoder GetStoryboardDecoder() => new LegacyStoryboardDecoder(BeatmapVersion);
@ -82,27 +81,15 @@ namespace osu.Game.Beatmaps.Formats
protected abstract void ProcessSection(Section section, string line);
/// <summary>
/// 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)
protected KeyValuePair<string, string> splitKeyVal(string line, char separator)
{
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];
}
var split = line.Trim().Split(new[] { separator }, 2);
line = string.Join(",", split);
if (line == origLine)
break;
}
return new KeyValuePair<string, string>
(
split[0].Trim(),
split.Length > 1 ? split[1].Trim() : string.Empty
);
}
protected enum Section

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using OpenTK;
@ -19,6 +20,8 @@ namespace osu.Game.Beatmaps.Formats
private StoryboardSprite storyboardSprite;
private CommandTimelineGroup timelineGroup;
private readonly Dictionary<string, string> Variables = new Dictionary<string, string>();
public LegacyStoryboardDecoder()
{
}
@ -47,6 +50,9 @@ namespace osu.Game.Beatmaps.Formats
case Section.Events:
handleEvents(line);
break;
case Section.Variables:
handleVariables(line);
break;
}
}
@ -266,6 +272,35 @@ namespace osu.Game.Beatmaps.Formats
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('\"'));
}
}