From dcc4e863ab69795a1eb42d0594667624021da98b Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 4 Jan 2018 19:04:52 +0800 Subject: [PATCH] move variables to StoryboardDecoder --- .../Beatmaps/Formats/LegacyBeatmapDecoder.cs | 23 ------------ osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 27 ++++---------- .../Formats/LegacyStoryboardDecoder.cs | 35 +++++++++++++++++++ 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index ea29e480ec..31678fd3b1 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -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 splitKeyVal(string line, char separator) - { - var split = line.Trim().Split(new[] { separator }, 2); - - return new KeyValuePair - ( - split[0].Trim(), - split.Length > 1 ? split[1].Trim() : string.Empty - ); - } } } diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index e5ced5f772..faad03e7d9 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -29,7 +29,6 @@ namespace osu.Game.Beatmaps.Formats } protected int BeatmapVersion; - protected readonly Dictionary Variables = new Dictionary(); public override Decoder GetStoryboardDecoder() => new LegacyStoryboardDecoder(BeatmapVersion); @@ -82,27 +81,15 @@ namespace osu.Game.Beatmaps.Formats protected abstract void ProcessSection(Section section, string line); - /// - /// Decodes any beatmap variables present in a line into their real values. - /// - /// The line which may contains variables. - protected void DecodeVariables(ref string line) + protected KeyValuePair 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 + ( + split[0].Trim(), + split.Length > 1 ? split[1].Trim() : string.Empty + ); } protected enum Section diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index 168f37e44e..40f2695f28 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -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 Variables = new Dictionary(); + 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; + } + + /// + /// Decodes any beatmap variables present in a line into their real values. + /// + /// The line which may contains variables. + 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('\"')); } }