Merge branch 'editor-undo-redo' into more-change-state-support

This commit is contained in:
Dean Herbert 2020-04-13 18:07:00 +09:00
commit 0e88c28060
26 changed files with 778 additions and 162 deletions

View File

@ -52,6 +52,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.407.1" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2020.411.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -45,6 +45,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = 1, BorderThickness = 1,
BorderColour = colours.Yellow, BorderColour = colours.Yellow,
Child = new Box Child = new Box

View File

@ -0,0 +1,412 @@
// 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 System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Screens;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Replays;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestSceneOutOfOrderHits : RateAdjustedBeatmapTestScene
{
private const double early_miss_window = 1000; // time after -1000 to -500 is considered a miss
private const double late_miss_window = 500; // time after +500 is considered a miss
/// <summary>
/// Tests clicking a future circle before the first circle's start time, while the first circle HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleBeforeFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 100, Position = positionSecondCircle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Miss);
addJudgementOffsetAssert(hitObjects[0], late_miss_window);
}
/// <summary>
/// Tests clicking a future circle at the first circle's start time, while the first circle HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAtFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle, Position = positionSecondCircle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], 0);
}
/// <summary>
/// Tests clicking a future circle after the first circle's start time, while the first circle HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAfterFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle + 100, Position = positionSecondCircle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], 100);
}
/// <summary>
/// Tests clicking a future circle before the first circle's start time, while the first circle HAS been judged.
/// </summary>
[Test]
public void TestClickSecondCircleBeforeFirstCircleTimeWithFirstCircleJudged()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 200, Position = positionFirstCircle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_first_circle - 100, Position = positionSecondCircle, Actions = { OsuAction.RightButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], -200); // time_first_circle - 200
addJudgementOffsetAssert(hitObjects[0], -200); // time_second_circle - first_circle_time - 100
}
/// <summary>
/// Tests clicking a future circle after a slider's start time, but hitting all slider ticks.
/// </summary>
[Test]
public void TestMissSliderHeadAndHitAllSliderTicks()
{
const double time_slider = 1500;
const double time_circle = 1510;
Vector2 positionCircle = Vector2.Zero;
Vector2 positionSlider = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_circle,
Position = positionCircle
},
new TestSlider
{
StartTime = time_slider,
Position = positionSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_slider, Position = positionCircle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_slider + 10, Position = positionSlider, Actions = { OsuAction.RightButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementAssert("slider head", () => ((Slider)hitObjects[1]).HeadCircle, HitResult.Miss);
addJudgementAssert("slider tick", () => ((Slider)hitObjects[1]).NestedHitObjects[1] as SliderTick, HitResult.Great);
}
/// <summary>
/// Tests clicking hitting future slider ticks before a circle.
/// </summary>
[Test]
public void TestHitSliderTicksBeforeCircle()
{
const double time_slider = 1500;
const double time_circle = 1510;
Vector2 positionCircle = Vector2.Zero;
Vector2 positionSlider = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_circle,
Position = positionCircle
},
new TestSlider
{
StartTime = time_slider,
Position = positionSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_slider, Position = positionSlider, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_circle + late_miss_window - 100, Position = positionCircle, Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_circle + late_miss_window - 90, Position = positionSlider, Actions = { OsuAction.LeftButton } },
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementAssert("slider head", () => ((Slider)hitObjects[1]).HeadCircle, HitResult.Great);
addJudgementAssert("slider tick", () => ((Slider)hitObjects[1]).NestedHitObjects[1] as SliderTick, HitResult.Great);
}
/// <summary>
/// Tests clicking a future circle before a spinner.
/// </summary>
[Test]
public void TestHitCircleBeforeSpinner()
{
const double time_spinner = 1500;
const double time_circle = 1800;
Vector2 positionCircle = Vector2.Zero;
var hitObjects = new List<OsuHitObject>
{
new TestSpinner
{
StartTime = time_spinner,
Position = new Vector2(256, 192),
EndTime = time_spinner + 1000,
},
new TestHitCircle
{
StartTime = time_circle,
Position = positionCircle
},
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_spinner - 100, Position = positionCircle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_spinner + 10, Position = new Vector2(236, 192), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 20, Position = new Vector2(256, 172), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 30, Position = new Vector2(276, 192), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 40, Position = new Vector2(256, 212), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 50, Position = new Vector2(236, 192), Actions = { OsuAction.RightButton } },
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
}
private void addJudgementAssert(OsuHitObject hitObject, HitResult result)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judgement is {result}",
() => judgementResults.Single(r => r.HitObject == hitObject).Type == result);
}
private void addJudgementAssert(string name, Func<OsuHitObject> hitObject, HitResult result)
{
AddAssert($"{name} judgement is {result}",
() => judgementResults.Single(r => r.HitObject == hitObject()).Type == result);
}
private void addJudgementOffsetAssert(OsuHitObject hitObject, double offset)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judged at {offset}",
() => Precision.AlmostEquals(judgementResults.Single(r => r.HitObject == hitObject).TimeOffset, offset, 100));
}
private ScoreAccessibleReplayPlayer currentPlayer;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
private void performTest(List<OsuHitObject> hitObjects, List<ReplayFrame> frames)
{
AddStep("load player", () =>
{
Beatmap.Value = CreateWorkingBeatmap(new Beatmap<OsuHitObject>
{
HitObjects = hitObjects,
BeatmapInfo =
{
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 },
Ruleset = new OsuRuleset().RulesetInfo
},
});
Beatmap.Value.Beatmap.ControlPointInfo.Add(0, new DifficultyControlPoint { SpeedMultiplier = 0.1f });
var p = new ScoreAccessibleReplayPlayer(new Score { Replay = new Replay { Frames = frames } });
p.OnLoadComplete += _ =>
{
p.ScoreProcessor.NewJudgement += result =>
{
if (currentPlayer == p) judgementResults.Add(result);
};
p.ScoreProcessor.AllJudged += () =>
{
if (currentPlayer == p) allJudgedFired = true;
};
};
LoadScreen(currentPlayer = p);
allJudgedFired = false;
judgementResults = new List<JudgementResult>();
});
AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
AddUntilStep("Wait for all judged", () => allJudgedFired);
}
private class TestHitCircle : HitCircle
{
protected override HitWindows CreateHitWindows() => new TestHitWindows();
}
private class TestSlider : Slider
{
public TestSlider()
{
DefaultsApplied += () =>
{
HeadCircle.HitWindows = new TestHitWindows();
TailCircle.HitWindows = new TestHitWindows();
};
}
}
private class TestSpinner : Spinner
{
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
SpinsRequired = 1;
}
}
private class TestHitWindows : HitWindows
{
private static readonly DifficultyRange[] ranges =
{
new DifficultyRange(HitResult.Great, 500, 500, 500),
new DifficultyRange(HitResult.Miss, early_miss_window, early_miss_window, early_miss_window),
};
public override bool IsHitResultAllowed(HitResult result) => result == HitResult.Great || result == HitResult.Miss;
protected override DifficultyRange[] GetRanges() => ranges;
}
private class ScoreAccessibleReplayPlayer : ReplayPlayer
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
protected override bool PauseOnFocusLost => false;
public ScoreAccessibleReplayPlayer(Score score)
: base(score, false, false)
{
}
}
}
}

