From dcc4e863ab69795a1eb42d0594667624021da98b Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 4 Jan 2018 19:04:52 +0800 Subject: [PATCH 1/2] 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('\"')); } } From 0158246ba148ab5a0e18e4caca528943f40bf032 Mon Sep 17 00:00:00 2001 From: james58899 Date: Thu, 4 Jan 2018 19:23:00 +0800 Subject: [PATCH 2/2] AppVeyor --- osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs | 10 +++++----- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 2 +- .../Beatmaps/Formats/LegacyStoryboardDecoder.cs | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index 31678fd3b1..83d70d832d 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -86,7 +86,7 @@ namespace osu.Game.Beatmaps.Formats private void handleGeneral(string line) { - var pair = splitKeyVal(line, ':'); + var pair = SplitKeyVal(line, ':'); var metadata = beatmap.BeatmapInfo.Metadata; switch (pair.Key) @@ -145,7 +145,7 @@ namespace osu.Game.Beatmaps.Formats private void handleEditor(string line) { - var pair = splitKeyVal(line, ':'); + var pair = SplitKeyVal(line, ':'); switch (pair.Key) { @@ -169,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) @@ -210,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) @@ -353,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(','); diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index faad03e7d9..214f7ccb8b 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -81,7 +81,7 @@ namespace osu.Game.Beatmaps.Formats protected abstract void ProcessSection(Section section, string line); - protected KeyValuePair splitKeyVal(string line, char separator) + protected KeyValuePair SplitKeyVal(string line, char separator) { var split = line.Trim().Split(new[] { separator }, 2); diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index 40f2695f28..ed4992d532 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -20,7 +20,7 @@ namespace osu.Game.Beatmaps.Formats private StoryboardSprite storyboardSprite; private CommandTimelineGroup timelineGroup; - private readonly Dictionary Variables = new Dictionary(); + private readonly Dictionary variables = new Dictionary(); public LegacyStoryboardDecoder() { @@ -65,7 +65,7 @@ namespace osu.Game.Beatmaps.Formats line = line.Substring(1); } - DecodeVariables(ref line); + decodeVariables(ref line); string[] split = line.Split(','); @@ -274,15 +274,15 @@ namespace osu.Game.Beatmaps.Formats private void handleVariables(string line) { - var pair = splitKeyVal(line, '='); - Variables[pair.Key] = pair.Value; + 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) + private void decodeVariables(ref string line) { while (line.IndexOf('$') >= 0) { @@ -291,8 +291,8 @@ namespace osu.Game.Beatmaps.Formats for (int i = 0; i < split.Length; i++) { var item = split[i]; - if (item.StartsWith("$") && Variables.ContainsKey(item)) - split[i] = Variables[item]; + if (item.StartsWith("$") && variables.ContainsKey(item)) + split[i] = variables[item]; } line = string.Join(",", split);