mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Enforce that there's only one configmanager per ruleset
This commit is contained in:
parent
92da02db87
commit
d96234bf40
@ -158,6 +158,6 @@ namespace osu.Game.Rulesets.Mania
|
||||
|
||||
public override string GetVariantName(int variant) => $"{variant}K";
|
||||
|
||||
public override IRulesetConfigManager CreateConfigManager(Storage storage) => new ManiaConfigManager(this, storage);
|
||||
protected override IRulesetConfigManager CreateConfigManager(Storage storage) => new ManiaConfigManager(this, storage);
|
||||
}
|
||||
}
|
||||
|
@ -91,10 +91,18 @@ namespace osu.Game.Rulesets
|
||||
/// <returns>A descriptive name of the variant.</returns>
|
||||
public virtual string GetVariantName(int variant) => string.Empty;
|
||||
|
||||
private static readonly Dictionary<Type, IRulesetConfigManager> config_manager_cache = new Dictionary<Type, IRulesetConfigManager>();
|
||||
public IRulesetConfigManager GetConfigManager(Storage storage)
|
||||
{
|
||||
if (config_manager_cache.TryGetValue(GetType(), out var existing))
|
||||
return existing;
|
||||
return config_manager_cache[GetType()] = CreateConfigManager(storage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ConfigManager{T}"/> that is used for settings specific to this <see cref="Ruleset"/>.
|
||||
/// </summary>
|
||||
public virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null;
|
||||
protected virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null;
|
||||
|
||||
/// <summary>
|
||||
/// Create a ruleset info based on this ruleset.
|
||||
|
@ -136,7 +136,7 @@ namespace osu.Game.Screens.Play
|
||||
if (!RulesetContainer.Objects.Any())
|
||||
throw new InvalidOperationException("Beatmap contains no hit objects!");
|
||||
|
||||
var rulesetConfig = rulesetInstance.CreateConfigManager();
|
||||
var rulesetConfig = rulesetInstance.GetConfigManager(storage);
|
||||
if (rulesetConfig != null)
|
||||
dependencies.Cache(rulesetConfig);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user