1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Dont serialize hitobject sample properties copied from the control point

This commit is contained in:
smoogipoo 2017-12-07 03:40:43 +09:00
parent 9787788081
commit 41b607c165
2 changed files with 27 additions and 15 deletions

View File

@ -1,8 +1,13 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// 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 @@ namespace osu.Game.Audio
public const string HIT_NORMAL = @"hitnormal";
public const string HIT_CLAP = @"hitclap";
[JsonIgnore]
public SoundControlPoint ControlPoint;
private string bank;
/// <summary>
/// The bank to load the sample from.
/// </summary>
public string Bank;
public string Bank
{
get { return string.IsNullOrEmpty(bank) ? (ControlPoint?.SampleBank ?? "normal") : bank; }
set { bank = value; }
}
public bool ShouldSerializeBank() => Bank == ControlPoint.SampleBank;
/// <summary>
/// The name of the sample to load.
/// </summary>
public string Name;
public string Name { get; set; }
private int volume;
/// <summary>
/// The sample volume.
/// </summary>
public int Volume;
public int Volume
{
get { return volume == 0 ? (ControlPoint?.SampleVolume ?? 0) : volume; }
set { volume = value; }
}
public bool ShouldSerializeVolume() => Volume == ControlPoint.SampleVolume;
}
}

View File

@ -48,21 +48,11 @@ namespace osu.Game.Rulesets.Objects
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));
}
}
}