1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-14 05:24:07 +08:00

Merge pull request #1854 from james58899/fix-storyboard-variables

Fix storyboard variable parsing
This commit is contained in:
Dean Herbert
2018-01-09 11:59:53 +09:00
committed by GitHub
Unverified
3 changed files with 48 additions and 49 deletions
@@ -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,15 +81,12 @@ namespace osu.Game.Beatmaps.Formats
case Section.HitObjects:
handleHitObjects(line);
break;
case Section.Variables:
handleVariables(line);
break;
}
}
private void handleGeneral(string line)
{
var pair = splitKeyVal(line, ':');
var pair = SplitKeyVal(line, ':');
var metadata = beatmap.BeatmapInfo.Metadata;
switch (pair.Key)
@@ -149,7 +145,7 @@ namespace osu.Game.Beatmaps.Formats
private void handleEditor(string line)
{
var pair = splitKeyVal(line, ':');
var pair = SplitKeyVal(line, ':');
switch (pair.Key)
{
@@ -173,7 +169,7 @@ namespace osu.Game.Beatmaps.Formats
private void handleMetadata(string line)
{
var pair = splitKeyVal(line, ':');
var pair = SplitKeyVal(line, ':');
var metadata = beatmap.BeatmapInfo.Metadata;
switch (pair.Key)
@@ -214,7 +210,7 @@ namespace osu.Game.Beatmaps.Formats
private void handleDifficulty(string line)
{
var pair = splitKeyVal(line, ':');
var pair = SplitKeyVal(line, ':');
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
switch (pair.Key)
@@ -242,8 +238,6 @@ namespace osu.Game.Beatmaps.Formats
private void handleEvents(string line)
{
DecodeVariables(ref line);
string[] split = line.Split(',');
EventType type;
@@ -359,7 +353,7 @@ namespace osu.Game.Beatmaps.Formats
private void handleColours(string line)
{
var pair = splitKeyVal(line, ':');
var pair = SplitKeyVal(line, ':');
string[] split = pair.Value.Split(',');
@@ -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
);
}
}
}
+7 -20
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
@@ -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;
}
}
@@ -59,7 +65,7 @@ namespace osu.Game.Beatmaps.Formats
line = line.Substring(1);
}
DecodeVariables(ref line);
decodeVariables(ref line);
string[] split = line.Split(',');
@@ -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('\"'));
}
}