mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +08:00
Merge pull request #3076 from smoogipoo/per-object-css
Add support for multiple sample banks on a per-hitobject level
This commit is contained in:
commit
f285279258
@ -214,10 +214,10 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeCustomSamples()
|
public void TestDecodeControlPointCustomSampleBank()
|
||||||
{
|
{
|
||||||
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
||||||
using (var resStream = Resource.OpenResource("custom-samples.osu"))
|
using (var resStream = Resource.OpenResource("controlpoint-custom-samplebank.osu"))
|
||||||
using (var stream = new StreamReader(resStream))
|
using (var stream = new StreamReader(resStream))
|
||||||
{
|
{
|
||||||
var hitObjects = decoder.Decode(stream).HitObjects;
|
var hitObjects = decoder.Decode(stream).HitObjects;
|
||||||
@ -228,25 +228,42 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First());
|
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" });
|
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeCustomHitObjectSamples()
|
public void TestDecodeHitObjectCustomSampleBank()
|
||||||
{
|
{
|
||||||
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
||||||
using (var resStream = Resource.OpenResource("custom-hitobject-samples.osu"))
|
using (var resStream = Resource.OpenResource("hitobject-custom-samplebank.osu"))
|
||||||
using (var stream = new StreamReader(resStream))
|
using (var stream = new StreamReader(resStream))
|
||||||
{
|
{
|
||||||
var hitObjects = decoder.Decode(stream).HitObjects;
|
var hitObjects = decoder.Decode(stream).HitObjects;
|
||||||
|
|
||||||
Assert.AreEqual("hit_1.wav", hitObjects[0].Samples[0].LookupNames.First());
|
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
|
||||||
Assert.AreEqual("hit_2.wav", hitObjects[1].Samples[0].LookupNames.First());
|
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
|
||||||
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
|
Assert.AreEqual("normal-hitnormal3", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
|
||||||
Assert.AreEqual("hit_1.wav", hitObjects[3].Samples[0].LookupNames.First());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" });
|
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDecodeHitObjectFileSamples()
|
||||||
|
{
|
||||||
|
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
|
||||||
|
using (var resStream = Resource.OpenResource("hitobject-file-samples.osu"))
|
||||||
|
using (var stream = new StreamReader(resStream))
|
||||||
|
{
|
||||||
|
var hitObjects = decoder.Decode(stream).HitObjects;
|
||||||
|
|
||||||
|
Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
|
||||||
|
Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
|
||||||
|
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
|
||||||
|
Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[3]).LookupNames.First());
|
||||||
|
}
|
||||||
|
|
||||||
|
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
osu.Game.Tests/Resources/hitobject-custom-samplebank.osu
Normal file
13
osu.Game.Tests/Resources/hitobject-custom-samplebank.osu
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
osu file format v14
|
||||||
|
|
||||||
|
[General]
|
||||||
|
SampleSet: Normal
|
||||||
|
|
||||||
|
[TimingPoints]
|
||||||
|
2170,468.75,4,1,0,40,1,0
|
||||||
|
3107,-100,4,1,2,40,0,0
|
||||||
|
|
||||||
|
[HitObjects]
|
||||||
|
255,193,2170,1,0,0:0:0:0:
|
||||||
|
256,191,3107,5,0,0:0:0:0:
|
||||||
|
255,193,4000,1,0,0:0:3:70:
|
@ -40,7 +40,6 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
{
|
{
|
||||||
var newSampleInfo = sampleInfo.Clone();
|
var newSampleInfo = sampleInfo.Clone();
|
||||||
newSampleInfo.Bank = sampleInfo.Bank ?? SampleBank;
|
newSampleInfo.Bank = sampleInfo.Bank ?? SampleBank;
|
||||||
newSampleInfo.Name = sampleInfo.Name;
|
|
||||||
newSampleInfo.Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume;
|
newSampleInfo.Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume;
|
||||||
return newSampleInfo;
|
return newSampleInfo;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
{
|
{
|
||||||
var baseInfo = base.ApplyTo(sampleInfo);
|
var baseInfo = base.ApplyTo(sampleInfo);
|
||||||
|
|
||||||
if (CustomSampleBank > 1)
|
if (string.IsNullOrEmpty(baseInfo.Suffix) && CustomSampleBank > 1)
|
||||||
baseInfo.Suffix = CustomSampleBank.ToString();
|
baseInfo.Suffix = CustomSampleBank.ToString();
|
||||||
|
|
||||||
return baseInfo;
|
return baseInfo;
|
||||||
|
@ -194,8 +194,8 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
|
|
||||||
string[] split = str.Split(':');
|
string[] split = str.Split(':');
|
||||||
|
|
||||||
var bank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[0]);
|
var bank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[0]);
|
||||||
var addbank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[1]);
|
var addbank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[1]);
|
||||||
|
|
||||||
string stringBank = bank.ToString().ToLower();
|
string stringBank = bank.ToString().ToLower();
|
||||||
if (stringBank == @"none")
|
if (stringBank == @"none")
|
||||||
@ -207,6 +207,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
bankInfo.Normal = stringBank;
|
bankInfo.Normal = stringBank;
|
||||||
bankInfo.Add = stringAddBank;
|
bankInfo.Add = stringAddBank;
|
||||||
|
|
||||||
|
if (split.Length > 2)
|
||||||
|
bankInfo.CustomSampleBank = int.Parse(split[2]);
|
||||||
|
|
||||||
if (split.Length > 3)
|
if (split.Length > 3)
|
||||||
bankInfo.Volume = int.Parse(split[3]);
|
bankInfo.Volume = int.Parse(split[3]);
|
||||||
|
|
||||||
@ -258,41 +261,45 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
|
|
||||||
var soundTypes = new List<SampleInfo>
|
var soundTypes = new List<SampleInfo>
|
||||||
{
|
{
|
||||||
new SampleInfo
|
new LegacySampleInfo
|
||||||
{
|
{
|
||||||
Bank = bankInfo.Normal,
|
Bank = bankInfo.Normal,
|
||||||
Name = SampleInfo.HIT_NORMAL,
|
Name = SampleInfo.HIT_NORMAL,
|
||||||
Volume = bankInfo.Volume
|
Volume = bankInfo.Volume,
|
||||||
|
CustomSampleBank = bankInfo.CustomSampleBank
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (type.HasFlag(LegacySoundType.Finish))
|
if (type.HasFlag(LegacySoundType.Finish))
|
||||||
{
|
{
|
||||||
soundTypes.Add(new SampleInfo
|
soundTypes.Add(new LegacySampleInfo
|
||||||
{
|
{
|
||||||
Bank = bankInfo.Add,
|
Bank = bankInfo.Add,
|
||||||
Name = SampleInfo.HIT_FINISH,
|
Name = SampleInfo.HIT_FINISH,
|
||||||
Volume = bankInfo.Volume
|
Volume = bankInfo.Volume,
|
||||||
|
CustomSampleBank = bankInfo.CustomSampleBank
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.HasFlag(LegacySoundType.Whistle))
|
if (type.HasFlag(LegacySoundType.Whistle))
|
||||||
{
|
{
|
||||||
soundTypes.Add(new SampleInfo
|
soundTypes.Add(new LegacySampleInfo
|
||||||
{
|
{
|
||||||
Bank = bankInfo.Add,
|
Bank = bankInfo.Add,
|
||||||
Name = SampleInfo.HIT_WHISTLE,
|
Name = SampleInfo.HIT_WHISTLE,
|
||||||
Volume = bankInfo.Volume
|
Volume = bankInfo.Volume,
|
||||||
|
CustomSampleBank = bankInfo.CustomSampleBank
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.HasFlag(LegacySoundType.Clap))
|
if (type.HasFlag(LegacySoundType.Clap))
|
||||||
{
|
{
|
||||||
soundTypes.Add(new SampleInfo
|
soundTypes.Add(new LegacySampleInfo
|
||||||
{
|
{
|
||||||
Bank = bankInfo.Add,
|
Bank = bankInfo.Add,
|
||||||
Name = SampleInfo.HIT_CLAP,
|
Name = SampleInfo.HIT_CLAP,
|
||||||
Volume = bankInfo.Volume
|
Volume = bankInfo.Volume,
|
||||||
|
CustomSampleBank = bankInfo.CustomSampleBank
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,9 +314,23 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
public string Add;
|
public string Add;
|
||||||
public int Volume;
|
public int Volume;
|
||||||
|
|
||||||
|
public int CustomSampleBank;
|
||||||
|
|
||||||
public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone();
|
public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class LegacySampleInfo : SampleInfo
|
||||||
|
{
|
||||||
|
public int CustomSampleBank
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value > 1)
|
||||||
|
Suffix = value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class FileSampleInfo : SampleInfo
|
private class FileSampleInfo : SampleInfo
|
||||||
{
|
{
|
||||||
public string Filename;
|
public string Filename;
|
||||||
|
Loading…
Reference in New Issue
Block a user