// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Edit { public abstract class EditRulesetContainer : CompositeDrawable { public Playfield Playfield => RulesetContainer.Playfield; protected abstract RulesetContainer RulesetContainer { get; } internal EditRulesetContainer() { RelativeSizeAxes = Axes.Both; } public abstract DrawableHitObject AddHitObject(HitObject hitObject); } public abstract class EditRulesetContainer : EditRulesetContainer where TObject : HitObject { private readonly Ruleset ruleset; private readonly RulesetContainer rulesetContainer; protected override RulesetContainer RulesetContainer => rulesetContainer; private Beatmap beatmap => rulesetContainer.Beatmap; protected EditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap) { this.ruleset = ruleset; InternalChild = rulesetContainer = CreateRulesetContainer(ruleset, workingBeatmap); } public override DrawableHitObject AddHitObject(HitObject hitObject) { var tObject = (TObject)hitObject; // Insert into beatmap while maintaining sorting order var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime); beatmap.HitObjects.Insert(insertionIndex + 1, tObject); var processor = ruleset.CreateBeatmapProcessor(beatmap); processor.PreProcess(); tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty); processor.PostProcess(); var drawableObject = rulesetContainer.GetVisualRepresentation(tObject); rulesetContainer.Playfield.Add(drawableObject); rulesetContainer.Playfield.PostProcess(); return drawableObject; } /// /// Creates the underlying . /// /// protected abstract RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap); } }