// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Configuration; using osu.Game.Rulesets.Configuration; namespace osu.Game.Rulesets { /// /// A cache that provides a single per-ruleset. /// This is done to support referring to and updating ruleset configs from multiple locations in the absence of inter-config bindings. /// public class RulesetConfigCache : Component { private readonly Dictionary configCache = new Dictionary(); private readonly SettingsStore settingsStore; public RulesetConfigCache(SettingsStore settingsStore) { this.settingsStore = settingsStore; } /// /// Retrieves the for a . /// /// The to retrieve the for. /// The defined by , null if doesn't define one. /// If doesn't have a valid . public IRulesetConfigManager GetConfigFor(Ruleset ruleset) { if (ruleset.RulesetInfo.ID == null) throw new InvalidOperationException("The provided ruleset doesn't have a valid id."); if (configCache.TryGetValue(ruleset.RulesetInfo.ID.Value, out var existing)) return existing; return configCache[ruleset.RulesetInfo.ID.Value] = ruleset.CreateConfig(settingsStore); } } }