Skip to content

Commit

Permalink
Merge branch 'master' into new-interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo authored Oct 6, 2021
2 parents 4f59fc1 + 9491e5a commit 4bbff2e
Show file tree
Hide file tree
Showing 40 changed files with 729 additions and 131 deletions.
2 changes: 1 addition & 1 deletion osu.Android.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1004.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.929.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.1004.0" />
</ItemGroup>
<ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beat
Mods = mods,
// Todo: This int cast is temporary to achieve 1:1 results with osu!stable, and should be removed in the future
GreatHitWindow = (int)Math.Ceiling(getHitWindow300(mods) / clockRate),
ScoreMultiplier = getScoreMultiplier(beatmap, mods),
ScoreMultiplier = getScoreMultiplier(mods),
MaxCombo = beatmap.HitObjects.Sum(h => h is HoldNote ? 2 : 1),
Skills = skills
};
Expand All @@ -70,7 +70,7 @@ protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(I

protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) => new Skill[]
{
new Strain(mods, ((ManiaBeatmap)beatmap).TotalColumns)
new Strain(mods, ((ManiaBeatmap)Beatmap).TotalColumns)
};

protected override Mod[] DifficultyAdjustmentMods
Expand Down Expand Up @@ -138,7 +138,7 @@ static int applyModAdjustments(double value, Mod[] mods)
}
}

private double getScoreMultiplier(IBeatmap beatmap, Mod[] mods)
private double getScoreMultiplier(Mod[] mods)
{
double scoreMultiplier = 1;

Expand All @@ -154,7 +154,7 @@ private double getScoreMultiplier(IBeatmap beatmap, Mod[] mods)
}
}

var maniaBeatmap = (ManiaBeatmap)beatmap;
var maniaBeatmap = (ManiaBeatmap)Beatmap;
int diff = maniaBeatmap.TotalColumns - maniaBeatmap.OriginalTotalColumns;

if (diff > 0)
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ public static async Task<BeatmapSetInfo> LoadQuickOszIntoOsu(OsuGameBase osu)

var manager = osu.Dependencies.Get<BeatmapManager>();

var importedSet = await manager.Import(new ImportTask(temp));
var importedSet = await manager.Import(new ImportTask(temp)).ConfigureAwait(false);

ensureLoaded(osu);

Expand All @@ -924,7 +924,7 @@ public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string

var manager = osu.Dependencies.Get<BeatmapManager>();

var importedSet = await manager.Import(new ImportTask(temp));
var importedSet = await manager.Import(new ImportTask(temp)).ConfigureAwait(false);

ensureLoaded(osu);

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tests/Online/TestDummyAPIRequestHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void TestGenericRequestHandling()

AddAssert("response event fired", () => response != null);

AddAssert("request has response", () => request.Result == response);
AddAssert("request has response", () => request.Response == response);
}

[Test]
Expand Down
21 changes: 11 additions & 10 deletions osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapSkinFallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TestSceneBeatmapSkinFallbacks : OsuPlayerTestScene
public void TestEmptyLegacyBeatmapSkinFallsBack()
{
CreateSkinTest(SkinInfo.Default, () => new LegacyBeatmapSkin(new BeatmapInfo(), null, null));
AddUntilStep("wait for hud load", () => Player.ChildrenOfType<SkinnableTargetContainer>().All(c => c.ComponentsLoaded));
AddAssert("hud from default skin", () => AssertComponentsFromExpectedSource(SkinnableTarget.MainHUDComponents, skinManager.CurrentSkin.Value));
}

Expand Down Expand Up @@ -84,18 +85,18 @@ protected bool AssertComponentsFromExpectedSource(SkinnableTarget target, ISkin
Remove(expectedComponentsAdjustmentContainer);

return almostEqual(actualInfo, expectedInfo);

static bool almostEqual(SkinnableInfo info, SkinnableInfo other) =>
other != null
&& info.Type == other.Type
&& info.Anchor == other.Anchor
&& info.Origin == other.Origin
&& Precision.AlmostEquals(info.Position, other.Position)
&& Precision.AlmostEquals(info.Scale, other.Scale)
&& Precision.AlmostEquals(info.Rotation, other.Rotation)
&& info.Children.SequenceEqual(other.Children, new FuncEqualityComparer<SkinnableInfo>(almostEqual));
}

private static bool almostEqual(SkinnableInfo info, SkinnableInfo other) =>
other != null
&& info.Type == other.Type
&& info.Anchor == other.Anchor
&& info.Origin == other.Origin
&& Precision.AlmostEquals(info.Position, other.Position, 1)
&& Precision.AlmostEquals(info.Scale, other.Scale)
&& Precision.AlmostEquals(info.Rotation, other.Rotation)
&& info.Children.SequenceEqual(other.Children, new FuncEqualityComparer<SkinnableInfo>(almostEqual));

protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
=> new CustomSkinWorkingBeatmap(beatmap, storyboard, Clock, Audio, currentBeatmapSkin);

Expand Down
108 changes: 108 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestScenePerformancePointsCounter.cs
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++;
}
}
}
91 changes: 82 additions & 9 deletions osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs
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", () =>
{
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
Expand Down Expand Up @@ -68,6 +69,8 @@ public override void SetUpSteps()
LoadScreen(dependenciesScreen = new DependenciesScreen(client));
});

AddUntilStep("wait for dependencies screen", () => Stack.CurrentScreen is DependenciesScreen);
AddUntilStep("wait for dependencies to start load", () => dependenciesScreen.LoadState > LoadState.NotLoaded);
AddUntilStep("wait for dependencies to load", () => dependenciesScreen.IsLoaded);

AddStep("load multiplayer", () => LoadScreen(multiplayerScreen));
Expand Down
Loading

0 comments on commit 4bbff2e

Please sign in to comment.