1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 09:23:06 +08:00

Move EditorBeatmap construction/conversion to Editor

This commit is contained in:
smoogipoo 2019-12-27 19:46:33 +09:00
parent 6069d98ced
commit 8c378dc625
12 changed files with 53 additions and 95 deletions

View File

@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Osu.Tests
typeof(CircularDistanceSnapGrid)
};
[Cached(typeof(IEditorBeatmap))]
[Cached(typeof(EditorBeatmap))]
private readonly EditorBeatmap editorBeatmap;
[Cached]

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tests.Visual.Editor
private const double beat_length = 100;
private static readonly Vector2 grid_position = new Vector2(512, 384);
[Cached(typeof(IEditorBeatmap))]
[Cached(typeof(EditorBeatmap))]
private readonly EditorBeatmap editorBeatmap;
[Cached(typeof(IDistanceSnapProvider))]

View File

@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Edit
private readonly DrawableRuleset<TObject> drawableRuleset;
[Resolved]
private IEditorBeatmap beatmap { get; set; }
private EditorBeatmap beatmap { get; set; }
public DrawableEditRulesetWrapper(DrawableRuleset<TObject> drawableRuleset)
{

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
@ -35,20 +34,20 @@ namespace osu.Game.Rulesets.Edit
{
protected IRulesetConfigManager Config { get; private set; }
protected new EditorBeatmap EditorBeatmap { get; private set; }
protected readonly Ruleset Ruleset;
[Resolved]
protected IFrameBasedClock EditorClock { get; private set; }
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; }
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
[Resolved]
private BindableBeatDivisor beatDivisor { get; set; }
private Beatmap<TObject> playableBeatmap;
private IBeatmapProcessor beatmapProcessor;
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
@ -68,9 +67,17 @@ namespace osu.Game.Rulesets.Edit
[BackgroundDependencyLoader]
private void load(IFrameBasedClock framedClock)
{
beatmapProcessor = Ruleset.CreateBeatmapProcessor(EditorBeatmap.PlayableBeatmap);
EditorBeatmap.HitObjectAdded += addHitObject;
EditorBeatmap.HitObjectRemoved += removeHitObject;
EditorBeatmap.StartTimeChanged += UpdateHitObject;
Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
try
{
drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, playableBeatmap))
drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap))
{
Clock = framedClock,
ProcessCustomClock = false
@ -140,27 +147,6 @@ namespace osu.Game.Rulesets.Edit
blueprintContainer.SelectionChanged += selectionChanged;
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var parentWorkingBeatmap = parent.Get<IBindable<WorkingBeatmap>>().Value;
playableBeatmap = (Beatmap<TObject>)parentWorkingBeatmap.GetPlayableBeatmap(Ruleset.RulesetInfo);
beatmapProcessor = Ruleset.CreateBeatmapProcessor(playableBeatmap);
base.EditorBeatmap = EditorBeatmap = new EditorBeatmap(playableBeatmap);
EditorBeatmap.HitObjectAdded += addHitObject;
EditorBeatmap.HitObjectRemoved += removeHitObject;
EditorBeatmap.StartTimeChanged += UpdateHitObject;
var dependencies = new DependencyContainer(parent);
dependencies.CacheAs<IEditorBeatmap>(EditorBeatmap);
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
return base.CreateChildDependencies(dependencies);
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -233,7 +219,7 @@ namespace osu.Game.Rulesets.Edit
scheduledUpdate = Schedule(() =>
{
beatmapProcessor?.PreProcess();
hitObject?.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
hitObject?.ApplyDefaults(EditorBeatmap.ControlPointInfo, EditorBeatmap.BeatmapInfo.BaseDifficulty);
beatmapProcessor?.PostProcess();
});
}
@ -332,11 +318,6 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public abstract IEnumerable<DrawableHitObject> HitObjects { get; }
/// <summary>
/// An editor-specific beatmap, exposing mutation events.
/// </summary>
public IEditorBeatmap EditorBeatmap { get; protected set; }
/// <summary>
/// Whether the user's cursor is currently in an area of the <see cref="HitObjectComposer"/> that is valid for placement.
/// </summary>

