1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 07:32:55 +08:00

Add a way to have ruleset-specific configs

This commit is contained in:
smoogipoo 2018-01-17 19:45:18 +09:00
parent 18cdd1caac
commit 0b7e1ce667
5 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,9 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Rulesets.Configuration
{
public interface IRulesetConfigManager
{
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<T> : ConfigManager<T>, 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();
}
}
}

View File

@ -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
/// <returns>A descriptive name of the variant.</returns>
public virtual string GetVariantName(int variant) => string.Empty;
/// <summary>
/// The <see cref="ConfigManager{T}"/> that is used for settings specific to this <see cref="Ruleset"/>.
/// </summary>
public virtual IRulesetConfigManager CreateConfigManager() => null;
/// <summary>
/// Create a ruleset info based on this ruleset.
/// </summary>

View File

@ -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)
{

View File

@ -314,6 +314,8 @@
<Compile Include="Overlays\Profile\Sections\Ranks\ScoreModsContainer.cs" />
<Compile Include="Overlays\Settings\Sections\Gameplay\ScrollingSettings.cs" />
<Compile Include="Overlays\Settings\Sections\Maintenance\DeleteAllBeatmapsDialog.cs" />
<Compile Include="Rulesets\Configuration\IRulesetConfigManager.cs" />
<Compile Include="Rulesets\Configuration\RulesetConfigManager.cs" />
<Compile Include="Rulesets\Mods\IApplicableFailOverride.cs" />
<Compile Include="Rulesets\Mods\IApplicableMod.cs" />
<Compile Include="Rulesets\Mods\IApplicableToBeatmapConverter.cs" />