mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Add ability to lookup mod from a type specification
This commit is contained in:
@ -24,7 +24,6 @@ using osu.Game.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Users;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.EnumExtensions;
|
||||
using osu.Framework.Testing;
|
||||
@ -86,6 +85,20 @@ namespace osu.Game.Rulesets
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a fresh instance of the mod matching the specified type.
|
||||
/// </summary>
|
||||
public T GetMod<T>()
|
||||
where T : Mod
|
||||
{
|
||||
var type = GetAllModsForReference().FirstOrDefault(m => m is T)?.GetType();
|
||||
|
||||
if (type != null)
|
||||
return (T)Activator.CreateInstance(type);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract IEnumerable<Mod> GetModsFor(ModType type);
|
||||
|
||||
/// <summary>
|
||||
@ -166,7 +179,7 @@ namespace osu.Game.Rulesets
|
||||
}
|
||||
|
||||
[CanBeNull]
|
||||
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().FirstOrDefault();
|
||||
public ModAutoplay GetAutoplayMod() => GetMod<ModAutoplay>();
|
||||
|
||||
public virtual ISkin CreateLegacySkinProvider([NotNull] ISkin skin, IBeatmap beatmap) => null;
|
||||
|
||||
|
Reference in New Issue
Block a user