View File

@ -40,7 +40,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private HitObjectComposer composer { get; set; }
[Resolved]
private IEditorBeatmap beatmap { get; set; }
private EditorBeatmap beatmap { get; set; }
public BlueprintContainer()
{

View File

@ -45,7 +45,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected IDistanceSnapProvider SnapProvider { get; private set; }
[Resolved]
private IEditorBeatmap beatmap { get; set; }
private EditorBeatmap beatmap { get; set; }
[Resolved]
private BindableBeatDivisor beatDivisor { get; set; }

View File

@ -16,9 +16,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
internal class TimelineHitObjectDisplay : TimelinePart
{
private IEditorBeatmap beatmap { get; }
private EditorBeatmap beatmap { get; }
public TimelineHitObjectDisplay(IEditorBeatmap beatmap)
public TimelineHitObjectDisplay(EditorBeatmap beatmap)
{
RelativeSizeAxes = Axes.Both;

View File

@ -32,6 +32,6 @@ namespace osu.Game.Screens.Edit.Compose
return beatmapSkinProvider.WithChild(rulesetSkinProvider.WithChild(composer));
}
protected override Drawable CreateTimelineContent() => composer == null ? base.CreateTimelineContent() : new TimelineHitObjectDisplay(composer.EditorBeatmap);
protected override Drawable CreateTimelineContent() => composer == null ? base.CreateTimelineContent() : new TimelineHitObjectDisplay(EditorBeatmap);
}
}

View File

@ -23,6 +23,7 @@ using osuTK.Input;
using System.Collections.Generic;
using osu.Framework;
using osu.Framework.Input.Bindings;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Cursor;
using osu.Game.Input.Bindings;
using osu.Game.Screens.Edit.Compose;
@ -49,9 +50,11 @@ namespace osu.Game.Screens.Edit
private EditorScreen currentScreen;
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
private EditorClock clock;
private IBeatmap playableBeatmap;
private EditorBeatmap editorBeatmap;
private DependencyContainer dependencies;
private GameHost host;
@ -73,9 +76,13 @@ namespace osu.Game.Screens.Edit
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
clock.ChangeSource(sourceClock);
playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
editorBeatmap = new EditorBeatmap(playableBeatmap);
dependencies.CacheAs<IFrameBasedClock>(clock);
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.Cache(beatDivisor);
dependencies.CacheAs(editorBeatmap);
EditorMenuBar menuBar;

View File

