1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-18 18:12:55 +08:00

Merge pull request #4434 from peppy/fix-autoplay-tests

Fix replay tests not working
This commit is contained in:
Dean Herbert 2019-03-08 12:21:33 +09:00 committed by GitHub
commit 196ebab10f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 51 additions and 32 deletions

View File

@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Catch.Mods
{ {
public class CatchModAutoplay : ModAutoplay<CatchHitObject> public class CatchModAutoplay : ModAutoplay<CatchHitObject>
{ {
protected override Score CreateReplayScore(Beatmap<CatchHitObject> beatmap) => new Score public override Score CreateReplayScore(IBeatmap beatmap) => new Score
{ {
ScoreInfo = new ScoreInfo { User = new User { Username = "osu!salad!" } }, ScoreInfo = new ScoreInfo { User = new User { Username = "osu!salad!" } },
Replay = new CatchAutoGenerator(beatmap).Generate(), Replay = new CatchAutoGenerator(beatmap).Generate(),

View File

@ -6,17 +6,20 @@ using System.Linq;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Catch.Beatmaps;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
namespace osu.Game.Rulesets.Catch.Replays namespace osu.Game.Rulesets.Catch.Replays
{ {
internal class CatchAutoGenerator : AutoGenerator<CatchHitObject> internal class CatchAutoGenerator : AutoGenerator
{ {
public const double RELEASE_DELAY = 20; public const double RELEASE_DELAY = 20;
public CatchAutoGenerator(Beatmap<CatchHitObject> beatmap) public new CatchBeatmap Beatmap => (CatchBeatmap)base.Beatmap;
public CatchAutoGenerator(IBeatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
Replay = new Replay(); Replay = new Replay();

View File

@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Mania.Mods
{ {
public class ManiaModAutoplay : ModAutoplay<ManiaHitObject> public class ManiaModAutoplay : ModAutoplay<ManiaHitObject>
{ {
protected override Score CreateReplayScore(Beatmap<ManiaHitObject> beatmap) => new Score public override Score CreateReplayScore(IBeatmap beatmap) => new Score
{ {
ScoreInfo = new ScoreInfo { User = new User { Username = "osu!topus!" } }, ScoreInfo = new ScoreInfo { User = new User { Username = "osu!topus!" } },
Replay = new ManiaAutoGenerator((ManiaBeatmap)beatmap).Generate(), Replay = new ManiaAutoGenerator((ManiaBeatmap)beatmap).Generate(),

View File

@ -5,13 +5,12 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
namespace osu.Game.Rulesets.Mania.Replays namespace osu.Game.Rulesets.Mania.Replays
{ {
internal class ManiaAutoGenerator : AutoGenerator<ManiaHitObject> internal class ManiaAutoGenerator : AutoGenerator
{ {
public const double RELEASE_DELAY = 20; public const double RELEASE_DELAY = 20;

View File

@ -16,7 +16,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{ {
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).Append(typeof(OsuModSpunOut)).ToArray(); public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).Append(typeof(OsuModSpunOut)).ToArray();
protected override Score CreateReplayScore(Beatmap<OsuHitObject> beatmap) => new Score public override Score CreateReplayScore(IBeatmap beatmap) => new Score
{ {
ScoreInfo = new ScoreInfo { User = new User { Username = "Autoplay" } }, ScoreInfo = new ScoreInfo { User = new User { Username = "Autoplay" } },
Replay = new OsuAutoGenerator(beatmap).Generate() Replay = new OsuAutoGenerator(beatmap).Generate()

View File

@ -10,12 +10,15 @@ using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Replays namespace osu.Game.Rulesets.Osu.Replays
{ {
public class OsuAutoGenerator : OsuAutoGeneratorBase public class OsuAutoGenerator : OsuAutoGeneratorBase
{ {
public new OsuBeatmap Beatmap => (OsuBeatmap)base.Beatmap;
#region Parameters #region Parameters
/// <summary> /// <summary>
@ -42,7 +45,7 @@ namespace osu.Game.Rulesets.Osu.Replays
#region Construction / Initialisation #region Construction / Initialisation
public OsuAutoGenerator(Beatmap<OsuHitObject> beatmap) public OsuAutoGenerator(IBeatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
// Already superhuman, but still somewhat realistic // Already superhuman, but still somewhat realistic

View File

@ -3,7 +3,6 @@
using osuTK; using osuTK;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Osu.Objects;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Replays; using osu.Game.Replays;
@ -12,7 +11,7 @@ using osu.Game.Rulesets.Replays;
namespace osu.Game.Rulesets.Osu.Replays namespace osu.Game.Rulesets.Osu.Replays
{ {
public abstract class OsuAutoGeneratorBase : AutoGenerator<OsuHitObject> public abstract class OsuAutoGeneratorBase : AutoGenerator
{ {
#region Constants #region Constants
@ -35,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.Replays
protected Replay Replay; protected Replay Replay;
protected List<ReplayFrame> Frames => Replay.Frames; protected List<ReplayFrame> Frames => Replay.Frames;
protected OsuAutoGeneratorBase(Beatmap<OsuHitObject> beatmap) protected OsuAutoGeneratorBase(IBeatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
Replay = new Replay(); Replay = new Replay();

View File

@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
{ {
public class TaikoModAutoplay : ModAutoplay<TaikoHitObject> public class TaikoModAutoplay : ModAutoplay<TaikoHitObject>
{ {
protected override Score CreateReplayScore(Beatmap<TaikoHitObject> beatmap) => new Score public override Score CreateReplayScore(IBeatmap beatmap) => new Score
{ {
ScoreInfo = new ScoreInfo { User = new User { Username = "mekkadosu!" } }, ScoreInfo = new ScoreInfo { User = new User { Username = "mekkadosu!" } },
Replay = new TaikoAutoGenerator(beatmap).Generate(), Replay = new TaikoAutoGenerator(beatmap).Generate(),

View File

@ -9,14 +9,17 @@ using osu.Game.Replays;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Taiko.Beatmaps;
namespace osu.Game.Rulesets.Taiko.Replays namespace osu.Game.Rulesets.Taiko.Replays
{ {
public class TaikoAutoGenerator : AutoGenerator<TaikoHitObject> public class TaikoAutoGenerator : AutoGenerator
{ {
public new TaikoBeatmap Beatmap => (TaikoBeatmap)base.Beatmap;
private const double swell_hit_speed = 50; private const double swell_hit_speed = 50;
public TaikoAutoGenerator(Beatmap<TaikoHitObject> beatmap) public TaikoAutoGenerator(IBeatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
Replay = new Replay(); Replay = new Replay();

View File

@ -1,10 +1,12 @@
// 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 System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -14,15 +16,27 @@ namespace osu.Game.Tests.Visual
{ {
protected override Player CreatePlayer(Ruleset ruleset) protected override Player CreatePlayer(Ruleset ruleset)
{ {
// We create a dummy RulesetContainer just to get the replay - we don't want to use mods here var beatmap = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo);
// to simulate setting a replay rather than having the replay already set for us
Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { ruleset.GetAutoplayMod() });
var dummyRulesetContainer = ruleset.CreateRulesetContainerWith(Beatmap.Value);
// Reset the mods return new ScoreAccessibleReplayPlayer(ruleset.GetAutoplayMod().CreateReplayScore(beatmap));
Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Where(m => !(m is ModAutoplay)); }
return new ReplayPlayer(dummyRulesetContainer.ReplayScore); protected override void AddCheckSteps(Func<Player> player)
{
base.AddCheckSteps(player);
AddUntilStep(() => ((ScoreAccessibleReplayPlayer)player()).ScoreProcessor.TotalScore.Value > 0, "score above zero");
AddUntilStep(() => ((ScoreAccessibleReplayPlayer)player()).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0), "key counter counted keys");
}
private class ScoreAccessibleReplayPlayer : ReplayPlayer
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
public new HUDOverlay HUDOverlay => base.HUDOverlay;
public ScoreAccessibleReplayPlayer(Score score)
: base(score)
{
}
} }
} }
} }

View File

@ -14,10 +14,6 @@ namespace osu.Game.Rulesets.Mods
public abstract class ModAutoplay<T> : ModAutoplay, IApplicableToRulesetContainer<T> public abstract class ModAutoplay<T> : ModAutoplay, IApplicableToRulesetContainer<T>
where T : HitObject where T : HitObject
{ {
protected virtual Score CreateReplayScore(Beatmap<T> beatmap) => new Score { Replay = new Replay() };
public override bool HasImplementation => GetType().GenericTypeArguments.Length == 0;
public virtual void ApplyToRulesetContainer(RulesetContainer<T> rulesetContainer) => rulesetContainer.SetReplayScore(CreateReplayScore(rulesetContainer.Beatmap)); public virtual void ApplyToRulesetContainer(RulesetContainer<T> rulesetContainer) => rulesetContainer.SetReplayScore(CreateReplayScore(rulesetContainer.Beatmap));
} }
@ -31,5 +27,9 @@ namespace osu.Game.Rulesets.Mods
public override double ScoreMultiplier => 1; public override double ScoreMultiplier => 1;
public bool AllowFail => false; public bool AllowFail => false;
public override Type[] IncompatibleMods => new[] { typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail) }; public override Type[] IncompatibleMods => new[] { typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail) };
public override bool HasImplementation => GetType().GenericTypeArguments.Length == 0;
public virtual Score CreateReplayScore(IBeatmap beatmap) => new Score { Replay = new Replay() };
} }
} }

View File

@ -1,14 +1,12 @@
// 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 osu.Game.Rulesets.Objects;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Replays; using osu.Game.Replays;
namespace osu.Game.Rulesets.Replays namespace osu.Game.Rulesets.Replays
{ {
public abstract class AutoGenerator<T> : IAutoGenerator public abstract class AutoGenerator : IAutoGenerator
where T : HitObject
{ {
/// <summary> /// <summary>
/// Creates the auto replay and returns it. /// Creates the auto replay and returns it.
@ -21,11 +19,11 @@ namespace osu.Game.Rulesets.Replays
/// <summary> /// <summary>
/// The beatmap we're making. /// The beatmap we're making.
/// </summary> /// </summary>
protected Beatmap<T> Beatmap; protected IBeatmap Beatmap;
#endregion #endregion
protected AutoGenerator(Beatmap<T> beatmap) protected AutoGenerator(IBeatmap beatmap)
{ {
Beatmap = beatmap; Beatmap = beatmap;
} }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Rulesets
/// <returns>An enumerable of constructed <see cref="Mod"/>s</returns> /// <returns>An enumerable of constructed <see cref="Mod"/>s</returns>
public virtual IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods) => new Mod[] { }; public virtual IEnumerable<Mod> ConvertLegacyMods(LegacyMods mods) => new Mod[] { };
public Mod GetAutoplayMod() => GetAllMods().First(mod => mod is ModAutoplay); public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().First();
protected Ruleset(RulesetInfo rulesetInfo = null) protected Ruleset(RulesetInfo rulesetInfo = null)
{ {