From 4eec59f669684fcb32758e95b3fc5a6521a58fca Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 22 Aug 2017 13:01:51 +0900 Subject: [PATCH] Only set the number of availableColumns once, at ManiaRulesetContainer level. # Conflicts: # osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs # osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs # osu.Game/Rulesets/UI/RulesetContainer.cs --- .../Beatmaps/ManiaBeatmapConverter.cs | 14 ++++++++++--- .../Beatmaps/Patterns/PatternGenerator.cs | 4 +--- .../UI/ManiaRulesetContainer.cs | 20 +++++++++---------- osu.Game/Rulesets/UI/RulesetContainer.cs | 19 +++++++++++++----- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs index b55b9fdb37..e5a3c7849e 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs @@ -28,12 +28,18 @@ namespace osu.Game.Rulesets.Mania.Beatmaps private Pattern lastPattern = new Pattern(); private FastRandom random; private Beatmap beatmap; - private bool isForCurrentRuleset; - protected override Beatmap ConvertBeatmap(Beatmap original, bool isForCurrentRuleset) + private readonly int availableColumns; + private readonly bool isForCurrentRuleset; + + public ManiaBeatmapConverter(bool isForCurrentRuleset, int availableColumns) { this.isForCurrentRuleset = isForCurrentRuleset; + this.availableColumns = availableColumns; + } + protected override Beatmap ConvertBeatmap(Beatmap original) + { beatmap = original; BeatmapDifficulty difficulty = original.BeatmapInfo.Difficulty; @@ -89,7 +95,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps /// The hit objects generated. private IEnumerable generateSpecific(HitObject original) { - var generator = new SpecificBeatmapPatternGenerator(random, original, beatmap, lastPattern); + var generator = new SpecificBeatmapPatternGenerator(random, original, beatmap, lastPattern) { AvailableColumns = availableColumns }; Pattern newPattern = generator.Generate(); lastPattern = newPattern; @@ -128,6 +134,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps if (conversion == null) return null; + conversion.AvailableColumns = availableColumns; + Pattern newPattern = conversion.Generate(); lastPattern = newPattern; diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/PatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/PatternGenerator.cs index dda4d07182..6b85a51402 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/PatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/PatternGenerator.cs @@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns /// /// The number of columns available to create the pattern. /// - protected readonly int AvailableColumns; + public int AvailableColumns; /// /// The last pattern. @@ -37,8 +37,6 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns PreviousPattern = previousPattern; HitObject = hitObject; Beatmap = beatmap; - - AvailableColumns = (int)Math.Round(beatmap.BeatmapInfo.Difficulty.CircleSize); } /// diff --git a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index 9584dc34b8..58ce05b165 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -33,9 +33,10 @@ namespace osu.Game.Rulesets.Mania.UI public class ManiaRulesetContainer : ScrollingRulesetContainer { /// - /// Preferred column count. This will only have an effect during the initialization of the play field. + /// The number of columns which the should display, and which + /// the beatmap converter will attempt to convert beatmaps to use. /// - public int PreferredColumns; + private int availableColumns; public IEnumerable BarLines; @@ -76,14 +77,7 @@ namespace osu.Game.Rulesets.Mania.UI BarLines.ForEach(Playfield.Add); } - protected override void ApplyBeatmap() - { - base.ApplyBeatmap(); - - PreferredColumns = (int)Math.Max(1, Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize)); - } - - protected sealed override Playfield CreatePlayfield() => new ManiaPlayfield(PreferredColumns) + protected sealed override Playfield CreatePlayfield() => new ManiaPlayfield(availableColumns) { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -95,7 +89,11 @@ namespace osu.Game.Rulesets.Mania.UI public override PassThroughInputManager CreateInputManager() => new ManiaInputManager(Ruleset.RulesetInfo); - protected override BeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(); + protected override BeatmapConverter CreateBeatmapConverter() + { + availableColumns = (int)Math.Max(1, Math.Round(WorkingBeatmap.BeatmapInfo.Difficulty.CircleSize)); + return new ManiaBeatmapConverter(IsForCurrentRuleset, availableColumns); + } protected override DrawableHitObject GetVisualRepresentation(ManiaHitObject h) { diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 5b19200f2d..c7240448b9 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -139,16 +139,25 @@ namespace osu.Game.Rulesets.UI protected IEnumerable Mods; /// + /// The this was created with. + /// + protected readonly WorkingBeatmap WorkingBeatmap; + + /// + /// Whether to assume the beatmap passed into this is for the current ruleset. /// Creates a hit renderer for a beatmap. /// /// The ruleset being repesented. - /// The beatmap to create the hit renderer for. + /// The beatmap to create the hit renderer for. /// Whether to assume the beatmap is for the current ruleset. internal RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(ruleset) + internal RulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap, bool isForCurrentRuleset) + : base(ruleset) { - Debug.Assert(beatmap != null, "RulesetContainer initialized with a null beatmap."); + Debug.Assert(workingBeatmap != null, "RulesetContainer initialized with a null beatmap."); - Mods = beatmap.Mods.Value; + WorkingBeatmap = workingBeatmap; + Mods = workingBeatmap.Mods.Value; RelativeSizeAxes = Axes.Both; @@ -156,11 +165,11 @@ namespace osu.Game.Rulesets.UI BeatmapProcessor processor = CreateBeatmapProcessor(); // Check if the beatmap can be converted - if (!converter.CanConvert(beatmap.Beatmap)) + if (!converter.CanConvert(workingBeatmap.Beatmap)) throw new BeatmapInvalidForRulesetException($"{nameof(Beatmap)} can not be converted for the current ruleset (converter: {converter})."); // Convert the beatmap - Beatmap = converter.Convert(beatmap.Beatmap, isForCurrentRuleset); + Beatmap = converter.Convert(workingBeatmap.Beatmap, isForCurrentRuleset); // Apply difficulty adjustments from mods before using Difficulty. foreach (var mod in Mods.OfType())