From d96234bf4063117ed10e391a7d4bbb98a25cd916 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 21:08:23 +0900 Subject: [PATCH] Enforce that there's only one configmanager per ruleset --- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 10 +++++++++- osu.Game/Screens/Play/Player.cs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 2709683eb4..9519de8b53 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -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); } } diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index e736e0ac27..faadbd24f7 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -91,10 +91,18 @@ namespace osu.Game.Rulesets /// A descriptive name of the variant. public virtual string GetVariantName(int variant) => string.Empty; + private static readonly Dictionary config_manager_cache = new Dictionary(); + public IRulesetConfigManager GetConfigManager(Storage storage) + { + if (config_manager_cache.TryGetValue(GetType(), out var existing)) + return existing; + return config_manager_cache[GetType()] = CreateConfigManager(storage); + } + /// /// The that is used for settings specific to this . /// - public virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null; + protected virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null; /// /// Create a ruleset info based on this ruleset. diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index b78f92f6b7..0ad2a4a78d 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -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); }