From 41b607c1657cfaac915e66dbe0e0a10b7dbdafaa Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 7 Dec 2017 03:40:43 +0900 Subject: [PATCH] Dont serialize hitobject sample properties copied from the control point --- osu.Game/Audio/SampleInfo.cs | 28 +++++++++++++++++++++++--- osu.Game/Rulesets/Objects/HitObject.cs | 14 ++----------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 171a1bdf75..edfda3bdc9 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -1,8 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using Newtonsoft.Json; +using osu.Game.Beatmaps.ControlPoints; + namespace osu.Game.Audio { + [Serializable] public class SampleInfo { public const string HIT_WHISTLE = @"hitwhistle"; @@ -10,19 +15,36 @@ public class SampleInfo public const string HIT_NORMAL = @"hitnormal"; public const string HIT_CLAP = @"hitclap"; + [JsonIgnore] + public SoundControlPoint ControlPoint; + + private string bank; /// /// The bank to load the sample from. /// - public string Bank; + public string Bank + { + get { return string.IsNullOrEmpty(bank) ? (ControlPoint?.SampleBank ?? "normal") : bank; } + set { bank = value; } + } + + public bool ShouldSerializeBank() => Bank == ControlPoint.SampleBank; /// /// The name of the sample to load. /// - public string Name; + public string Name { get; set; } + private int volume; /// /// The sample volume. /// - public int Volume; + public int Volume + { + get { return volume == 0 ? (ControlPoint?.SampleVolume ?? 0) : volume; } + set { volume = value; } + } + + public bool ShouldSerializeVolume() => Volume == ControlPoint.SampleVolume; } } diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index c69979d4cf..92220ff8bd 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -48,21 +48,11 @@ public virtual void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDiff Kiai |= effectPoint.KiaiMode; // Initialize first sample - Samples.ForEach(s => initializeSampleInfo(s, soundPoint)); + Samples.ForEach(s => s.ControlPoint = soundPoint); // Initialize any repeat samples var repeatData = this as IHasRepeats; - repeatData?.RepeatSamples?.ForEach(r => r.ForEach(s => initializeSampleInfo(s, soundPoint))); - } - - private void initializeSampleInfo(SampleInfo sample, SoundControlPoint soundPoint) - { - if (sample.Volume == 0) - sample.Volume = soundPoint?.SampleVolume ?? 0; - - // If the bank is not assigned a name, assign it from the control point - if (string.IsNullOrEmpty(sample.Bank)) - sample.Bank = soundPoint?.SampleBank ?? @"normal"; + repeatData?.RepeatSamples?.ForEach(r => r.ForEach(s => s.ControlPoint = soundPoint)); } } }