Merge pull request #18835 from peppy/beatmap-update-flow

Split out beatmap update tasks to `BeatmapUpdater` and invoke from editor save flow
This commit is contained in:
Dan Balasescu
2022-07-01 20:28:04 +09:00
committed by GitHub
13 changed files with 277 additions and 126 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
@ -130,6 +131,54 @@ namespace osu.Game.Tests.Visual.Editing
!ReferenceEquals(EditorBeatmap.HitObjects[0].DifficultyControlPoint, DifficultyControlPoint.DEFAULT));
}
[Test]
public void TestLengthAndStarRatingUpdated()
{
WorkingBeatmap working = null;
double lastStarRating = 0;
double lastLength = 0;
AddStep("Add timing point", () => EditorBeatmap.ControlPointInfo.Add(500, new TimingControlPoint()));
AddStep("Change to placement mode", () => InputManager.Key(Key.Number2));
AddStep("Move to playfield", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.Centre));
AddStep("Place single hitcircle", () => InputManager.Click(MouseButton.Left));
AddAssert("One hitobject placed", () => EditorBeatmap.HitObjects.Count == 1);
SaveEditor();
AddStep("Get working beatmap", () => working = Game.BeatmapManager.GetWorkingBeatmap(EditorBeatmap.BeatmapInfo, true));
AddAssert("Beatmap length is zero", () => working.BeatmapInfo.Length == 0);
checkDifficultyIncreased();
AddStep("Move forward", () => InputManager.Key(Key.Right));
AddStep("Place another hitcircle", () => InputManager.Click(MouseButton.Left));
AddAssert("Two hitobjects placed", () => EditorBeatmap.HitObjects.Count == 2);
SaveEditor();
AddStep("Get working beatmap", () => working = Game.BeatmapManager.GetWorkingBeatmap(EditorBeatmap.BeatmapInfo, true));
checkDifficultyIncreased();
checkLengthIncreased();
void checkLengthIncreased()
{
AddStep("Beatmap length increased", () =>
{
Assert.That(working.BeatmapInfo.Length, Is.GreaterThan(lastLength));
lastLength = working.BeatmapInfo.Length;
});
}
void checkDifficultyIncreased()
{
AddStep("Beatmap difficulty increased", () =>
{
Assert.That(working.BeatmapInfo.StarRating, Is.GreaterThan(lastStarRating));
lastStarRating = working.BeatmapInfo.StarRating;
});
}
}
[Test]
public void TestExitWithoutSaveFromExistingBeatmap()
{

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
@ -166,15 +167,22 @@ namespace osu.Game.Tests.Visual.SongSelect
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(rulesets.Length, rulesets);
for (int i = 0; i < rulesets.Length; i++)
var importedBeatmapSet = Game.BeatmapManager.Import(beatmapSet);
Debug.Assert(importedBeatmapSet != null);
importedBeatmapSet.PerformWrite(s =>
{
var beatmap = beatmapSet.Beatmaps[i];
for (int i = 0; i < rulesets.Length; i++)
{
var beatmap = s.Beatmaps[i];
beatmap.StarRating = i + 1;
beatmap.DifficultyName = $"SR{i + 1}";
}
beatmap.StarRating = i + 1;
beatmap.DifficultyName = $"SR{i + 1}";
}
});
return Game.BeatmapManager.Import(beatmapSet)?.Value;
return importedBeatmapSet.Value;
}
private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null);