View File

@ -120,7 +120,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
var result = HitObject.HitWindows.ResultFor(timeOffset); var result = HitObject.HitWindows.ResultFor(timeOffset);
if (result == HitResult.None) if (result == HitResult.None || CheckHittable?.Invoke(this, Time.Current) == false)
{ {
Shake(Math.Abs(timeOffset) - HitObject.HitWindows.WindowFor(HitResult.Miss)); Shake(Math.Abs(timeOffset) - HitObject.HitWindows.WindowFor(HitResult.Miss));
return; return;

View File

@ -1,11 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Objects.Drawables namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
@ -16,6 +18,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
// Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects. // Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects.
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
/// <summary>
/// Whether this <see cref="DrawableOsuHitObject"/> can be hit.
/// If non-null, judgements will be ignored (resulting in a shake) whilst the function returns false.
/// </summary>
public Func<DrawableHitObject, double, bool> CheckHittable;
protected DrawableOsuHitObject(OsuHitObject hitObject) protected DrawableOsuHitObject(OsuHitObject hitObject)
: base(hitObject) : base(hitObject)
{ {
@ -54,6 +62,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
} }
} }
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void MissForcefully() => ApplyResult(r => r.Type = HitResult.Miss);
protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement); protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement);
} }
} }

View File

