mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Merge branch 'immutable-hit-samples' into hit-sample-pooling
This commit is contained in:
@ -5,7 +5,6 @@ using osuTK;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Audio;
|
||||
@ -14,6 +13,7 @@ using JetBrains.Annotations;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects.Legacy
|
||||
{
|
||||
@ -428,62 +428,25 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
||||
// Todo: This should return the normal SampleInfos if the specified sample file isn't found, but that's a pretty edge-case scenario
|
||||
if (!string.IsNullOrEmpty(bankInfo.Filename))
|
||||
{
|
||||
return new List<HitSampleInfo>
|
||||
{
|
||||
new FileHitSampleInfo
|
||||
{
|
||||
Filename = bankInfo.Filename,
|
||||
Volume = bankInfo.Volume
|
||||
}
|
||||
};
|
||||
return new List<HitSampleInfo> { new FileHitSampleInfo(bankInfo.Filename, bankInfo.Volume) };
|
||||
}
|
||||
|
||||
var soundTypes = new List<HitSampleInfo>
|
||||
{
|
||||
new LegacyHitSampleInfo
|
||||
{
|
||||
Bank = bankInfo.Normal,
|
||||
Name = HitSampleInfo.HIT_NORMAL,
|
||||
Volume = bankInfo.Volume,
|
||||
CustomSampleBank = bankInfo.CustomSampleBank,
|
||||
new LegacyHitSampleInfo(HitSampleInfo.HIT_NORMAL, bankInfo.Normal, bankInfo.Volume, bankInfo.CustomSampleBank,
|
||||
// if the sound type doesn't have the Normal flag set, attach it anyway as a layered sample.
|
||||
// None also counts as a normal non-layered sample: https://osu.ppy.sh/help/wiki/osu!_File_Formats/Osu_(file_format)#hitsounds
|
||||
IsLayered = type != LegacyHitSoundType.None && !type.HasFlag(LegacyHitSoundType.Normal)
|
||||
}
|
||||
type != LegacyHitSoundType.None && !type.HasFlag(LegacyHitSoundType.Normal))
|
||||
};
|
||||
|
||||
if (type.HasFlag(LegacyHitSoundType.Finish))
|
||||
{
|
||||
soundTypes.Add(new LegacyHitSampleInfo
|
||||
{
|
||||
Bank = bankInfo.Add,
|
||||
Name = HitSampleInfo.HIT_FINISH,
|
||||
Volume = bankInfo.Volume,
|
||||
CustomSampleBank = bankInfo.CustomSampleBank
|
||||
});
|
||||
}
|
||||
soundTypes.Add(new LegacyHitSampleInfo(HitSampleInfo.HIT_FINISH, bankInfo.Add, bankInfo.Volume, bankInfo.CustomSampleBank));
|
||||
|
||||
if (type.HasFlag(LegacyHitSoundType.Whistle))
|
||||
{
|
||||
soundTypes.Add(new LegacyHitSampleInfo
|
||||
{
|
||||
Bank = bankInfo.Add,
|
||||
Name = HitSampleInfo.HIT_WHISTLE,
|
||||
Volume = bankInfo.Volume,
|
||||
CustomSampleBank = bankInfo.CustomSampleBank
|
||||
});
|
||||
}
|
||||
soundTypes.Add(new LegacyHitSampleInfo(HitSampleInfo.HIT_WHISTLE, bankInfo.Add, bankInfo.Volume, bankInfo.CustomSampleBank));
|
||||
|
||||
if (type.HasFlag(LegacyHitSoundType.Clap))
|
||||
{
|
||||
soundTypes.Add(new LegacyHitSampleInfo
|
||||
{
|
||||
Bank = bankInfo.Add,
|
||||
Name = HitSampleInfo.HIT_CLAP,
|
||||
Volume = bankInfo.Volume,
|
||||
CustomSampleBank = bankInfo.CustomSampleBank
|
||||
});
|
||||
}
|
||||
soundTypes.Add(new LegacyHitSampleInfo(HitSampleInfo.HIT_CLAP, bankInfo.Add, bankInfo.Volume, bankInfo.CustomSampleBank));
|
||||
|
||||
return soundTypes;
|
||||
}
|
||||
@ -501,21 +464,11 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
||||
public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone();
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class LegacyHitSampleInfo : HitSampleInfo, IEquatable<LegacyHitSampleInfo>
|
||||
{
|
||||
private int customSampleBank;
|
||||
|
||||
public int CustomSampleBank
|
||||
{
|
||||
get => customSampleBank;
|
||||
set
|
||||
{
|
||||
customSampleBank = value;
|
||||
|
||||
if (value >= 2)
|
||||
Suffix = value.ToString();
|
||||
}
|
||||
}
|
||||
public readonly int CustomSampleBank;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this hit sample is layered.
|
||||
@ -524,30 +477,40 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
||||
/// Layered hit samples are automatically added in all modes (except osu!mania), but can be disabled
|
||||
/// using the <see cref="LegacySkinConfiguration.LegacySetting.LayeredHitSounds"/> skin config option.
|
||||
/// </remarks>
|
||||
public bool IsLayered { get; set; }
|
||||
public readonly bool IsLayered;
|
||||
|
||||
public bool Equals(LegacyHitSampleInfo other)
|
||||
=> other != null && base.Equals(other) && CustomSampleBank == other.CustomSampleBank;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> obj is LegacyHitSampleInfo other && Equals(other);
|
||||
|
||||
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] // This will have to be addressed eventually
|
||||
public override int GetHashCode()
|
||||
public LegacyHitSampleInfo(string name, string? bank = null, int volume = 100, int customSampleBank = 0, bool isLayered = false)
|
||||
: base(name, bank, customSampleBank >= 2 ? customSampleBank.ToString() : null, volume)
|
||||
{
|
||||
return HashCode.Combine(base.GetHashCode(), customSampleBank);
|
||||
CustomSampleBank = customSampleBank;
|
||||
IsLayered = isLayered;
|
||||
}
|
||||
|
||||
public override HitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<string?> suffix = default, Optional<int> volume = default)
|
||||
=> With(name, bank, volume);
|
||||
|
||||
public LegacyHitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<int> volume = default, Optional<int> customSampleBank = default,
|
||||
Optional<bool> isLayered = default)
|
||||
=> new LegacyHitSampleInfo(name.GetOr(Name), bank.GetOr(Bank), volume.GetOr(Volume), customSampleBank.GetOr(CustomSampleBank), isLayered.GetOr(IsLayered));
|
||||
|
||||
public bool Equals(LegacyHitSampleInfo? other)
|
||||
=> base.Equals(other) && CustomSampleBank == other.CustomSampleBank && IsLayered == other.IsLayered;
|
||||
|
||||
public override bool Equals(object? obj) => Equals((LegacyHitSampleInfo?)obj);
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), CustomSampleBank, IsLayered);
|
||||
}
|
||||
|
||||
private class FileHitSampleInfo : LegacyHitSampleInfo, IEquatable<FileHitSampleInfo>
|
||||
{
|
||||
public string Filename;
|
||||
public readonly string Filename;
|
||||
|
||||
public FileHitSampleInfo()
|
||||
{
|
||||
// Make sure that the LegacyBeatmapSkin does not fall back to the user skin.
|
||||
public FileHitSampleInfo(string filename, int volume)
|
||||
// Force CSS=1 to make sure that the LegacyBeatmapSkin does not fall back to the user skin.
|
||||
// Note that this does not change the lookup names, as they are overridden locally.
|
||||
CustomSampleBank = 1;
|
||||
: base(string.Empty, customSampleBank: 1, volume: volume)
|
||||
{
|
||||
Filename = filename;
|
||||
}
|
||||
|
||||
public override IEnumerable<string> LookupNames => new[]
|
||||
@ -556,17 +519,21 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
||||
Path.ChangeExtension(Filename, null)
|
||||
};
|
||||
|
||||
public bool Equals(FileHitSampleInfo other)
|
||||
=> other != null && Filename == other.Filename;
|
||||
public override HitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<string?> suffix = default, Optional<int> volume = default)
|
||||
=> With(volume: volume);
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> obj is FileHitSampleInfo other && Equals(other);
|
||||
public FileHitSampleInfo With(Optional<string> filename = default, Optional<int> volume = default)
|
||||
=> new FileHitSampleInfo(filename.GetOr(Filename), volume.GetOr(Volume));
|
||||
|
||||
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] // This will have to be addressed eventually
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Filename);
|
||||
}
|
||||
public bool Equals(FileHitSampleInfo? other)
|
||||
=> base.Equals(other) && Filename == other.Filename;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
=> Equals((FileHitSampleInfo?)obj);
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Filename);
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user