1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

allow test scenes to specify replays manually

This commit is contained in:
Nitrous 2022-01-29 22:31:24 +08:00
parent 24f9ef4005
commit b4e516c535
No known key found for this signature in database
GPG Key ID: 85EC4A6AE8F69D64

View File

@ -5,8 +5,12 @@ using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Game.Beatmaps;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Replays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Replays;
using osu.Game.Scoring;
namespace osu.Game.Tests.Visual
{
@ -50,18 +54,37 @@ namespace osu.Game.Tests.Visual
return CreateModPlayer(ruleset);
}
protected virtual TestPlayer CreateModPlayer(Ruleset ruleset) => new ModTestPlayer(AllowFail);
protected virtual TestPlayer CreateModPlayer(Ruleset ruleset) => new ModTestPlayer(currentTestData, AllowFail);
protected class ModTestPlayer : TestPlayer
{
private readonly bool allowFail;
private ModTestData currentTestData;
protected override bool CheckModsAllowFailure() => allowFail;
public ModTestPlayer(bool allowFail)
public ModTestPlayer(ModTestData data, bool allowFail)
: base(false, false)
{
this.allowFail = allowFail;
currentTestData = data;
}
protected override void PrepareReplay()
{
if (currentTestData.Autoplay && currentTestData.Frames?.Count > 0)
throw new InvalidOperationException(@$"{nameof(ModTestData.Autoplay)} must be false when {nameof(ModTestData.Frames)} is specified.");
if (currentTestData.Frames != null)
{
DrawableRuleset?.SetReplayScore(new Score
{
Replay = new Replay { Frames = currentTestData.Frames },
ScoreInfo = new ScoreInfo { User = new APIUser { Username = @"Test" } },
});
}
base.PrepareReplay();
}
}
@ -72,6 +95,12 @@ namespace osu.Game.Tests.Visual
/// </summary>
public bool Autoplay = true;
/// <summary>
/// The frames to use for replay. <see cref="Autoplay"/> must be set to false.
/// </summary>
[CanBeNull]
public List<ReplayFrame> Frames;
/// <summary>
/// The beatmap for this test case.
/// </summary>