@ -124,7 +124,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
case SliderTailCircle tail: case SliderTailCircle tail:
return new DrawableSliderTail(slider, tail); return new DrawableSliderTail(slider, tail);
case HitCircle head: case SliderHeadCircle head:
return new DrawableSliderHead(slider, head) { OnShake = Shake }; return new DrawableSliderHead(slider, head) { OnShake = Shake };
case SliderTick tick: case SliderTick tick:

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private readonly Slider slider; private readonly Slider slider;
public DrawableSliderHead(Slider slider, HitCircle h) public DrawableSliderHead(Slider slider, SliderHeadCircle h)
: base(h) : base(h)
{ {
this.slider = slider; this.slider = slider;

View File

@ -155,7 +155,7 @@ namespace osu.Game.Rulesets.Osu.Objects
break; break;
case SliderEventType.Head: case SliderEventType.Head:
AddNested(HeadCircle = new SliderCircle AddNested(HeadCircle = new SliderHeadCircle
{ {
StartTime = e.Time, StartTime = e.Time,
Position = Position, Position = Position,

View File

@ -0,0 +1,9 @@
// 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.
namespace osu.Game.Rulesets.Osu.Objects
{
public class SliderHeadCircle : HitCircle
{
}
}

View File

@ -0,0 +1,127 @@
// 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 osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.UI
{
/// <summary>
/// Ensures that <see cref="HitObject"/>s are hit in-order.
/// If a <see cref="HitObject"/> is hit out of order:
/// <list type="number">
/// <item><description>The hit is blocked if it occurred earlier than the previous <see cref="HitObject"/>'s start time.</description></item>
/// <item><description>The hit causes all previous <see cref="HitObject"/>s to missed otherwise.</description></item>
/// </list>
/// </summary>
public class OrderedHitPolicy
{
private readonly HitObjectContainer hitObjectContainer;
public OrderedHitPolicy(HitObjectContainer hitObjectContainer)
{
this.hitObjectContainer = hitObjectContainer;
}
/// <summary>
/// Determines whether a <see cref="DrawableHitObject"/> can be hit at a point in time.
/// </summary>
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to check.</param>
/// <param name="time">The time to check.</param>
/// <returns>Whether <paramref name="hitObject"/> can be hit at the given <paramref name="time"/>.</returns>
public bool IsHittable(DrawableHitObject hitObject, double time)
{
DrawableHitObject blockingObject = null;
// Find the last hitobject which blocks future hits.
foreach (var obj in hitObjectContainer.AliveObjects)
{
if (obj == hitObject)
break;
if (drawableCanBlockFutureHits(obj))
blockingObject = obj;
}
// If there is no previous hitobject, allow the hit.
if (blockingObject == null)
return true;
// A hit is allowed if:
// 1. The last blocking hitobject has been judged.
// 2. The current time is after the last hitobject's start time.
// Hits at exactly the same time as the blocking hitobject are allowed for maps that contain simultaneous hitobjects (e.g. /b/372245).
if (blockingObject.Judged || time >= blockingObject.HitObject.StartTime)
return true;
return false;
}
/// <summary>
/// Handles a <see cref="HitObject"/> being hit to potentially miss all earlier <see cref="HitObject"/>s.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> that was hit.</param>
public void HandleHit(HitObject hitObject)
{
// Hitobjects which themselves don't block future hitobjects don't cause misses (e.g. slider ticks, spinners).
if (!hitObjectCanBlockFutureHits(hitObject))
return;
double maximumTime = hitObject.StartTime;
// Iterate through and apply miss results to all top-level and nested hitobjects which block future hits.
foreach (var obj in hitObjectContainer.AliveObjects)
{
if (obj.Judged || obj.HitObject.StartTime >= maximumTime)
continue;
if (hitObjectCanBlockFutureHits(obj.HitObject))
applyMiss(obj);
foreach (var nested in obj.NestedHitObjects)
{
if (nested.Judged || nested.HitObject.StartTime >= maximumTime)
continue;
if (hitObjectCanBlockFutureHits(nested.HitObject))
applyMiss(nested);
}
}
static void applyMiss(DrawableHitObject obj) => ((DrawableOsuHitObject)obj).MissForcefully();
}
/// <summary>
/// Whether a <see cref="DrawableHitObject"/> blocks hits on future <see cref="DrawableHitObject"/>s until its start time is reached.
/// </summary>
/// <remarks>
/// This will ONLY match on top-most <see cref="DrawableHitObject"/>s.
/// </remarks>
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to test.</param>
private static bool drawableCanBlockFutureHits(DrawableHitObject hitObject)
{
// Special considerations for slider tails aren't required since only top-most drawable hitobjects are being iterated over.
return hitObject is DrawableHitCircle || hitObject is DrawableSlider;
}
/// <summary>
/// Whether a <see cref="HitObject"/> blocks hits on future <see cref="HitObject"/>s until its start time is reached.
/// </summary>
/// <remarks>
/// This is more rigorous and may not match on top-most <see cref="HitObject"/>s as <see cref="drawableCanBlockFutureHits"/> does.
/// </remarks>
/// <param name="hitObject">The <see cref="HitObject"/> to test.</param>
private static bool hitObjectCanBlockFutureHits(HitObject hitObject)
{
// Unlike the above we will receive slider tails, but they do not block future hits.
if (hitObject is SliderTailCircle)
return false;
// All other hitcircles continue to block future hits.
return hitObject is HitCircle;
}
}
}

View File

@ -20,6 +20,7 @@ namespace osu.Game.Rulesets.Osu.UI
private readonly ApproachCircleProxyContainer approachCircles; private readonly ApproachCircleProxyContainer approachCircles;
private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer; private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
private readonly FollowPointRenderer followPoints; private readonly FollowPointRenderer followPoints;
private readonly OrderedHitPolicy hitPolicy;
public static readonly Vector2 BASE_SIZE = new Vector2(512, 384); public static readonly Vector2 BASE_SIZE = new Vector2(512, 384);
@ -51,6 +52,8 @@ namespace osu.Game.Rulesets.Osu.UI
Depth = -1, Depth = -1,
}, },
}; };
hitPolicy = new OrderedHitPolicy(HitObjectContainer);
} }
public override void Add(DrawableHitObject h) public override void Add(DrawableHitObject h)
@ -64,7 +67,10 @@ namespace osu.Game.Rulesets.Osu.UI
base.Add(h); base.Add(h);
followPoints.AddFollowPoints((DrawableOsuHitObject)h); DrawableOsuHitObject osuHitObject = (DrawableOsuHitObject)h;
osuHitObject.CheckHittable = hitPolicy.IsHittable;
followPoints.AddFollowPoints(osuHitObject);
} }
public override bool Remove(DrawableHitObject h) public override bool Remove(DrawableHitObject h)
@ -79,6 +85,9 @@ namespace osu.Game.Rulesets.Osu.UI
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result) private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{ {
// Hitobjects that block future hits should miss previous hitobjects if they're hit out-of-order.
hitPolicy.HandleHit(result.HitObject);
if (!judgedObject.DisplayResult || !DisplayJudgements.Value) if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
return; return;

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Internal;
using NUnit.Framework; using NUnit.Framework;
@ -162,5 +163,69 @@ namespace osu.Game.Tests.Beatmaps
Assert.That(editorBeatmap.HitObjects.Count(h => h == hitCircle), Is.EqualTo(1)); Assert.That(editorBeatmap.HitObjects.Count(h => h == hitCircle), Is.EqualTo(1));
Assert.That(editorBeatmap.HitObjects.IndexOf(hitCircle), Is.EqualTo(1)); Assert.That(editorBeatmap.HitObjects.IndexOf(hitCircle), Is.EqualTo(1));
} }
/// <summary>
/// Tests that multiple hitobjects are updated simultaneously.
/// </summary>
[Test]
public void TestMultipleHitObjectUpdate()
{
var updatedObjects = new List<HitObject>();
var allHitObjects = new List<HitObject>();
EditorBeatmap editorBeatmap = null;
AddStep("add beatmap", () =>
{
updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
for (int i = 0; i < 10; i++)
{
var h = new HitCircle();
editorBeatmap.Add(h);
allHitObjects.Add(h);
}
});
AddStep("change all start times", () =>
{
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
for (int i = 0; i < 10; i++)
allHitObjects[i].StartTime += 10;
});
// Distinct ensures that all hitobjects have been updated once, debounce is tested below.
AddAssert("all hitobjects updated", () => updatedObjects.Distinct().Count() == 10);
}
/// <summary>
/// Tests that hitobject updates are debounced when they happen too soon.
/// </summary>
[Test]
public void TestDebouncedUpdate()
{
var updatedObjects = new List<HitObject>();
EditorBeatmap editorBeatmap = null;
AddStep("add beatmap", () =>
{
updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
editorBeatmap.Add(new HitCircle());
});
AddStep("change start time twice", () =>
{
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
editorBeatmap.HitObjects[0].StartTime = 10;
editorBeatmap.HitObjects[0].StartTime = 20;
});
AddAssert("only updated once", () => updatedObjects.Count == 1);
}
} }
} }

View File

@ -20,15 +20,15 @@ using Decoder = osu.Game.Beatmaps.Formats.Decoder;
namespace osu.Game.Tests.Editor namespace osu.Game.Tests.Editor
{ {
[TestFixture] [TestFixture]
public class LegacyEditorBeatmapDifferTest public class LegacyEditorBeatmapPatcherTest
{ {
private LegacyEditorBeatmapDiffer differ; private LegacyEditorBeatmapPatcher patcher;
private EditorBeatmap current; private EditorBeatmap current;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
differ = new LegacyEditorBeatmapDiffer(current = new EditorBeatmap(new OsuBeatmap patcher = new LegacyEditorBeatmapPatcher(current = new EditorBeatmap(new OsuBeatmap
{ {
BeatmapInfo = BeatmapInfo =
{ {
@ -312,30 +312,30 @@ namespace osu.Game.Tests.Editor
patch = decode(encode(patch)); patch = decode(encode(patch));
// Apply the patch. // Apply the patch.
differ.Patch(encode(current), encode(patch)); patcher.Patch(encode(current), encode(patch));
// Convert beatmaps to strings for assertion purposes. // Convert beatmaps to strings for assertion purposes.
string currentStr = Encoding.ASCII.GetString(encode(current).ToArray()); string currentStr = Encoding.ASCII.GetString(encode(current));
string patchStr = Encoding.ASCII.GetString(encode(patch).ToArray()); string patchStr = Encoding.ASCII.GetString(encode(patch));
Assert.That(currentStr, Is.EqualTo(patchStr)); Assert.That(currentStr, Is.EqualTo(patchStr));
} }
private MemoryStream encode(IBeatmap beatmap) private byte[] encode(IBeatmap beatmap)
{ {
var encoded = new MemoryStream(); using (var encoded = new MemoryStream())
{
using (var sw = new StreamWriter(encoded, leaveOpen: true)) using (var sw = new StreamWriter(encoded))
new LegacyBeatmapEncoder(beatmap).Encode(sw); new LegacyBeatmapEncoder(beatmap).Encode(sw);
return encoded; return encoded.ToArray();
}
} }
private IBeatmap decode(Stream stream) private IBeatmap decode(byte[] state)
{ {
stream.Seek(0, SeekOrigin.Begin); using (var stream = new MemoryStream(state))
using (var reader = new LineBufferedReader(stream))
using (var reader = new LineBufferedReader(stream, true))
return Decoder.GetDecoder<Beatmap>(reader).Decode(reader); return Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
} }
} }

View File

@ -20,26 +20,30 @@ namespace osu.Game.Tests.Visual.Navigation
public void TestFromMainMenu() public void TestFromMainMenu()
{ {
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
var secondimport = importBeatmap(3);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
returnToMenu();
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
var secondimport = importBeatmap(2);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
returnToMenu();
presentSecondDifficultyAndConfirm(firstImport, 1);
returnToMenu();
presentSecondDifficultyAndConfirm(secondimport, 3);
} }
[Test] [Test]
public void TestFromMainMenuDifferentRuleset() public void TestFromMainMenuDifferentRuleset()
{ {
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
var secondimport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
returnToMenu();
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
var secondimport = importBeatmap(2, new ManiaRuleset().RulesetInfo);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
returnToMenu();
presentSecondDifficultyAndConfirm(firstImport, 1);
returnToMenu();
presentSecondDifficultyAndConfirm(secondimport, 3);
} }
[Test] [Test]
@ -48,8 +52,11 @@ namespace osu.Game.Tests.Visual.Navigation
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
var secondimport = importBeatmap(2); var secondimport = importBeatmap(3);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
presentSecondDifficultyAndConfirm(firstImport, 1);
presentSecondDifficultyAndConfirm(secondimport, 3);
} }
[Test] [Test]
@ -58,8 +65,17 @@ namespace osu.Game.Tests.Visual.Navigation
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
var secondimport = importBeatmap(2, new ManiaRuleset().RulesetInfo); var secondimport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
presentSecondDifficultyAndConfirm(firstImport, 1);
presentSecondDifficultyAndConfirm(secondimport, 3);
}
private void returnToMenu()
{
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
} }
private Func<BeatmapSetInfo> importBeatmap(int i, RulesetInfo ruleset = null) private Func<BeatmapSetInfo> importBeatmap(int i, RulesetInfo ruleset = null)
@ -89,6 +105,13 @@ namespace osu.Game.Tests.Visual.Navigation
BaseDifficulty = difficulty, BaseDifficulty = difficulty,
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
}, },
new BeatmapInfo
{
OnlineBeatmapID = i * 2048,
Metadata = metadata,
BaseDifficulty = difficulty,
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
},
} }
}).Result; }).Result;
}); });
@ -106,5 +129,15 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapSetInfo.ID == getImport().ID); AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapSetInfo.ID == getImport().ID);
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID); AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID);
} }
private void presentSecondDifficultyAndConfirm(Func<BeatmapSetInfo> getImport, int importedID)
{
Predicate<BeatmapInfo> pred = b => b.OnlineBeatmapID == importedID * 2048;
AddStep("present difficulty", () => Game.PresentBeatmap(getImport(), pred));
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineBeatmapID == importedID * 2048);
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID);
}
} }
} }

