From bd7341c5a18e68175e0af794b7cf19997b8ea361 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 21 Apr 2017 14:36:28 +0900 Subject: [PATCH] Restructure reading normal/add/volume members into class to make code a bit more readable/usable. --- .../Objects/Legacy/HitObjectParser.cs | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Legacy/HitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/HitObjectParser.cs index 5031128a79..9e10b7c69e 100644 --- a/osu.Game/Rulesets/Objects/Legacy/HitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/HitObjectParser.cs @@ -23,9 +23,9 @@ namespace osu.Game.Rulesets.Objects.Legacy bool combo = type.HasFlag(HitObjectType.NewCombo); type &= ~HitObjectType.NewCombo; - int sampleVolume = 0; - string normalSampleBank = null; - string addSampleBank = null; + var soundType = (LegacySoundType)int.Parse(split[4]); + + SampleBankInfo bankInfo = new SampleBankInfo(); HitObject result; @@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Objects.Legacy result = CreateHit(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo); if (split.Length > 5) - readCustomSampleBanks(split[5], ref normalSampleBank, ref addSampleBank, ref sampleVolume); + readCustomSampleBanks(split[5], bankInfo); } else if ((type & HitObjectType.Slider) > 0) { @@ -76,18 +76,19 @@ namespace osu.Game.Rulesets.Objects.Legacy if (split.Length > 7) length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture); + + if (split.Length > 10) + readCustomSampleBanks(split[10], bankInfo); result = CreateSlider(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, points, length, curveType, repeatCount); - if (split.Length > 10) - readCustomSampleBanks(split[10], ref normalSampleBank, ref addSampleBank, ref sampleVolume); } else if ((type & HitObjectType.Spinner) > 0) { result = CreateSpinner(new Vector2(512, 384) / 2, Convert.ToDouble(split[5], CultureInfo.InvariantCulture)); if (split.Length > 6) - readCustomSampleBanks(split[6], ref normalSampleBank, ref addSampleBank, ref sampleVolume); + readCustomSampleBanks(split[6], bankInfo); } else if ((type & HitObjectType.Hold) > 0) { @@ -106,15 +107,12 @@ namespace osu.Game.Rulesets.Objects.Legacy throw new InvalidOperationException($@"Unknown hit object type {type}"); result.StartTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture); - - var soundType = (LegacySoundType)int.Parse(split[4]); - result.Samples = convertSoundType(soundType, normalSampleBank, addSampleBank); - result.Samples.ForEach(s => s.Volume = sampleVolume); + result.Samples = convertSoundType(soundType, bankInfo); return result; } - private void readCustomSampleBanks(string str, ref string normalSampleBank, ref string addSampleBank, ref int sampleVolume) + private void readCustomSampleBanks(string str, SampleBankInfo bankInfo) { if (string.IsNullOrEmpty(str)) return; @@ -134,9 +132,11 @@ namespace osu.Game.Rulesets.Objects.Legacy if (stringAddBank == @"none") stringAddBank = null; - normalSampleBank = stringBank; - addSampleBank = stringAddBank; - sampleVolume = split.Length > 3 ? int.Parse(split[3]) : 0; + bankInfo.Normal = stringBank; + bankInfo.Add = stringAddBank; + + if (split.Length > 3) + bankInfo.Volume = int.Parse(split[3]); } /// @@ -167,7 +167,7 @@ namespace osu.Game.Rulesets.Objects.Legacy /// The hit object. protected abstract HitObject CreateSpinner(Vector2 position, double endTime); - private List convertSoundType(LegacySoundType type, string normalSampleBank, string addSampleBank) + private List convertSoundType(LegacySoundType type, SampleBankInfo bankInfo) { List soundTypes = new List(); @@ -175,8 +175,9 @@ namespace osu.Game.Rulesets.Objects.Legacy { soundTypes.Add(new SampleInfo { - Bank = normalSampleBank, - Name = SampleInfo.HIT_NORMAL + Bank = bankInfo.Normal, + Name = SampleInfo.HIT_NORMAL, + Volume = bankInfo.Volume }); } @@ -184,8 +185,9 @@ namespace osu.Game.Rulesets.Objects.Legacy { soundTypes.Add(new SampleInfo { - Bank = addSampleBank, - Name = SampleInfo.HIT_FINISH + Bank = bankInfo.Add, + Name = SampleInfo.HIT_FINISH, + Volume = bankInfo.Volume }); } @@ -193,8 +195,9 @@ namespace osu.Game.Rulesets.Objects.Legacy { soundTypes.Add(new SampleInfo { - Bank = addSampleBank, - Name = SampleInfo.HIT_WHISTLE + Bank = bankInfo.Add, + Name = SampleInfo.HIT_WHISTLE, + Volume = bankInfo.Volume }); } @@ -202,14 +205,27 @@ namespace osu.Game.Rulesets.Objects.Legacy { soundTypes.Add(new SampleInfo { - Bank = addSampleBank, - Name = SampleInfo.HIT_CLAP + Bank = bankInfo.Add, + Name = SampleInfo.HIT_CLAP, + Volume = bankInfo.Volume }); } return soundTypes; } + private class SampleBankInfo + { + public string Normal = null; + public string Add = null; + public int Volume = 0; + + public SampleBankInfo Clone() + { + return (SampleBankInfo)MemberwiseClone(); + } + } + [Flags] private enum LegacySoundType {