diff --git a/osu.Desktop.Tests/Visual/TestCaseCatcher.cs b/osu.Desktop.Tests/Visual/TestCaseCatcher.cs index de32608a6c..3f57b5eeb9 100644 --- a/osu.Desktop.Tests/Visual/TestCaseCatcher.cs +++ b/osu.Desktop.Tests/Visual/TestCaseCatcher.cs @@ -1,7 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Game.Rulesets; using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Catch.UI; using OpenTK; @@ -10,13 +12,12 @@ namespace osu.Desktop.Tests.Visual { internal class TestCaseCatcher : OsuTestCase { - protected override void LoadComplete() + [BackgroundDependencyLoader] + private void load(RulesetStore rulesets) { - base.LoadComplete(); - Children = new Drawable[] { - new CatchInputManager + new CatchInputManager(rulesets.GetRuleset(2)) { RelativeSizeAxes = Axes.Both, Child = new CatcherArea diff --git a/osu.Desktop.Tests/Visual/TestCaseGamefield.cs b/osu.Desktop.Tests/Visual/TestCaseGamefield.cs index 9d61c9ab0c..98dda56d41 100644 --- a/osu.Desktop.Tests/Visual/TestCaseGamefield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseGamefield.cs @@ -11,11 +11,15 @@ using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets; +using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Catch.UI; +using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.UI; +using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko.UI; using OpenTK; @@ -84,25 +88,25 @@ namespace osu.Desktop.Tests.Visual Clock = new FramedClock(), Children = new Drawable[] { - new OsuHitRenderer(beatmap, false) + new OsuHitRenderer(new OsuRuleset(new RulesetInfo()), beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.TopLeft, Origin = Anchor.TopLeft }, - new TaikoHitRenderer(beatmap, false) + new TaikoHitRenderer(new TaikoRuleset(new RulesetInfo()),beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.TopRight, Origin = Anchor.TopRight }, - new CatchHitRenderer(beatmap, false) + new CatchHitRenderer(new CatchRuleset(new RulesetInfo()),beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft }, - new ManiaHitRenderer(beatmap, false) + new ManiaHitRenderer(new ManiaRuleset(new RulesetInfo()),beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.BottomRight, diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index 7f067efa78..aaa2f7d49d 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -59,7 +59,7 @@ namespace osu.Desktop.Tests.Visual private class TestHitRenderer : ScrollingHitRenderer { public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + : base(null, beatmap, isForCurrentRuleset) { } diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index dc13329bde..66e2fd30bb 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Catch { public class CatchRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchHitRenderer(beatmap, isForCurrentRuleset); + public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchHitRenderer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetModsFor(ModType type) { @@ -102,5 +102,10 @@ namespace osu.Game.Rulesets.Catch public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); public override int LegacyID => 2; + + public CatchRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Catch/RulesetInputManager.cs b/osu.Game.Rulesets.Catch/RulesetInputManager.cs index 78bd18baa3..eada5cf532 100644 --- a/osu.Game.Rulesets.Catch/RulesetInputManager.cs +++ b/osu.Game.Rulesets.Catch/RulesetInputManager.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Catch { public class CatchInputManager : ActionMappingInputManager { - public CatchInputManager() + public CatchInputManager(RulesetInfo ruleset) : base(ruleset) { Mappings = new Dictionary { diff --git a/osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs b/osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs index 04e3036db6..d08b349459 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs @@ -17,8 +17,8 @@ namespace osu.Game.Rulesets.Catch.UI { public class CatchHitRenderer : ScrollingHitRenderer { - public CatchHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public CatchHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } @@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Catch.UI protected override Playfield CreatePlayfield() => new CatchPlayfield(); - protected override PassThroughInputManager CreateKeyConversionInputManager() => new CatchInputManager(); + protected override PassThroughInputManager CreateActionMappingInputManager() => new CatchInputManager(Ruleset.RulesetInfo); protected override DrawableHitObject GetVisualRepresentation(CatchBaseHit h) { diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index a8a89a57e0..b61230d347 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mania { public class ManiaRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaHitRenderer(beatmap, isForCurrentRuleset); + public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaHitRenderer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetModsFor(ModType type) { @@ -118,5 +118,10 @@ namespace osu.Game.Rulesets.Mania public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); public override int LegacyID => 3; + + public ManiaRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 0b8ad10b16..ffb3ad4a45 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -38,8 +38,8 @@ namespace osu.Game.Rulesets.Mania.UI public IEnumerable BarLines; - public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public ManiaHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { // Generate the bar lines double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 9a1971d791..d80beaf0a3 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Osu { public class OsuRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuHitRenderer(beatmap, isForCurrentRuleset); + public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuHitRenderer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] { @@ -126,5 +126,10 @@ namespace osu.Game.Rulesets.Osu public override SettingsSubsection CreateSettings() => new OsuSettings(); public override int LegacyID => 0; + + public OsuRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs b/osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs index e59af40db4..1356e97907 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs @@ -18,8 +18,8 @@ namespace osu.Game.Rulesets.Osu.UI { public class OsuHitRenderer : HitRenderer { - public OsuHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public OsuHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI protected override Playfield CreatePlayfield() => new OsuPlayfield(); - protected override PassThroughInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager(); + protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuKeyConversionInputManager(); protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 83db9b35af..9b2536a7ec 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Taiko { public class TaikoRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoHitRenderer(beatmap, isForCurrentRuleset); + public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoHitRenderer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetModsFor(ModType type) { @@ -103,5 +103,10 @@ namespace osu.Game.Rulesets.Taiko public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); public override int LegacyID => 1; + + public TaikoRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs index 570b4be488..cb89cfed72 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs @@ -23,8 +23,8 @@ namespace osu.Game.Rulesets.Taiko.UI { public class TaikoHitRenderer : HitRenderer { - public TaikoHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public TaikoHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } @@ -93,7 +93,6 @@ namespace osu.Game.Rulesets.Taiko.UI return new Vector2(1, default_relative_height * aspectAdjust); } - public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this); protected override BeatmapConverter CreateBeatmapConverter() => new TaikoBeatmapConverter(); diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index bd53a80555..7538893cb7 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps private class DummyRulesetInfo : RulesetInfo { - public override Ruleset CreateInstance() => new DummyRuleset(); + public override Ruleset CreateInstance() => new DummyRuleset(this); private class DummyRuleset : Ruleset { @@ -77,6 +77,11 @@ namespace osu.Game.Beatmaps public override string Description => "dummy"; public override IEnumerable CreateGameplayKeys() => new List(); + + public DummyRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } } diff --git a/osu.Game/Input/ActionMappingInputManager.cs b/osu.Game/Input/ActionMappingInputManager.cs index 89e8686a2c..2e78b49b75 100644 --- a/osu.Game/Input/ActionMappingInputManager.cs +++ b/osu.Game/Input/ActionMappingInputManager.cs @@ -17,12 +17,20 @@ namespace osu.Game.Input public class ActionMappingInputManager : PassThroughInputManager where T : struct { + private readonly RulesetInfo ruleset; + + protected ActionMappingInputManager(RulesetInfo ruleset = null) + { + this.ruleset = ruleset; + } + protected IDictionary Mappings { get; set; } [BackgroundDependencyLoader] private void load(BindingStore bindings) { - foreach (var b in bindings.Query()) + var rulesetId = ruleset?.ID; + foreach (var b in bindings.Query(b => b.RulesetID == rulesetId)) Mappings[b.Key] = (T)(object)b.Action; } diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b3be36a983..4a492b84fb 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -15,12 +15,19 @@ namespace osu.Game.Rulesets { public abstract class Ruleset { + public readonly RulesetInfo RulesetInfo; + public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public abstract IEnumerable GetModsFor(ModType type); public abstract Mod GetAutoplayMod(); + protected Ruleset(RulesetInfo rulesetInfo) + { + RulesetInfo = rulesetInfo; + } + /// /// Attempt to create a hit renderer for a beatmap /// diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index 84ecb7718e..bc23649ede 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -20,6 +20,6 @@ namespace osu.Game.Rulesets [Indexed] public bool Available { get; set; } - public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo)); + public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this); } } \ No newline at end of file diff --git a/osu.Game/Rulesets/RulesetStore.cs b/osu.Game/Rulesets/RulesetStore.cs index 1564df1366..2956c11d7f 100644 --- a/osu.Game/Rulesets/RulesetStore.cs +++ b/osu.Game/Rulesets/RulesetStore.cs @@ -44,7 +44,7 @@ namespace osu.Game.Rulesets continue; foreach (Type rulesetType in rulesets) - instances.Add((Ruleset)Activator.CreateInstance(rulesetType)); + instances.Add((Ruleset)Activator.CreateInstance(rulesetType, new RulesetInfo())); } catch (Exception) { } } diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 244c3312c4..00f8e8a469 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -67,9 +67,16 @@ namespace osu.Game.Rulesets.UI /// protected abstract bool AllObjectsJudged { get; } - internal HitRenderer() + protected readonly Ruleset Ruleset; + + /// + /// A visual representation of a . + /// + /// The ruleset being repesented. + internal HitRenderer(Ruleset ruleset) { - KeyConversionInputManager = CreateKeyConversionInputManager(); + Ruleset = ruleset; + KeyConversionInputManager = CreateActionMappingInputManager(); KeyConversionInputManager.RelativeSizeAxes = Axes.Both; } @@ -88,7 +95,7 @@ namespace osu.Game.Rulesets.UI /// Creates a key conversion input manager. /// /// The input manager. - protected virtual PassThroughInputManager CreateKeyConversionInputManager() => new PassThroughInputManager(); + protected virtual PassThroughInputManager CreateActionMappingInputManager() => new PassThroughInputManager(); protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay); @@ -134,9 +141,10 @@ namespace osu.Game.Rulesets.UI /// /// Creates a hit renderer for a beatmap. /// + /// The ruleset being repesented. /// The beatmap to create the hit renderer for. /// Whether to assume the beatmap is for the current ruleset. - internal HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) + internal HitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(ruleset) { Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap."); @@ -236,10 +244,11 @@ namespace osu.Game.Rulesets.UI /// /// Creates a hit renderer for a beatmap. /// + /// The ruleset being repesented. /// The beatmap to create the hit renderer for. /// Whether to assume the beatmap is for the current ruleset. - protected HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + protected HitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { InputManager.Add(content = new Container { @@ -343,10 +352,11 @@ namespace osu.Game.Rulesets.UI /// /// Creates a hit renderer for a beatmap. /// + /// The ruleset being repesented. /// The beatmap to create the hit renderer for. /// Whether to assume the beatmap is for the current ruleset. - protected HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + protected HitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } } diff --git a/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs b/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs index da4340ac7a..37df08ba21 100644 --- a/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs +++ b/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs @@ -32,8 +32,8 @@ namespace osu.Game.Rulesets.UI /// protected readonly SortedList DefaultControlPoints = new SortedList(Comparer.Default); - protected ScrollingHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + protected ScrollingHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { }