Cleanups.

This commit is contained in:
smoogipooo 2017-05-30 19:52:21 +09:00
parent 94ae730a20
commit 0175b91927
1 changed files with 49 additions and 27 deletions

View File

@ -10,6 +10,7 @@
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using System.Linq;
namespace osu.Game.Beatmaps.Formats namespace osu.Game.Beatmaps.Formats
{ {
@ -206,18 +207,29 @@ private void handleDifficulty(Beatmap beatmap, string key, string val)
} }
} }
/// <summary>
/// Decodes any beatmap variables present in a string value.
/// </summary>
/// <param name="val">The value which contains variables.</param>
private void decodeVariables(ref string val)
{
while (val.IndexOf('$') >= 0)
{
string[] split = val.Split(',');
for (int i = 0; i < split.Length; i++)
{
var item = split[i];
if (item.StartsWith("$") && variables.ContainsKey(item))
item = variables[item];
}
val = string.Join(",", split);
}
}
private void handleEvents(Beatmap beatmap, string val) private void handleEvents(Beatmap beatmap, string val)
{ {
do decodeVariables(ref val);
{
string[] valSplit = val.Split(',');
for (int i = 0; i < valSplit.Length; i++)
{
if (valSplit[i][0] == '$' && variables.ContainsKey(valSplit[i]))
valSplit[i] = variables[valSplit[i]];
}
val = string.Join(",", valSplit);
} while (val.IndexOf('$') != -1);
string[] split = val.Split(','); string[] split = val.Split(',');
@ -405,46 +417,56 @@ protected override void ParseFile(StreamReader stream, Beatmap beatmap)
continue; continue;
} }
string val = line, key = null; string key = null, value = null;
if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects && section != Section.Variables)
{
key = val.Remove(val.IndexOf(':')).Trim();
val = val.Substring(val.IndexOf(':') + 1).Trim();
}
switch (section) switch (section)
{ {
case Section.General: case Section.General:
handleGeneral(beatmap, key, val); case Section.Editor:
case Section.Metadata:
case Section.Difficulty:
case Section.Colours:
key = line.Remove(line.IndexOf(':')).Trim();
value = line.Substring(line.IndexOf(':') + 1).Trim();
break;
case Section.Variables:
key = line.Remove(line.IndexOf('=')).Trim();
value = line.Substring(line.IndexOf('=') + 1).Trim();
break;
}
switch (section)
{
case Section.General:
handleGeneral(beatmap, key, value);
break; break;
case Section.Editor: case Section.Editor:
handleEditor(beatmap, key, val); handleEditor(beatmap, key, value);
break; break;
case Section.Metadata: case Section.Metadata:
handleMetadata(beatmap, key, val); handleMetadata(beatmap, key, value);
break; break;
case Section.Difficulty: case Section.Difficulty:
handleDifficulty(beatmap, key, val); handleDifficulty(beatmap, key, value);
break; break;
case Section.Events: case Section.Events:
handleEvents(beatmap, val); handleEvents(beatmap, line);
break; break;
case Section.TimingPoints: case Section.TimingPoints:
handleTimingPoints(beatmap, val); handleTimingPoints(beatmap, line);
break; break;
case Section.Colours: case Section.Colours:
handleColours(beatmap, key, val, ref hasCustomColours); handleColours(beatmap, key, value, ref hasCustomColours);
break; break;
case Section.HitObjects: case Section.HitObjects:
var obj = parser.Parse(val); var obj = parser.Parse(line);
if (obj != null) if (obj != null)
beatmap.HitObjects.Add(obj); beatmap.HitObjects.Add(obj);
break; break;
case Section.Variables: case Section.Variables:
key = val.Remove(val.IndexOf('=')).Trim(); variables[key] = value;
val = val.Substring(val.IndexOf('=') + 1).Trim();
variables[key] = val;
break; break;
} }
} }