@ -12,7 +12,7 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit
{
public class EditorBeatmap : IEditorBeatmap
public class EditorBeatmap : IBeatmap
{
/// <summary>
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
@ -29,12 +29,13 @@ namespace osu.Game.Screens.Edit
/// </summary>
public event Action<HitObject> StartTimeChanged;
private readonly Dictionary<HitObject, Bindable<double>> startTimeBindables = new Dictionary<HitObject, Bindable<double>>();
private readonly IBeatmap beatmap;
public readonly IBeatmap PlayableBeatmap;
public EditorBeatmap(IBeatmap beatmap)
private readonly Dictionary<HitObject, Bindable<double>> startTimeBindables = new Dictionary<HitObject, Bindable<double>>();
public EditorBeatmap(IBeatmap playableBeatmap)
{
this.beatmap = beatmap;
PlayableBeatmap = playableBeatmap;
foreach (var obj in HitObjects)
trackStartTime(obj);
@ -42,23 +43,21 @@ namespace osu.Game.Screens.Edit
public BeatmapInfo BeatmapInfo
{
get => beatmap.BeatmapInfo;
set => beatmap.BeatmapInfo = value;
get => PlayableBeatmap.BeatmapInfo;
set => PlayableBeatmap.BeatmapInfo = value;
}
public BeatmapMetadata Metadata => beatmap.Metadata;
public BeatmapMetadata Metadata => PlayableBeatmap.Metadata;
public ControlPointInfo ControlPointInfo => beatmap.ControlPointInfo;
public ControlPointInfo ControlPointInfo => PlayableBeatmap.ControlPointInfo;
public List<BreakPeriod> Breaks => beatmap.Breaks;
public List<BreakPeriod> Breaks => PlayableBeatmap.Breaks;
public double TotalBreakTime => beatmap.TotalBreakTime;
public double TotalBreakTime => PlayableBeatmap.TotalBreakTime;
public IReadOnlyList<HitObject> HitObjects => beatmap.HitObjects;
public IReadOnlyList<HitObject> HitObjects => PlayableBeatmap.HitObjects;
IReadOnlyList<HitObject> IBeatmap.HitObjects => beatmap.HitObjects;
public IEnumerable<BeatmapStatistic> GetStatistics() => beatmap.GetStatistics();
public IEnumerable<BeatmapStatistic> GetStatistics() => PlayableBeatmap.GetStatistics();
public IBeatmap Clone() => (EditorBeatmap)MemberwiseClone();
@ -71,8 +70,8 @@ namespace osu.Game.Screens.Edit
trackStartTime(hitObject);
// Preserve existing sorting order in the beatmap
var insertionIndex = findInsertionIndex(beatmap.HitObjects, hitObject.StartTime);
((IList)beatmap.HitObjects).Insert(insertionIndex + 1, hitObject);
var insertionIndex = findInsertionIndex(PlayableBeatmap.HitObjects, hitObject.StartTime);
((IList)PlayableBeatmap.HitObjects).Insert(insertionIndex + 1, hitObject);
HitObjectAdded?.Invoke(hitObject);
}
@ -83,10 +82,10 @@ namespace osu.Game.Screens.Edit
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
public void Remove(HitObject hitObject)
{
if (!((IList)beatmap.HitObjects).Contains(hitObject))
if (!((IList)PlayableBeatmap.HitObjects).Contains(hitObject))
return;
((IList)beatmap.HitObjects).Remove(hitObject);
((IList)PlayableBeatmap.HitObjects).Remove(hitObject);
var bindable = startTimeBindables[hitObject];
bindable.UnbindAll();
@ -101,10 +100,10 @@ namespace osu.Game.Screens.Edit
startTimeBindables[hitObject].ValueChanged += _ =>
{
// For now we'll remove and re-add the hitobject. This is not optimal and can be improved if required.
((IList)beatmap.HitObjects).Remove(hitObject);
((IList)PlayableBeatmap.HitObjects).Remove(hitObject);
var insertionIndex = findInsertionIndex(beatmap.HitObjects, hitObject.StartTime);
((IList)beatmap.HitObjects).Insert(insertionIndex + 1, hitObject);
var insertionIndex = findInsertionIndex(PlayableBeatmap.HitObjects, hitObject.StartTime);
((IList)PlayableBeatmap.HitObjects).Insert(insertionIndex + 1, hitObject);
StartTimeChanged?.Invoke(hitObject);
};

View File

@ -17,6 +17,9 @@ namespace osu.Game.Screens.Edit
[Resolved]
protected IBindable<WorkingBeatmap> Beatmap { get; private set; }
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; }
protected override Container<Drawable> Content => content;
private readonly Container content;

View File

@ -1,32 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Edit
{
/// <summary>
/// Interface for the <see cref="IBeatmap"/> contained by the see <see cref="HitObjectComposer"/>.
/// Children of <see cref="HitObjectComposer"/> may resolve the beatmap via <see cref="IEditorBeatmap"/>.
/// </summary>
public interface IEditorBeatmap : IBeatmap
{
/// <summary>
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="IEditorBeatmap"/>.
/// </summary>
event Action<HitObject> HitObjectAdded;
/// <summary>
/// Invoked when a <see cref="HitObject"/> is removed from this <see cref="IEditorBeatmap"/>.
/// </summary>
event Action<HitObject> HitObjectRemoved;
/// <summary>
/// Invoked when the start time of a <see cref="HitObject"/> in this <see cref="EditorBeatmap"/> was changed.
/// </summary>
event Action<HitObject> StartTimeChanged;
}
}