1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:52:54 +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) typeof(CircularDistanceSnapGrid)
}; };
[Cached(typeof(IEditorBeatmap))] [Cached(typeof(EditorBeatmap))]
private readonly EditorBeatmap editorBeatmap; private readonly EditorBeatmap editorBeatmap;
[Cached] [Cached]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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