From 0b7e1ce667dae810a2fc9d7e2d1ad3b3ada05007 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 19:45:18 +0900 Subject: [PATCH] Add a way to have ruleset-specific configs --- .../Configuration/IRulesetConfigManager.cs | 9 +++++++ .../Configuration/RulesetConfigManager.cs | 24 +++++++++++++++++++ osu.Game/Rulesets/Ruleset.cs | 6 +++++ osu.Game/Screens/Play/Player.cs | 12 +++++++++- osu.Game/osu.Game.csproj | 2 ++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs create mode 100644 osu.Game/Rulesets/Configuration/RulesetConfigManager.cs diff --git a/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs new file mode 100644 index 0000000000..08fb6f53d6 --- /dev/null +++ b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Configuration +{ + public interface IRulesetConfigManager + { + } +} diff --git a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs new file mode 100644 index 0000000000..633d8f3951 --- /dev/null +++ b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Configuration; +using osu.Framework.Platform; + +namespace osu.Game.Rulesets.Configuration +{ + public abstract class RulesetConfigManager : ConfigManager, IRulesetConfigManager + where T : struct + { + protected override string Filename => ruleset?.ShortName; + private readonly Ruleset ruleset; + + protected RulesetConfigManager(Ruleset ruleset, Storage storage) + : base(storage) + { + this.ruleset = ruleset; + + // Re-load with the ruleset + Load(); + } + } +} diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 4f256621fb..c1aba5b403 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -9,6 +9,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; +using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; @@ -89,6 +90,11 @@ namespace osu.Game.Rulesets /// A descriptive name of the variant. public virtual string GetVariantName(int variant) => string.Empty; + /// + /// The that is used for settings specific to this . + /// + public virtual IRulesetConfigManager CreateConfigManager() => 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 31d9fac2ad..b78f92f6b7 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -24,6 +24,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Ranking; using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Cursor; +using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Cursor; @@ -88,8 +89,13 @@ namespace osu.Game.Screens.Play private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(base.CreateLocalDependencies(parent)); + [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuConfigManager config, APIAccess api) + private void load(AudioManager audio, OsuConfigManager config, APIAccess api, Storage storage) { this.api = api; @@ -129,6 +135,10 @@ namespace osu.Game.Screens.Play if (!RulesetContainer.Objects.Any()) throw new InvalidOperationException("Beatmap contains no hit objects!"); + + var rulesetConfig = rulesetInstance.CreateConfigManager(); + if (rulesetConfig != null) + dependencies.Cache(rulesetConfig); } catch (Exception e) { diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 85da54e317..05728c2b41 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -314,6 +314,8 @@ + +