View File

@ -24,7 +24,6 @@ namespace osu.Game.Tests.Visual.Online
typeof(ChangelogListing), typeof(ChangelogListing),
typeof(ChangelogSingleBuild), typeof(ChangelogSingleBuild),
typeof(ChangelogBuild), typeof(ChangelogBuild),
typeof(Comments),
}; };
protected override bool UseOnlineAPI => true; protected override bool UseOnlineAPI => true;

View File

@ -315,8 +315,15 @@ namespace osu.Game
/// The user should have already requested this interactively. /// The user should have already requested this interactively.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap to select.</param> /// <param name="beatmap">The beatmap to select.</param>
public void PresentBeatmap(BeatmapSetInfo beatmap) /// <param name="difficultyCriteria">
/// Optional predicate used to try and find a difficulty to select.
/// If omitted, this will try to present the first beatmap from the current ruleset.
/// In case of failure the first difficulty of the set will be presented, ignoring the predicate.
/// </param>
public void PresentBeatmap(BeatmapSetInfo beatmap, Predicate<BeatmapInfo> difficultyCriteria = null)
{ {
difficultyCriteria ??= b => b.Ruleset.Equals(Ruleset.Value);
var databasedSet = beatmap.OnlineBeatmapSetID != null var databasedSet = beatmap.OnlineBeatmapSetID != null
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID) ? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID)
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash); : BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash);
@ -334,13 +341,13 @@ namespace osu.Game
menuScreen.LoadToSolo(); menuScreen.LoadToSolo();
// we might even already be at the song // we might even already be at the song
if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash) if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash && difficultyCriteria(Beatmap.Value.BeatmapInfo))
{ {
return; return;
} }
// Use first beatmap available for current ruleset, else switch ruleset. // Find first beatmap that matches our predicate.
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First(); var first = databasedSet.Beatmaps.Find(difficultyCriteria) ?? databasedSet.Beatmaps.First();
Ruleset.Value = first.Ruleset; Ruleset.Value = first.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first); Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first);

