Skip to content

Commit

Permalink
Merge pull request #129 from andy840119/update-nuget
Browse files Browse the repository at this point in the history
Update nuget
  • Loading branch information
andy840119 authored Jul 2, 2020
2 parents c53acc9 + fdbcf80 commit 46424c0
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 11 deletions.
44 changes: 44 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Users;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
public class TestKaraokeScoreInfo : ScoreInfo
{
public TestKaraokeScoreInfo()
{
var ruleset = new KaraokeRuleset().RulesetInfo;

User = new User
{
Id = 1030492,
Username = "andy840119",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
};

Beatmap = new TestKaraokeBeatmap(ruleset).BeatmapInfo;
Ruleset = ruleset;
RulesetID = ruleset.ID ?? 0;
Mods = new Mod[] { new KaraokeModFlashlight(), new KaraokeModSnow() };

TotalScore = 2845370;
Accuracy = 0.95;
MaxCombo = 999;
Rank = ScoreRank.S;
Date = DateTimeOffset.Now;

Statistics[HitResult.Miss] = 1;
Statistics[HitResult.Meh] = 50;
Statistics[HitResult.Good] = 100;
Statistics[HitResult.Great] = 300;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
{
[Test]
public void TestManyDistributedEvents()
{
createTest(CreateDistributedHitEvents());
}

[Test]
public void TestZeroTimeOffset()
{
createTest(Enumerable.Range(0, 100).Select(_ => new HitEvent(0, HitResult.Perfect, new Note(), new Note(), null)).ToList());
}

[Test]
public void TestNoEvents()
{
createTest(new List<HitEvent>());
}

private void createTest(List<HitEvent> events) => AddStep("create test", () =>
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
new HitEventTimingDistributionGraph(events)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(600, 130)
}
};
});

public static List<HitEvent> CreateDistributedHitEvents()
{
var hitEvents = new List<HitEvent>();

for (int i = 0; i < 50; i++)
{
int count = (int)(Math.Pow(25 - Math.Abs(i - 25), 2));

for (int j = 0; j < count; j++)
hitEvents.Add(new HitEvent(i - 25, HitResult.Perfect, new Note(), new Note(), null));
}

return hitEvents;
}
}
}
107 changes: 107 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
using osu.Game.Scoring;
using osu.Game.Screens;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests.Visual;
using osuTK.Input;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
[TestFixture]
public class TestSceneResultsScreen : OsuManualInputManagerTestScene
{
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestKaraokeBeatmap(ruleset);

private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestKaraokeScoreInfo
{
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents()
});

[Test]
public void TestShowStatisticsAndClickOtherPanel()
{
TestResultsScreen screen = null;

AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen()));
AddUntilStep("wait for loaded", () => screen.IsLoaded);

ScorePanel expandedPanel = null;
ScorePanel contractedPanel = null;

AddStep("click expanded panel then contracted panel", () =>
{
expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
InputManager.MoveMouseTo(expandedPanel);
InputManager.Click(MouseButton.Left);

contractedPanel = this.ChildrenOfType<ScorePanel>().First(p => p.State == PanelState.Contracted && p.ScreenSpaceDrawQuad.TopLeft.X > screen.ScreenSpaceDrawQuad.TopLeft.X);
InputManager.MoveMouseTo(contractedPanel);
InputManager.Click(MouseButton.Left);
});

AddAssert("statistics shown", () => this.ChildrenOfType<StatisticsPanel>().Single().State.Value == Visibility.Visible);

AddAssert("contracted panel still contracted", () => contractedPanel.State == PanelState.Contracted);
AddAssert("expanded panel still expanded", () => expandedPanel.State == PanelState.Expanded);
}

private class TestResultsContainer : Container
{
[Cached(typeof(Player))]
private readonly Player player = new TestPlayer();

public TestResultsContainer(IScreen screen)
{
RelativeSizeAxes = Axes.Both;
OsuScreenStack stack;

InternalChild = stack = new OsuScreenStack
{
RelativeSizeAxes = Axes.Both,
};

stack.Push(screen);
}
}

private class TestResultsScreen : ResultsScreen
{
public TestResultsScreen(ScoreInfo score)
: base(score)
{
}

protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
var scores = new List<ScoreInfo>();

for (int i = 0; i < 20; i++)
{
var score = new TestKaraokeScoreInfo();
score.TotalScore += 10 - i;
scores.Add(score);
}

scoresCallback?.Invoke(scores);

return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
public class TestSceneStatisticsPanel : OsuTestScene
{
[Test]
public void TestScoreWithStatistics()
{
var score = new TestKaraokeScoreInfo
{
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents()
};

loadPanel(score);
}

[Test]
public void TestScoreWithoutStatistics()
{
loadPanel(new TestKaraokeScoreInfo());
}

[Test]
public void TestNullScore()
{
loadPanel(null);
}

private void loadPanel(ScoreInfo score) => AddStep("load panel", () =>
{
Child = new StatisticsPanel
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible },
Score = { Value = score }
};
});
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Tests.Skinning
{
public abstract class KaraokeSkinnableTestScene : SkinnableTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(KaraokeRuleset),
typeof(KaraokeLegacySkinTransformer),
};

protected override Ruleset CreateRulesetForSkinProvider() => new KaraokeRuleset();

protected override IBeatmap CreateBeatmapForSkinProvider() => new KaraokeBeatmap();
Expand Down
19 changes: 19 additions & 0 deletions osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings;
Expand All @@ -18,6 +19,7 @@
using osu.Game.Rulesets.Karaoke.Difficulty;
using osu.Game.Rulesets.Karaoke.Edit;
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Replays;
using osu.Game.Rulesets.Karaoke.Resources.Fonts;
using osu.Game.Rulesets.Karaoke.Scoring;
Expand All @@ -27,6 +29,8 @@
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Skinning;

namespace osu.Game.Rulesets.Karaoke
Expand Down Expand Up @@ -140,6 +144,21 @@ public override IEnumerable<Mod> GetModsFor(ModType type)

public override RulesetSettingsSubsection CreateSettings() => new KaraokeSettingsSubsection(this);

public override StatisticRow[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => new[]
{
new StatisticRow
{
Columns = new[]
{
new StatisticItem("Timing Distribution", new HitEventTimingDistributionGraph(score.HitEvents.Where(e => e.HitObject is Note).ToList())
{
RelativeSizeAxes = Axes.X,
Height = 250
}),
}
}
};

public KaraokeRuleset()
{
// It's a tricky to let osu! to read karaoke testing beatmap
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<EmbeddedResource Include="Resources\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Octokit" Version="0.47.0" />
<PackageReference Include="Octokit" Version="0.48.0" />
<PackageReference Include="osu.Framework.Microphone" Version="1.0.7" />
<PackageReference Include="ppy.osu.Game" Version="2020.623.1" />
<PackageReference Include="ppy.osu.Game" Version="2020.629.0" />
<PackageReference Include="LyricMaker" Version="1.1.1" />
<PackageReference Include="NicoKaraParser" Version="1.1.0" />
<PackageReference Include="osu.KaraokeFramework" Version="1.2.1" />
Expand Down

0 comments on commit 46424c0

Please sign in to comment.