1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Enforce that there's only one configmanager per ruleset

This commit is contained in:
smoogipoo 2018-01-17 21:08:23 +09:00
parent 92da02db87
commit d96234bf40
3 changed files with 11 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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);
}