View File

@ -277,7 +277,8 @@ namespace osu.Game.Overlays.BeatmapSet
downloadButtonsContainer.Child = new PanelDownloadButton(BeatmapSet.Value) downloadButtonsContainer.Child = new PanelDownloadButton(BeatmapSet.Value)
{ {
Width = 50, Width = 50,
RelativeSizeAxes = Axes.Y RelativeSizeAxes = Axes.Y,
SelectedBeatmap = { BindTarget = Picker.Beatmap }
}; };
break; break;

View File

@ -1,79 +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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
{
public class Comments : CompositeDrawable
{
private readonly APIChangelogBuild build;
public Comments(APIChangelogBuild build)
{
this.build = build;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding
{
Horizontal = 50,
Vertical = 20,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
LinkFlowContainer text;
InternalChildren = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 10,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreyVioletDarker
},
},
text = new LinkFlowContainer(t =>
{
t.Colour = colours.PinkLighter;
t.Font = OsuFont.Default.With(size: 14);
})
{
Padding = new MarginPadding(20),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
};
text.AddParagraph("Got feedback?", t =>
{
t.Colour = Color4.White;
t.Font = OsuFont.Default.With(italics: true, size: 20);
t.Padding = new MarginPadding { Bottom = 20 };
});
text.AddParagraph("We would love to hear what you think of this update! ");
text.AddIcon(FontAwesome.Regular.GrinHearts);
text.AddParagraph("Please visit the ");
text.AddLink("web version", $"{build.Url}#comments");
text.AddText(" of this changelog to leave any comments.");
}
}
}

View File

