-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into new-interfaces
- Loading branch information
Showing
40 changed files
with
729 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
osu.Game.Tests/Visual/Gameplay/TestScenePerformancePointsCounter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Diagnostics; | ||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Testing; | ||
using osu.Game.Rulesets; | ||
using osu.Game.Rulesets.Judgements; | ||
using osu.Game.Rulesets.Objects; | ||
using osu.Game.Rulesets.Osu; | ||
using osu.Game.Rulesets.Osu.Judgements; | ||
using osu.Game.Rulesets.Scoring; | ||
using osu.Game.Screens.Play; | ||
using osu.Game.Screens.Play.HUD; | ||
using osuTK; | ||
|
||
namespace osu.Game.Tests.Visual.Gameplay | ||
{ | ||
public class TestScenePerformancePointsCounter : OsuTestScene | ||
{ | ||
[Cached] | ||
private GameplayState gameplayState; | ||
|
||
[Cached] | ||
private ScoreProcessor scoreProcessor; | ||
|
||
private int iteration; | ||
private PerformancePointsCounter counter; | ||
|
||
public TestScenePerformancePointsCounter() | ||
{ | ||
var ruleset = CreateRuleset(); | ||
|
||
Debug.Assert(ruleset != null); | ||
|
||
var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo) | ||
.GetPlayableBeatmap(ruleset.RulesetInfo); | ||
|
||
gameplayState = new GameplayState(beatmap, ruleset); | ||
scoreProcessor = new ScoreProcessor(); | ||
} | ||
|
||
protected override Ruleset CreateRuleset() => new OsuRuleset(); | ||
|
||
[SetUpSteps] | ||
public void SetUpSteps() | ||
{ | ||
AddStep("Create counter", () => | ||
{ | ||
iteration = 0; | ||
|
||
Child = counter = new PerformancePointsCounter | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Scale = new Vector2(5), | ||
}; | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestBasicCounting() | ||
{ | ||
int previousValue = 0; | ||
|
||
AddAssert("counter displaying zero", () => counter.Current.Value == 0); | ||
|
||
AddRepeatStep("Add judgement", applyOneJudgement, 10); | ||
|
||
AddUntilStep("counter non-zero", () => counter.Current.Value > 0); | ||
AddUntilStep("counter opaque", () => counter.Child.Alpha == 1); | ||
|
||
AddStep("Revert judgement", () => | ||
{ | ||
previousValue = counter.Current.Value; | ||
|
||
scoreProcessor.RevertResult(new JudgementResult(new HitObject(), new OsuJudgement())); | ||
}); | ||
|
||
AddUntilStep("counter decreased", () => counter.Current.Value < previousValue); | ||
|
||
AddStep("Add judgement", applyOneJudgement); | ||
|
||
AddUntilStep("counter non-zero", () => counter.Current.Value > 0); | ||
} | ||
|
||
private void applyOneJudgement() | ||
{ | ||
var scoreInfo = gameplayState.Score.ScoreInfo; | ||
|
||
scoreInfo.MaxCombo = iteration * 1000; | ||
scoreInfo.Accuracy = 1; | ||
scoreInfo.Statistics[HitResult.Great] = iteration * 1000; | ||
|
||
scoreProcessor.ApplyResult(new OsuJudgementResult(new HitObject | ||
{ | ||
StartTime = iteration * 10000, | ||
}, new OsuJudgement()) | ||
{ | ||
Type = HitResult.Perfect, | ||
}); | ||
|
||
iteration++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,119 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Online; | ||
using osu.Game.Online.API.Requests.Responses; | ||
using osu.Game.Scoring; | ||
using osu.Game.Users; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Testing; | ||
using osu.Game.Graphics.UserInterface; | ||
using osu.Game.Rulesets; | ||
using osu.Game.Screens.Ranking; | ||
using osuTK.Input; | ||
|
||
namespace osu.Game.Tests.Visual.Gameplay | ||
{ | ||
[TestFixture] | ||
public class TestSceneReplayDownloadButton : OsuTestScene | ||
public class TestSceneReplayDownloadButton : OsuManualInputManagerTestScene | ||
{ | ||
[Resolved] | ||
private RulesetStore rulesets { get; set; } | ||
|
||
private TestReplayDownloadButton downloadButton; | ||
|
||
public TestSceneReplayDownloadButton() | ||
[Test] | ||
public void TestDisplayStates() | ||
{ | ||
createButton(true); | ||
AddStep(@"create button with replay", () => | ||
{ | ||
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(true)) | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
}; | ||
}); | ||
|
||
AddUntilStep("wait for load", () => downloadButton.IsLoaded); | ||
|
||
AddStep(@"downloading state", () => downloadButton.SetDownloadState(DownloadState.Downloading)); | ||
AddStep(@"locally available state", () => downloadButton.SetDownloadState(DownloadState.LocallyAvailable)); | ||
AddStep(@"not downloaded state", () => downloadButton.SetDownloadState(DownloadState.NotDownloaded)); | ||
createButton(false); | ||
createButtonNoScore(); | ||
} | ||
|
||
private void createButton(bool withReplay) | ||
[Test] | ||
public void TestButtonWithReplayStartsDownload() | ||
{ | ||
AddStep(withReplay ? @"create button with replay" : "create button without replay", () => | ||
bool downloadStarted = false; | ||
bool downloadFinished = false; | ||
|
||
AddStep(@"create button with replay", () => | ||
{ | ||
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(withReplay)) | ||
downloadStarted = false; | ||
downloadFinished = false; | ||
|
||
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(true)) | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
}; | ||
|
||
downloadButton.State.BindValueChanged(state => | ||
{ | ||
switch (state.NewValue) | ||
{ | ||
case DownloadState.Downloading: | ||
downloadStarted = true; | ||
break; | ||
} | ||
|
||
switch (state.OldValue) | ||
{ | ||
case DownloadState.Downloading: | ||
downloadFinished = true; | ||
break; | ||
} | ||
}); | ||
}); | ||
|
||
AddUntilStep("wait for load", () => downloadButton.IsLoaded); | ||
|
||
AddAssert("state is available", () => downloadButton.State.Value == DownloadState.NotDownloaded); | ||
|
||
AddStep("click button", () => | ||
{ | ||
InputManager.MoveMouseTo(downloadButton); | ||
InputManager.Click(MouseButton.Left); | ||
}); | ||
|
||
AddAssert("state entered downloading", () => downloadStarted); | ||
AddUntilStep("state left downloading", () => downloadFinished); | ||
} | ||
|
||
[Test] | ||
public void TestButtonWithoutReplay() | ||
{ | ||
AddStep("create button without replay", () => | ||
{ | ||
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false)) | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
}; | ||
}); | ||
|
||
AddUntilStep("wait for load", () => downloadButton.IsLoaded); | ||
|
||
AddAssert("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded); | ||
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value); | ||
} | ||
|
||
private void createButtonNoScore() | ||
[Test] | ||
public void CreateButtonWithNoScore() | ||
{ | ||
AddStep("create button with null score", () => | ||
{ | ||
|
@@ -57,6 +125,9 @@ private void createButtonNoScore() | |
}); | ||
|
||
AddUntilStep("wait for load", () => downloadButton.IsLoaded); | ||
|
||
AddAssert("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded); | ||
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value); | ||
} | ||
|
||
private ScoreInfo getScoreInfo(bool replayAvailable) | ||
|
@@ -78,6 +149,8 @@ private class TestReplayDownloadButton : ReplayDownloadButton | |
{ | ||
public void SetDownloadState(DownloadState state) => State.Value = state; | ||
|
||
public new Bindable<DownloadState> State => base.State; | ||
|
||
public TestReplayDownloadButton(ScoreInfo score) | ||
: base(score) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.