@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -16,6 +18,11 @@ namespace osu.Game.Overlays.Direct
private readonly bool noVideo; private readonly bool noVideo;
/// <summary>
/// Currently selected beatmap. Used to present the correct difficulty after completing a download.
/// </summary>
public readonly IBindable<BeatmapInfo> SelectedBeatmap = new Bindable<BeatmapInfo>();
private readonly ShakeContainer shakeContainer; private readonly ShakeContainer shakeContainer;
private readonly DownloadButton button; private readonly DownloadButton button;
@ -62,7 +69,11 @@ namespace osu.Game.Overlays.Direct
break; break;
case DownloadState.LocallyAvailable: case DownloadState.LocallyAvailable:
game?.PresentBeatmap(BeatmapSet.Value); Predicate<BeatmapInfo> findPredicate = null;
if (SelectedBeatmap.Value != null)
findPredicate = b => b.OnlineBeatmapID == SelectedBeatmap.Value.OnlineBeatmapID;
game?.PresentBeatmap(BeatmapSet.Value, findPredicate);
break; break;
default: default:

View File

@ -29,14 +29,8 @@ namespace osu.Game.Overlays.Music
{ {
public CollectionsMenu() public CollectionsMenu()
{ {
Masking = true;
CornerRadius = 5; CornerRadius = 5;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.3f),
Radius = 3,
Offset = new Vector2(0f, 1f),
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -375,7 +375,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
} }
} }
protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => AllJudged && base.ComputeIsMaskedAway(maskingBounds); public override bool UpdateSubTreeMasking(Drawable source, RectangleF maskingBounds) => AllJudged && base.UpdateSubTreeMasking(source, maskingBounds);
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {

View File

@ -63,6 +63,7 @@ namespace osu.Game.Screens.Edit
trackStartTime(obj); trackStartTime(obj);
} }
private readonly HashSet<HitObject> pendingUpdates = new HashSet<HitObject>();
private ScheduledDelegate scheduledUpdate; private ScheduledDelegate scheduledUpdate;
/// <summary> /// <summary>
@ -74,15 +75,27 @@ namespace osu.Game.Screens.Edit
private void updateHitObject([CanBeNull] HitObject hitObject, bool silent) private void updateHitObject([CanBeNull] HitObject hitObject, bool silent)
{ {
scheduledUpdate?.Cancel(); scheduledUpdate?.Cancel();
scheduledUpdate = Scheduler.AddDelayed(() =>
if (hitObject != null)
pendingUpdates.Add(hitObject);
scheduledUpdate = Schedule(() =>
{ {
beatmapProcessor?.PreProcess(); beatmapProcessor?.PreProcess();
hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
foreach (var obj in pendingUpdates)
obj.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
beatmapProcessor?.PostProcess(); beatmapProcessor?.PostProcess();
if (!silent) if (!silent)
HitObjectUpdated?.Invoke(hitObject); {
}, 0); foreach (var obj in pendingUpdates)
HitObjectUpdated?.Invoke(obj);
}
pendingUpdates.Clear();
});
} }
public BeatmapInfo BeatmapInfo public BeatmapInfo BeatmapInfo

View File

@ -15,8 +15,10 @@ namespace osu.Game.Screens.Edit
/// </summary> /// </summary>
public class EditorChangeHandler : IEditorChangeHandler public class EditorChangeHandler : IEditorChangeHandler
{ {
private readonly LegacyEditorBeatmapDiffer differ; private readonly LegacyEditorBeatmapPatcher patcher;
private readonly List<Stream> savedStates = new List<Stream>();
private readonly List<byte[]> savedStates = new List<byte[]>();
private int currentState = -1; private int currentState = -1;
private readonly EditorBeatmap editorBeatmap; private readonly EditorBeatmap editorBeatmap;
@ -35,7 +37,7 @@ namespace osu.Game.Screens.Edit
editorBeatmap.HitObjectRemoved += hitObjectRemoved; editorBeatmap.HitObjectRemoved += hitObjectRemoved;
editorBeatmap.HitObjectUpdated += hitObjectUpdated; editorBeatmap.HitObjectUpdated += hitObjectUpdated;
differ = new LegacyEditorBeatmapDiffer(editorBeatmap); patcher = new LegacyEditorBeatmapPatcher(editorBeatmap);
// Initial state. // Initial state.
SaveState(); SaveState();
@ -69,15 +71,17 @@ namespace osu.Game.Screens.Edit
if (isRestoring) if (isRestoring)
return; return;
var stream = new MemoryStream();
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
new LegacyBeatmapEncoder(editorBeatmap).Encode(sw);
if (currentState < savedStates.Count - 1) if (currentState < savedStates.Count - 1)
savedStates.RemoveRange(currentState + 1, savedStates.Count - currentState - 1); savedStates.RemoveRange(currentState + 1, savedStates.Count - currentState - 1);
savedStates.Add(stream); using (var stream = new MemoryStream())
{
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
new LegacyBeatmapEncoder(editorBeatmap).Encode(sw);
savedStates.Add(stream.ToArray());
}
currentState = savedStates.Count - 1; currentState = savedStates.Count - 1;
} }
@ -99,7 +103,7 @@ namespace osu.Game.Screens.Edit
isRestoring = true; isRestoring = true;
differ.Patch(savedStates[currentState], savedStates[newState]); patcher.Patch(savedStates[currentState], savedStates[newState]);
currentState = newState; currentState = newState;
isRestoring = false; isRestoring = false;

View File

@ -4,25 +4,29 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using DiffPlex; using DiffPlex;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO; using osu.Game.IO;
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
namespace osu.Game.Screens.Edit namespace osu.Game.Screens.Edit
{ {
public class LegacyEditorBeatmapDiffer /// <summary>
/// Patches an <see cref="EditorBeatmap"/> based on the difference between two legacy (.osu) states.
/// </summary>
public class LegacyEditorBeatmapPatcher
{ {
private readonly EditorBeatmap editorBeatmap; private readonly EditorBeatmap editorBeatmap;
public LegacyEditorBeatmapDiffer(EditorBeatmap editorBeatmap) public LegacyEditorBeatmapPatcher(EditorBeatmap editorBeatmap)
{ {
this.editorBeatmap = editorBeatmap; this.editorBeatmap = editorBeatmap;
} }
public void Patch(Stream currentState, Stream newState) public void Patch(byte[] currentState, byte[] newState)
{ {
// Diff the beatmaps // Diff the beatmaps
var result = new Differ().CreateLineDiffs(readString(currentState), readString(newState), true, false); var result = new Differ().CreateLineDiffs(readString(currentState), readString(newState), true, false);
@ -36,7 +40,7 @@ namespace osu.Game.Screens.Edit
foreach (var block in result.DiffBlocks) foreach (var block in result.DiffBlocks)
{ {
// Removed hitobject // Removed hitobjects
for (int i = 0; i < block.DeleteCountA; i++) for (int i = 0; i < block.DeleteCountA; i++)
{ {
int hoIndex = block.DeleteStartA + i - oldHitObjectsIndex - 1; int hoIndex = block.DeleteStartA + i - oldHitObjectsIndex - 1;
@ -47,7 +51,7 @@ namespace osu.Game.Screens.Edit
toRemove.Add(hoIndex); toRemove.Add(hoIndex);
} }
// Added hitobject // Added hitobjects
for (int i = 0; i < block.InsertCountB; i++) for (int i = 0; i < block.InsertCountB; i++)
{ {
int hoIndex = block.InsertStartB + i - newHitObjectsIndex - 1; int hoIndex = block.InsertStartB + i - newHitObjectsIndex - 1;
@ -74,18 +78,11 @@ namespace osu.Game.Screens.Edit
} }
} }
private string readString(Stream stream) private string readString(byte[] state) => Encoding.UTF8.GetString(state);
private IBeatmap readBeatmap(byte[] state)
{ {
stream.Seek(0, SeekOrigin.Begin); using (var stream = new MemoryStream(state))
using (var sr = new StreamReader(stream, System.Text.Encoding.UTF8, true, 1024, true))
return sr.ReadToEnd();
}
private IBeatmap readBeatmap(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
using (var reader = new LineBufferedReader(stream, true)) using (var reader = new LineBufferedReader(stream, true))
return new PassThroughWorkingBeatmap(Decoder.GetDecoder<Beatmap>(reader).Decode(reader)).GetPlayableBeatmap(editorBeatmap.BeatmapInfo.Ruleset); return new PassThroughWorkingBeatmap(Decoder.GetDecoder<Beatmap>(reader).Decode(reader)).GetPlayableBeatmap(editorBeatmap.BeatmapInfo.Ruleset);
} }

View File

@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.407.1" /> <PackageReference Include="ppy.osu.Framework" Version="2020.411.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" />
<PackageReference Include="Sentry" Version="2.1.1" /> <PackageReference Include="Sentry" Version="2.1.1" />
<PackageReference Include="SharpCompress" Version="0.25.0" /> <PackageReference Include="SharpCompress" Version="0.25.0" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.407.1" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2020.411.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" />
</ItemGroup> </ItemGroup>
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. --> <!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
@ -80,7 +80,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.407.1" /> <PackageReference Include="ppy.osu.Framework" Version="2020.411.0" />
<PackageReference Include="SharpCompress" Version="0.25.0" /> <PackageReference Include="SharpCompress" Version="0.25.0" />
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />