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

Merge branch 'timed-difficulty-attributes' into update-beatmap-scores-design

# Conflicts:
#	osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs
This commit is contained in:
smoogipoo 2019-03-20 17:12:34 +09:00
commit ce57bdb8db
162 changed files with 2373 additions and 1278 deletions

View File

@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
protected override string ResourceAssembly => "osu.Game.Rulesets.Catch"; protected override string ResourceAssembly => "osu.Game.Rulesets.Catch";
[TestCase(4.2038001515546597d, "diffcalc-test")] [TestCase(4.2058561036909863d, "diffcalc-test")]
public void Test(double expected, string name) public void Test(double expected, string name)
=> base.Test(expected, name); => base.Test(expected, name);

View File

@ -13,7 +13,7 @@ using osuTK;
namespace osu.Game.Rulesets.Catch.Tests namespace osu.Game.Rulesets.Catch.Tests
{ {
public class TestCaseAutoJuiceStream : TestCasePlayer public class TestCaseAutoJuiceStream : PlayerTestCase
{ {
public TestCaseAutoJuiceStream() public TestCaseAutoJuiceStream()
: base(new CatchRuleset()) : base(new CatchRuleset())

View File

@ -8,11 +8,12 @@ using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawable; using osu.Game.Rulesets.Catch.Objects.Drawable;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Catch.Tests namespace osu.Game.Rulesets.Catch.Tests
{ {
[TestFixture] [TestFixture]
public class TestCaseBananaShower : Game.Tests.Visual.TestCasePlayer public class TestCaseBananaShower : PlayerTestCase
{ {
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
{ {
@ -20,7 +21,7 @@ namespace osu.Game.Rulesets.Catch.Tests
typeof(DrawableBananaShower), typeof(DrawableBananaShower),
typeof(CatchRuleset), typeof(CatchRuleset),
typeof(CatchRulesetContainer), typeof(DrawableCatchRuleset),
}; };
public TestCaseBananaShower() public TestCaseBananaShower()

View File

@ -2,11 +2,12 @@
// 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 NUnit.Framework; using NUnit.Framework;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Catch.Tests namespace osu.Game.Rulesets.Catch.Tests
{ {
[TestFixture] [TestFixture]
public class TestCaseCatchPlayer : Game.Tests.Visual.TestCasePlayer public class TestCaseCatchPlayer : PlayerTestCase
{ {
public TestCaseCatchPlayer() public TestCaseCatchPlayer()
: base(new CatchRuleset()) : base(new CatchRuleset())

View File

@ -4,11 +4,12 @@
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Catch.Tests namespace osu.Game.Rulesets.Catch.Tests
{ {
[TestFixture] [TestFixture]
public class TestCaseCatchStacker : Game.Tests.Visual.TestCasePlayer public class TestCaseCatchStacker : PlayerTestCase
{ {
public TestCaseCatchStacker() public TestCaseCatchStacker()
: base(new CatchRuleset()) : base(new CatchRuleset())

View File

@ -1,22 +1,28 @@
// 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 NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Screens.Play; using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Catch.Tests namespace osu.Game.Rulesets.Catch.Tests
{ {
[TestFixture] [TestFixture]
public class TestCaseHyperDash : Game.Tests.Visual.TestCasePlayer public class TestCaseHyperDash : PlayerTestCase
{ {
public TestCaseHyperDash() public TestCaseHyperDash()
: base(new CatchRuleset()) : base(new CatchRuleset())
{ {
} }
[BackgroundDependencyLoader]
private void load()
{
AddAssert("First note is hyperdash", () => Beatmap.Value.Beatmap.HitObjects[0] is Fruit f && f.HyperDash);
}
protected override IBeatmap CreateBeatmap(Ruleset ruleset) protected override IBeatmap CreateBeatmap(Ruleset ruleset)
{ {
var beatmap = new Beatmap var beatmap = new Beatmap
@ -28,7 +34,7 @@ namespace osu.Game.Rulesets.Catch.Tests
} }
}; };
// Should produce a hperdash // Should produce a hyper-dash
beatmap.HitObjects.Add(new Fruit { StartTime = 816, X = 308 / 512f, NewCombo = true }); beatmap.HitObjects.Add(new Fruit { StartTime = 816, X = 308 / 512f, NewCombo = true });
beatmap.HitObjects.Add(new Fruit { StartTime = 1008, X = 56 / 512f, }); beatmap.HitObjects.Add(new Fruit { StartTime = 1008, X = 56 / 512f, });
@ -38,11 +44,5 @@ namespace osu.Game.Rulesets.Catch.Tests
return beatmap; return beatmap;
} }
protected override void AddCheckSteps(Func<Player> player)
{
base.AddCheckSteps(player);
AddAssert("First note is hyperdash", () => Beatmap.Value.Beatmap.HitObjects[0] is Fruit f && f.HyperDash);
}
} }
} }

View File

@ -10,6 +10,7 @@ using osu.Game.Rulesets.UI;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Replays; using osu.Game.Rulesets.Catch.Replays;
using osu.Game.Rulesets.Replays.Types; using osu.Game.Rulesets.Replays.Types;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
@ -21,7 +22,7 @@ namespace osu.Game.Rulesets.Catch
{ {
public class CatchRuleset : Ruleset public class CatchRuleset : Ruleset
{ {
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap) => new CatchRulesetContainer(this, beatmap); public override DrawableRuleset CreateDrawableRulesetWith(WorkingBeatmap beatmap) => new DrawableCatchRuleset(this, beatmap);
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new CatchBeatmapConverter(beatmap); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new CatchBeatmapConverter(beatmap);
public override IBeatmapProcessor CreateBeatmapProcessor(IBeatmap beatmap) => new CatchBeatmapProcessor(beatmap); public override IBeatmapProcessor CreateBeatmapProcessor(IBeatmap beatmap) => new CatchBeatmapProcessor(beatmap);
@ -99,6 +100,11 @@ namespace osu.Game.Rulesets.Catch
new MultiMod(new CatchModAutoplay(), new ModCinema()), new MultiMod(new CatchModAutoplay(), new ModCinema()),
new CatchModRelax(), new CatchModRelax(),
}; };
case ModType.Fun:
return new Mod[]
{
new MultiMod(new ModWindUp<CatchHitObject>(), new ModWindDown<CatchHitObject>())
};
default: default:
return new Mod[] { }; return new Mod[] { };
} }

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Difficulty.Preprocessing; using osu.Game.Rulesets.Catch.Difficulty.Preprocessing;
using osu.Game.Rulesets.Catch.Difficulty.Skills; using osu.Game.Rulesets.Catch.Difficulty.Skills;
using osu.Game.Rulesets.Catch.Mods;
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.Difficulty; using osu.Game.Rulesets.Difficulty;
@ -22,16 +23,9 @@ namespace osu.Game.Rulesets.Catch.Difficulty
protected override int SectionLength => 750; protected override int SectionLength => 750;
private readonly float halfCatchWidth;
public CatchDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap) public CatchDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
var catcher = new CatcherArea.Catcher(beatmap.BeatmapInfo.BaseDifficulty);
halfCatchWidth = catcher.CatchWidth * 0.5f;
// We're only using 80% of the catcher's width to simulate imperfect gameplay.
halfCatchWidth *= 0.8f;
} }
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
@ -53,6 +47,14 @@ namespace osu.Game.Rulesets.Catch.Difficulty
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate) protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate)
{ {
float halfCatchWidth;
using (var catcher = new CatcherArea.Catcher(beatmap.BeatmapInfo.BaseDifficulty))
{
halfCatchWidth = catcher.CatchWidth * 0.5f;
halfCatchWidth *= 0.8f; // We're only using 80% of the catcher's width to simulate imperfect gameplay.
}
CatchHitObject lastObject = null; CatchHitObject lastObject = null;
foreach (var hitObject in beatmap.HitObjects.OfType<CatchHitObject>()) foreach (var hitObject in beatmap.HitObjects.OfType<CatchHitObject>())
@ -88,5 +90,13 @@ namespace osu.Game.Rulesets.Catch.Difficulty
{ {
new Movement(), new Movement(),
}; };
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
{
new CatchModDoubleTime(),
new CatchModHalfTime(),
new CatchModHardRock(),
new CatchModEasy(),
};
} }
} }

View File

@ -21,10 +21,10 @@ namespace osu.Game.Rulesets.Catch.Mods
private CatchPlayfield playfield; private CatchPlayfield playfield;
public override void ApplyToRulesetContainer(RulesetContainer<CatchHitObject> rulesetContainer) public override void ApplyToDrawableRuleset(DrawableRuleset<CatchHitObject> drawableRuleset)
{ {
playfield = (CatchPlayfield)rulesetContainer.Playfield; playfield = (CatchPlayfield)drawableRuleset.Playfield;
base.ApplyToRulesetContainer(rulesetContainer); base.ApplyToDrawableRuleset(drawableRuleset);
} }
private class CatchFlashlight : Flashlight private class CatchFlashlight : Flashlight

View File

@ -15,41 +15,73 @@ namespace osu.Game.Rulesets.Catch.Mods
public override double ScoreMultiplier => 1.12; public override double ScoreMultiplier => 1.12;
public override bool Ranked => true; public override bool Ranked => true;
private float lastStartX; private float? lastPosition;
private int lastStartTime; private double lastStartTime;
public void ApplyToHitObject(HitObject hitObject) public void ApplyToHitObject(HitObject hitObject)
{ {
if (hitObject is JuiceStream stream)
{
lastPosition = stream.EndX;
lastStartTime = stream.EndTime;
return;
}
if (!(hitObject is Fruit))
return;
var catchObject = (CatchHitObject)hitObject; var catchObject = (CatchHitObject)hitObject;
float position = catchObject.X; float position = catchObject.X;
int startTime = (int)hitObject.StartTime; double startTime = hitObject.StartTime;
if (lastStartX == 0) if (lastPosition == null)
{ {
lastStartX = position; lastPosition = position;
lastStartTime = startTime; lastStartTime = startTime;
return; return;
} }
float diff = lastStartX - position; float positionDiff = position - lastPosition.Value;
int timeDiff = startTime - lastStartTime; double timeDiff = startTime - lastStartTime;
if (timeDiff > 1000) if (timeDiff > 1000)
{ {
lastStartX = position; lastPosition = position;
lastStartTime = startTime; lastStartTime = startTime;
return; return;
} }
if (diff == 0) if (positionDiff == 0)
{
applyRandomOffset(ref position, timeDiff / 4d);
catchObject.X = position;
return;
}
if (Math.Abs(positionDiff * CatchPlayfield.BASE_WIDTH) < timeDiff / 3d)
applyOffset(ref position, positionDiff);
catchObject.X = position;
lastPosition = position;
lastStartTime = startTime;
}
/// <summary>
/// Applies a random offset in a random direction to a position, ensuring that the final position remains within the boundary of the playfield.
/// </summary>
/// <param name="position">The position which the offset should be applied to.</param>
/// <param name="maxOffset">The maximum offset, cannot exceed 20px.</param>
private void applyRandomOffset(ref float position, double maxOffset)
{ {
bool right = RNG.NextBool(); bool right = RNG.NextBool();
float rand = Math.Min(20, (float)RNG.NextDouble(0, Math.Max(0, maxOffset))) / CatchPlayfield.BASE_WIDTH;
float rand = Math.Min(20, (float)RNG.NextDouble(0, timeDiff / 4d)) / CatchPlayfield.BASE_WIDTH;
if (right) if (right)
{ {
// Clamp to the right bound
if (position + rand <= 1) if (position + rand <= 1)
position += rand; position += rand;
else else
@ -57,35 +89,33 @@ namespace osu.Game.Rulesets.Catch.Mods
} }
else else
{ {
// Clamp to the left bound
if (position - rand >= 0) if (position - rand >= 0)
position -= rand; position -= rand;
else else
position += rand; position += rand;
} }
catchObject.X = position;
return;
} }
if (Math.Abs(diff) < timeDiff / 3d) /// <summary>
/// Applies an offset to a position, ensuring that the final position remains within the boundary of the playfield.
/// </summary>
/// <param name="position">The position which the offset should be applied to.</param>
/// <param name="amount">The amount to offset by.</param>
private void applyOffset(ref float position, float amount)
{ {
if (diff > 0) if (amount > 0)
{ {
if (position - diff > 0) // Clamp to the right bound
position -= diff; if (position + amount < 1)
position += amount;
} }
else else
{ {
if (position - diff < 1) // Clamp to the left bound
position -= diff; if (position + amount > 0)
} position += amount;
} }
catchObject.X = position;
lastStartX = position;
lastStartTime = startTime;
} }
} }
} }

View File

@ -1,7 +1,6 @@
// 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.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Audio; using osu.Game.Audio;
@ -25,6 +24,11 @@ namespace osu.Game.Rulesets.Catch.Objects
public double Velocity; public double Velocity;
public double TickDistance; public double TickDistance;
/// <summary>
/// The length of one span of this <see cref="JuiceStream"/>.
/// </summary>
public double SpanDuration => Duration / this.SpanCount();
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaultsToSelf(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
@ -41,19 +45,6 @@ namespace osu.Game.Rulesets.Catch.Objects
protected override void CreateNestedHitObjects() protected override void CreateNestedHitObjects()
{ {
base.CreateNestedHitObjects(); base.CreateNestedHitObjects();
createTicks();
}
private void createTicks()
{
if (TickDistance == 0)
return;
var length = Path.Distance;
var tickDistance = Math.Min(TickDistance, length);
var spanDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
var tickSamples = Samples.Select(s => new SampleInfo var tickSamples = Samples.Select(s => new SampleInfo
{ {
@ -62,81 +53,59 @@ namespace osu.Game.Rulesets.Catch.Objects
Volume = s.Volume Volume = s.Volume
}).ToList(); }).ToList();
AddNested(new Fruit SliderEventDescriptor? lastEvent = null;
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset))
{ {
Samples = Samples, // generate tiny droplets since the last point
StartTime = StartTime, if (lastEvent != null)
X = X
});
double lastTickTime = StartTime;
for (int span = 0; span < this.SpanCount(); span++)
{ {
var spanStartTime = StartTime + span * spanDuration; double sinceLastTick = e.Time - lastEvent.Value.Time;
var reversed = span % 2 == 1;
for (double d = tickDistance;; d += tickDistance) if (sinceLastTick > 80)
{ {
bool isLastTick = false; double timeBetweenTiny = sinceLastTick;
if (d + minDistanceFromEnd >= length) while (timeBetweenTiny > 100)
timeBetweenTiny /= 2;
for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny)
{ {
d = length;
isLastTick = true;
}
var timeProgress = d / length;
var distanceProgress = reversed ? 1 - timeProgress : timeProgress;
double time = spanStartTime + timeProgress * spanDuration;
if (LegacyLastTickOffset != null)
{
// If we're the last tick, apply the legacy offset
if (span == this.SpanCount() - 1 && isLastTick)
time = Math.Max(StartTime + Duration / 2, time - LegacyLastTickOffset.Value);
}
int tinyTickCount = 1;
double tinyTickInterval = time - lastTickTime;
while (tinyTickInterval > 100 && tinyTickCount < 10000)
{
tinyTickInterval /= 2;
tinyTickCount *= 2;
}
for (int tinyTickIndex = 0; tinyTickIndex < tinyTickCount - 1; tinyTickIndex++)
{
var t = lastTickTime + (tinyTickIndex + 1) * tinyTickInterval;
double progress = reversed ? 1 - (t - spanStartTime) / spanDuration : (t - spanStartTime) / spanDuration;
AddNested(new TinyDroplet AddNested(new TinyDroplet
{ {
StartTime = t, Samples = tickSamples,
X = X + Path.PositionAt(progress).X / CatchPlayfield.BASE_WIDTH, StartTime = t + lastEvent.Value.Time,
Samples = tickSamples X = X + Path.PositionAt(
lastEvent.Value.PathProgress + (t / sinceLastTick) * (e.PathProgress - lastEvent.Value.PathProgress)).X / CatchPlayfield.BASE_WIDTH,
}); });
} }
}
}
lastTickTime = time; // this also includes LegacyLastTick and this is used for TinyDroplet generation above.
// this means that the final segment of TinyDroplets are increasingly mistimed where LegacyLastTickOffset is being applied.
if (isLastTick) lastEvent = e;
break;
switch (e.Type)
{
case SliderEventType.Tick:
AddNested(new Droplet AddNested(new Droplet
{ {
StartTime = time, Samples = tickSamples,
X = X + Path.PositionAt(distanceProgress).X / CatchPlayfield.BASE_WIDTH, StartTime = e.Time,
Samples = tickSamples X = X + Path.PositionAt(e.PathProgress).X / CatchPlayfield.BASE_WIDTH,
}); });
} break;
case SliderEventType.Head:
case SliderEventType.Tail:
case SliderEventType.Repeat:
AddNested(new Fruit AddNested(new Fruit
{ {
Samples = Samples, Samples = Samples,
StartTime = spanStartTime + spanDuration, StartTime = e.Time,
X = X + Path.PositionAt(reversed ? 0 : 1).X / CatchPlayfield.BASE_WIDTH X = X + Path.PositionAt(e.PathProgress).X / CatchPlayfield.BASE_WIDTH,
}); });
break;
}
} }
} }

View File

@ -13,8 +13,8 @@ namespace osu.Game.Rulesets.Catch.Scoring
{ {
public class CatchScoreProcessor : ScoreProcessor<CatchHitObject> public class CatchScoreProcessor : ScoreProcessor<CatchHitObject>
{ {
public CatchScoreProcessor(RulesetContainer<CatchHitObject> rulesetContainer) public CatchScoreProcessor(DrawableRuleset<CatchHitObject> drawableRuleset)
: base(rulesetContainer) : base(drawableRuleset)
{ {
} }

View File

@ -60,7 +60,7 @@ namespace osu.Game.Rulesets.Catch.UI
if (lastPlateableFruit.IsLoaded) if (lastPlateableFruit.IsLoaded)
action(); action();
else else
lastPlateableFruit.OnLoadComplete = _ => action(); lastPlateableFruit.OnLoadComplete += _ => action();
} }
if (result.IsHit && fruit.CanBePlated) if (result.IsHit && fruit.CanBePlated)

View File

@ -17,13 +17,13 @@ using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Catch.UI namespace osu.Game.Rulesets.Catch.UI
{ {
public class CatchRulesetContainer : ScrollingRulesetContainer<CatchPlayfield, CatchHitObject> public class DrawableCatchRuleset : DrawableScrollingRuleset<CatchHitObject>
{ {
protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Constant; protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Constant;
protected override bool UserScrollSpeedAdjustment => false; protected override bool UserScrollSpeedAdjustment => false;
public CatchRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public DrawableCatchRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
Direction.Value = ScrollingDirection.Down; Direction.Value = ScrollingDirection.Down;
@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Catch.UI
protected override Playfield CreatePlayfield() => new CatchPlayfield(Beatmap.BeatmapInfo.BaseDifficulty, GetVisualRepresentation); protected override Playfield CreatePlayfield() => new CatchPlayfield(Beatmap.BeatmapInfo.BaseDifficulty, GetVisualRepresentation);
public override PassThroughInputManager CreateInputManager() => new CatchInputManager(Ruleset.RulesetInfo); protected override PassThroughInputManager CreateInputManager() => new CatchInputManager(Ruleset.RulesetInfo);
public override DrawableHitObject<CatchHitObject> GetVisualRepresentation(CatchHitObject h) public override DrawableHitObject<CatchHitObject> GetVisualRepresentation(CatchHitObject h)
{ {

View File

@ -10,11 +10,11 @@ using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Mania.Edit namespace osu.Game.Rulesets.Mania.Edit
{ {
public class ManiaEditRulesetContainer : ManiaRulesetContainer public class DrawableManiaEditRuleset : DrawableManiaRuleset
{ {
public new IScrollingInfo ScrollingInfo => base.ScrollingInfo; public new IScrollingInfo ScrollingInfo => base.ScrollingInfo;
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public DrawableManiaEditRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Mania.Edit
[Cached(Type = typeof(IManiaHitObjectComposer))] [Cached(Type = typeof(IManiaHitObjectComposer))]
public class ManiaHitObjectComposer : HitObjectComposer<ManiaHitObject>, IManiaHitObjectComposer public class ManiaHitObjectComposer : HitObjectComposer<ManiaHitObject>, IManiaHitObjectComposer
{ {
protected new ManiaEditRulesetContainer RulesetContainer { get; private set; } protected new DrawableManiaEditRuleset DrawableRuleset { get; private set; }
public ManiaHitObjectComposer(Ruleset ruleset) public ManiaHitObjectComposer(Ruleset ruleset)
: base(ruleset) : base(ruleset)
@ -32,23 +32,23 @@ namespace osu.Game.Rulesets.Mania.Edit
/// </summary> /// </summary>
/// <param name="screenSpacePosition">The screen-space position.</param> /// <param name="screenSpacePosition">The screen-space position.</param>
/// <returns>The column which intersects with <paramref name="screenSpacePosition"/>.</returns> /// <returns>The column which intersects with <paramref name="screenSpacePosition"/>.</returns>
public Column ColumnAt(Vector2 screenSpacePosition) => RulesetContainer.GetColumnByPosition(screenSpacePosition); public Column ColumnAt(Vector2 screenSpacePosition) => DrawableRuleset.GetColumnByPosition(screenSpacePosition);
private DependencyContainer dependencies; private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); => dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
public int TotalColumns => ((ManiaPlayfield)RulesetContainer.Playfield).TotalColumns; public int TotalColumns => ((ManiaPlayfield)DrawableRuleset.Playfield).TotalColumns;
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) protected override DrawableRuleset<ManiaHitObject> CreateDrawableRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
{ {
RulesetContainer = new ManiaEditRulesetContainer(ruleset, beatmap); DrawableRuleset = new DrawableManiaEditRuleset(ruleset, beatmap);
// This is the earliest we can cache the scrolling info to ourselves, before masks are added to the hierarchy and inject it // This is the earliest we can cache the scrolling info to ourselves, before masks are added to the hierarchy and inject it
dependencies.CacheAs(RulesetContainer.ScrollingInfo); dependencies.CacheAs(DrawableRuleset.ScrollingInfo);
return RulesetContainer; return DrawableRuleset;
} }
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[] protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]

View File

@ -12,6 +12,7 @@ using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Replays; using osu.Game.Rulesets.Mania.Replays;
using osu.Game.Rulesets.Replays.Types; using osu.Game.Rulesets.Replays.Types;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
@ -30,7 +31,7 @@ namespace osu.Game.Rulesets.Mania
{ {
public class ManiaRuleset : Ruleset public class ManiaRuleset : Ruleset
{ {
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap) => new ManiaRulesetContainer(this, beatmap); public override DrawableRuleset CreateDrawableRulesetWith(WorkingBeatmap beatmap) => new DrawableManiaRuleset(this, beatmap);
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new ManiaBeatmapConverter(beatmap); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new ManiaBeatmapConverter(beatmap);
public override PerformanceCalculator CreatePerformanceCalculator(WorkingBeatmap beatmap, ScoreInfo score) => new ManiaPerformanceCalculator(this, beatmap, score); public override PerformanceCalculator CreatePerformanceCalculator(WorkingBeatmap beatmap, ScoreInfo score) => new ManiaPerformanceCalculator(this, beatmap, score);
@ -145,6 +146,11 @@ namespace osu.Game.Rulesets.Mania
{ {
new MultiMod(new ManiaModAutoplay(), new ModCinema()), new MultiMod(new ManiaModAutoplay(), new ModCinema()),
}; };
case ModType.Fun:
return new Mod[]
{
new MultiMod(new ModWindUp<ManiaHitObject>(), new ModWindDown<ManiaHitObject>())
};
default: default:
return new Mod[] { }; return new Mod[] { };
} }

View File

@ -92,8 +92,8 @@ namespace osu.Game.Rulesets.Mania.Scoring
{ {
} }
public ManiaScoreProcessor(RulesetContainer<ManiaHitObject> rulesetContainer) public ManiaScoreProcessor(DrawableRuleset<ManiaHitObject> drawableRuleset)
: base(rulesetContainer) : base(drawableRuleset)
{ {
} }

View File

@ -22,22 +22,15 @@ namespace osu.Game.Rulesets.Mania.UI
JudgementText.Font = JudgementText.Font.With(size: 25); JudgementText.Font = JudgementText.Font.With(size: 25);
} }
protected override void LoadComplete() protected override double FadeInDuration => 50;
{
base.LoadComplete();
this.FadeInFromZero(50, Easing.OutQuint); protected override void ApplyHitAnimations()
if (Result.IsHit)
{ {
JudgementBody.ScaleTo(0.8f); JudgementBody.ScaleTo(0.8f);
JudgementBody.ScaleTo(1, 250, Easing.OutElastic); JudgementBody.ScaleTo(1, 250, Easing.OutElastic);
JudgementBody.Delay(50).ScaleTo(0.75f, 250); JudgementBody.Delay(FadeInDuration).ScaleTo(0.75f, 250);
this.Delay(50).FadeOut(200); this.Delay(FadeInDuration).FadeOut(200);
}
Expire();
} }
} }
} }

View File

@ -28,8 +28,10 @@ using osuTK;
namespace osu.Game.Rulesets.Mania.UI namespace osu.Game.Rulesets.Mania.UI
{ {
public class ManiaRulesetContainer : ScrollingRulesetContainer<ManiaPlayfield, ManiaHitObject> public class DrawableManiaRuleset : DrawableScrollingRuleset<ManiaHitObject>
{ {
protected new ManiaPlayfield Playfield => (ManiaPlayfield)base.Playfield;
public new ManiaBeatmap Beatmap => (ManiaBeatmap)base.Beatmap; public new ManiaBeatmap Beatmap => (ManiaBeatmap)base.Beatmap;
public IEnumerable<BarLine> BarLines; public IEnumerable<BarLine> BarLines;
@ -38,7 +40,7 @@ namespace osu.Game.Rulesets.Mania.UI
private readonly Bindable<ManiaScrollingDirection> configDirection = new Bindable<ManiaScrollingDirection>(); private readonly Bindable<ManiaScrollingDirection> configDirection = new Bindable<ManiaScrollingDirection>();
public ManiaRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public DrawableManiaRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
// Generate the bar lines // Generate the bar lines
@ -97,7 +99,7 @@ namespace osu.Game.Rulesets.Mania.UI
public override int Variant => (int)(Beatmap.Stages.Count == 1 ? PlayfieldType.Single : PlayfieldType.Dual) + Beatmap.TotalColumns; public override int Variant => (int)(Beatmap.Stages.Count == 1 ? PlayfieldType.Single : PlayfieldType.Dual) + Beatmap.TotalColumns;
public override PassThroughInputManager CreateInputManager() => new ManiaInputManager(Ruleset.RulesetInfo, Variant); protected override PassThroughInputManager CreateInputManager() => new ManiaInputManager(Ruleset.RulesetInfo, Variant);
public override DrawableHitObject<ManiaHitObject> GetVisualRepresentation(ManiaHitObject h) public override DrawableHitObject<ManiaHitObject> GetVisualRepresentation(ManiaHitObject h)
{ {

View File

@ -4,12 +4,13 @@
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Visual;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Osu.Tests namespace osu.Game.Rulesets.Osu.Tests
{ {
[TestFixture] [TestFixture]
public class TestCaseHitCircleLongCombo : Game.Tests.Visual.TestCasePlayer public class TestCaseHitCircleLongCombo : PlayerTestCase
{ {
public TestCaseHitCircleLongCombo() public TestCaseHitCircleLongCombo()
: base(new OsuRuleset()) : base(new OsuRuleset())

View File

@ -0,0 +1,17 @@
// 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.
using NUnit.Framework;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class TestCaseOsuPlayer : PlayerTestCase
{
public TestCaseOsuPlayer()
: base(new OsuRuleset())
{
}
}
}

View File

@ -354,9 +354,9 @@ namespace osu.Game.Rulesets.Osu.Tests
judgementResults = new List<JudgementResult>(); judgementResults = new List<JudgementResult>();
}); });
AddUntilStep(() => Beatmap.Value.Track.CurrentTime == 0, "Beatmap at 0"); AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
AddUntilStep(() => currentPlayer.IsCurrentScreen(), "Wait until player is loaded"); AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
AddUntilStep(() => allJudgedFired, "Wait for all judged"); AddUntilStep("Wait for all judged", () => allJudgedFired);
} }
private class ScoreAccessibleReplayPlayer : ReplayPlayer private class ScoreAccessibleReplayPlayer : ReplayPlayer

View File

@ -8,9 +8,9 @@ using osuTK;
namespace osu.Game.Rulesets.Osu.Edit namespace osu.Game.Rulesets.Osu.Edit
{ {
public class OsuEditRulesetContainer : OsuRulesetContainer public class DrawableOsuEditRuleset : DrawableOsuRuleset
{ {
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public DrawableOsuEditRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
} }

View File

@ -26,8 +26,8 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
} }
protected override RulesetContainer<OsuHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) protected override DrawableRuleset<OsuHitObject> CreateDrawableRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
=> new OsuEditRulesetContainer(ruleset, beatmap); => new DrawableOsuEditRuleset(ruleset, beatmap);
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[] protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
{ {

View File

@ -18,7 +18,7 @@ using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModBlinds : Mod, IApplicableToRulesetContainer<OsuHitObject>, IApplicableToScoreProcessor public class OsuModBlinds : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToScoreProcessor
{ {
public override string Name => "Blinds"; public override string Name => "Blinds";
public override string Description => "Play with blinds on your screen."; public override string Description => "Play with blinds on your screen.";
@ -32,9 +32,9 @@ namespace osu.Game.Rulesets.Osu.Mods
public override double ScoreMultiplier => 1.12; public override double ScoreMultiplier => 1.12;
private DrawableOsuBlinds blinds; private DrawableOsuBlinds blinds;
public void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer) public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{ {
rulesetContainer.Overlays.Add(blinds = new DrawableOsuBlinds(rulesetContainer.Playfield.HitObjectContainer, rulesetContainer.Beatmap)); drawableRuleset.Overlays.Add(blinds = new DrawableOsuBlinds(drawableRuleset.Playfield.HitObjectContainer, drawableRuleset.Beatmap));
} }
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)

View File

@ -13,7 +13,7 @@ using static osu.Game.Input.Handlers.ReplayInputHandler;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModRelax : ModRelax, IApplicableFailOverride, IUpdatableByPlayfield, IApplicableToRulesetContainer<OsuHitObject> public class OsuModRelax : ModRelax, IApplicableFailOverride, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
{ {
public override string Description => @"You don't need to click. Give your clicking/tapping fingers a break from the heat of things."; public override string Description => @"You don't need to click. Give your clicking/tapping fingers a break from the heat of things.";
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).ToArray(); public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).ToArray();
@ -79,10 +79,10 @@ namespace osu.Game.Rulesets.Osu.Mods
state.Apply(osuInputManager.CurrentState, osuInputManager); state.Apply(osuInputManager.CurrentState, osuInputManager);
} }
public void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer) public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{ {
// grab the input manager for future use. // grab the input manager for future use.
osuInputManager = (OsuInputManager)rulesetContainer.KeyBindingInputManager; osuInputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
osuInputManager.AllowUserPresses = false; osuInputManager.AllowUserPresses = false;
} }
} }

View File

@ -5,7 +5,6 @@ using osu.Framework.Graphics;
using osuTK; using osuTK;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Objects.Drawables namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
@ -16,12 +15,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
} }
protected override void LoadComplete() protected override void ApplyHitAnimations()
{ {
if (Result.Type != HitResult.Miss)
JudgementText?.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint); JudgementText?.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
base.ApplyHitAnimations();
base.LoadComplete();
} }
} }
} }

View File

@ -132,6 +132,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
base.ClearTransformsAfter(time, false, targetMember); base.ClearTransformsAfter(time, false, targetMember);
} }
public override void ApplyTransformsAt(double time, bool propagateChildren = false)
{
// For the same reasons as above w.r.t rewinding, we shouldn't propagate to children here either.
base.ApplyTransformsAt(time, false);
}
private bool tracking; private bool tracking;
public bool Tracking public bool Tracking

View File

@ -1,7 +1,6 @@
// 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 osuTK; using osuTK;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using System.Collections.Generic; using System.Collections.Generic;
@ -155,66 +154,9 @@ namespace osu.Game.Rulesets.Osu.Objects
{ {
base.CreateNestedHitObjects(); base.CreateNestedHitObjects();
createSliderEnds(); foreach (var e in
createTicks(); SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset))
createRepeatPoints();
if (LegacyLastTickOffset != null)
TailCircle.StartTime = Math.Max(StartTime + Duration / 2, TailCircle.StartTime - LegacyLastTickOffset.Value);
}
private void createSliderEnds()
{ {
HeadCircle = new SliderCircle
{
StartTime = StartTime,
Position = Position,
Samples = getNodeSamples(0),
SampleControlPoint = SampleControlPoint,
IndexInCurrentCombo = IndexInCurrentCombo,
ComboIndex = ComboIndex,
};
TailCircle = new SliderTailCircle(this)
{
StartTime = EndTime,
Position = EndPosition,
IndexInCurrentCombo = IndexInCurrentCombo,
ComboIndex = ComboIndex,
};
AddNested(HeadCircle);
AddNested(TailCircle);
}
private void createTicks()
{
// A very lenient maximum length of a slider for ticks to be generated.
// This exists for edge cases such as /b/1573664 where the beatmap has been edited by the user, and should never be reached in normal usage.
const double max_length = 100000;
var length = Math.Min(max_length, Path.Distance);
var tickDistance = MathHelper.Clamp(TickDistance, 0, length);
if (tickDistance == 0) return;
var minDistanceFromEnd = Velocity * 10;
var spanCount = this.SpanCount();
for (var span = 0; span < spanCount; span++)
{
var spanStartTime = StartTime + span * SpanDuration;
var reversed = span % 2 == 1;
for (var d = tickDistance; d <= length; d += tickDistance)
{
if (d > length - minDistanceFromEnd)
break;
var distanceProgress = d / length;
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress;
var firstSample = Samples.Find(s => s.Name == SampleInfo.HIT_NORMAL) var firstSample = Samples.Find(s => s.Name == SampleInfo.HIT_NORMAL)
?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933) ?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
var sampleList = new List<SampleInfo>(); var sampleList = new List<SampleInfo>();
@ -227,44 +169,61 @@ namespace osu.Game.Rulesets.Osu.Objects
Name = @"slidertick", Name = @"slidertick",
}); });
switch (e.Type)
{
case SliderEventType.Tick:
AddNested(new SliderTick AddNested(new SliderTick
{ {
SpanIndex = span, SpanIndex = e.SpanIndex,
SpanStartTime = spanStartTime, SpanStartTime = e.SpanStartTime,
StartTime = spanStartTime + timeProgress * SpanDuration, StartTime = e.Time,
Position = Position + Path.PositionAt(distanceProgress), Position = Position + Path.PositionAt(e.PathProgress),
StackHeight = StackHeight, StackHeight = StackHeight,
Scale = Scale, Scale = Scale,
Samples = sampleList Samples = sampleList
}); });
} break;
} case SliderEventType.Head:
} AddNested(HeadCircle = new SliderCircle
private void createRepeatPoints()
{ {
for (int repeatIndex = 0, repeat = 1; repeatIndex < RepeatCount; repeatIndex++, repeat++) StartTime = e.Time,
Position = Position,
Samples = getNodeSamples(0),
SampleControlPoint = SampleControlPoint,
IndexInCurrentCombo = IndexInCurrentCombo,
ComboIndex = ComboIndex,
});
break;
case SliderEventType.LegacyLastTick:
// we need to use the LegacyLastTick here for compatibility reasons (difficulty).
// it is *okay* to use this because the TailCircle is not used for any meaningful purpose in gameplay.
// if this is to change, we should revisit this.
AddNested(TailCircle = new SliderTailCircle(this)
{ {
StartTime = e.Time,
Position = EndPosition,
IndexInCurrentCombo = IndexInCurrentCombo,
ComboIndex = ComboIndex,
});
break;
case SliderEventType.Repeat:
AddNested(new RepeatPoint AddNested(new RepeatPoint
{ {
RepeatIndex = repeatIndex, RepeatIndex = e.SpanIndex,
SpanDuration = SpanDuration, SpanDuration = SpanDuration,
StartTime = StartTime + repeat * SpanDuration, StartTime = StartTime + (e.SpanIndex + 1) * SpanDuration,
Position = Position + Path.PositionAt(repeat % 2), Position = Position + Path.PositionAt(e.PathProgress),
StackHeight = StackHeight, StackHeight = StackHeight,
Scale = Scale, Scale = Scale,
Samples = getNodeSamples(1 + repeatIndex) Samples = getNodeSamples(e.SpanIndex + 1)
}); });
break;
}
} }
} }
private List<SampleInfo> getNodeSamples(int nodeIndex) private List<SampleInfo> getNodeSamples(int nodeIndex) =>
{ nodeIndex < NodeSamples.Count ? NodeSamples[nodeIndex] : Samples;
if (nodeIndex < NodeSamples.Count)
return NodeSamples[nodeIndex];
return Samples;
}
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
} }

View File

@ -8,6 +8,10 @@ using osu.Game.Rulesets.Osu.Judgements;
namespace osu.Game.Rulesets.Osu.Objects namespace osu.Game.Rulesets.Osu.Objects
{ {
/// <summary>
/// Note that this should not be used for timing correctness.
/// See <see cref="SliderEventType.LegacyLastTick"/> usage in <see cref="Slider"/> for more information.
/// </summary>
public class SliderTailCircle : SliderCircle public class SliderTailCircle : SliderCircle
{ {
private readonly IBindable<SliderPath> pathBindable = new Bindable<SliderPath>(); private readonly IBindable<SliderPath> pathBindable = new Bindable<SliderPath>();

View File

@ -13,6 +13,7 @@ using osu.Game.Overlays.Settings;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Osu.Edit; using osu.Game.Rulesets.Osu.Edit;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays; using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Replays.Types; using osu.Game.Rulesets.Replays.Types;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
@ -28,7 +29,7 @@ namespace osu.Game.Rulesets.Osu
{ {
public class OsuRuleset : Ruleset public class OsuRuleset : Ruleset
{ {
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap) => new OsuRulesetContainer(this, beatmap); public override DrawableRuleset CreateDrawableRulesetWith(WorkingBeatmap beatmap) => new DrawableOsuRuleset(this, beatmap);
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new OsuBeatmapConverter(beatmap); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new OsuBeatmapConverter(beatmap);
public override IBeatmapProcessor CreateBeatmapProcessor(IBeatmap beatmap) => new OsuBeatmapProcessor(beatmap); public override IBeatmapProcessor CreateBeatmapProcessor(IBeatmap beatmap) => new OsuBeatmapProcessor(beatmap);
@ -128,7 +129,8 @@ namespace osu.Game.Rulesets.Osu
{ {
new OsuModTransform(), new OsuModTransform(),
new OsuModWiggle(), new OsuModWiggle(),
new OsuModGrow() new OsuModGrow(),
new MultiMod(new ModWindUp<OsuHitObject>(), new ModWindDown<OsuHitObject>()),
}; };
default: default:
return new Mod[] { }; return new Mod[] { };

View File

@ -15,8 +15,8 @@ namespace osu.Game.Rulesets.Osu.Scoring
{ {
internal class OsuScoreProcessor : ScoreProcessor<OsuHitObject> internal class OsuScoreProcessor : ScoreProcessor<OsuHitObject>
{ {
public OsuScoreProcessor(RulesetContainer<OsuHitObject> rulesetContainer) public OsuScoreProcessor(DrawableRuleset<OsuHitObject> drawableRuleset)
: base(rulesetContainer) : base(drawableRuleset)
{ {
} }

View File

@ -17,11 +17,11 @@ using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
public class OsuRulesetContainer : RulesetContainer<OsuPlayfield, OsuHitObject> public class DrawableOsuRuleset : DrawableRuleset<OsuHitObject>
{ {
protected new OsuRulesetConfigManager Config => (OsuRulesetConfigManager)base.Config; protected new OsuRulesetConfigManager Config => (OsuRulesetConfigManager)base.Config;
public OsuRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public DrawableOsuRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
} }
@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.UI
protected override Playfield CreatePlayfield() => new OsuPlayfield(); protected override Playfield CreatePlayfield() => new OsuPlayfield();
public override PassThroughInputManager CreateInputManager() => new OsuInputManager(Ruleset.RulesetInfo); protected override PassThroughInputManager CreateInputManager() => new OsuInputManager(Ruleset.RulesetInfo);
public override DrawableHitObject<OsuHitObject> GetVisualRepresentation(OsuHitObject h) public override DrawableHitObject<OsuHitObject> GetVisualRepresentation(OsuHitObject h)
{ {

View File

@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
protected override double TimePerAction => default_duration * 2; protected override double TimePerAction => default_duration * 2;
private readonly Random rng = new Random(1337); private readonly Random rng = new Random(1337);
private TaikoRulesetContainer rulesetContainer; private DrawableTaikoRuleset drawableRuleset;
private Container playfieldContainer; private Container playfieldContainer;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -86,7 +86,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 768, Height = 768,
Children = new[] { rulesetContainer = new TaikoRulesetContainer(new TaikoRuleset(), beatmap) } Children = new[] { drawableRuleset = new DrawableTaikoRuleset(new TaikoRuleset(), beatmap) }
}); });
} }
@ -139,7 +139,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
var h = new DrawableTestHit(hit) { X = RNG.NextSingle(hitResult == HitResult.Good ? -0.1f : -0.05f, hitResult == HitResult.Good ? 0.1f : 0.05f) }; var h = new DrawableTestHit(hit) { X = RNG.NextSingle(hitResult == HitResult.Good ? -0.1f : -0.05f, hitResult == HitResult.Good ? 0.1f : 0.05f) };
((TaikoPlayfield)rulesetContainer.Playfield).OnNewResult(h, new JudgementResult(new TaikoJudgement()) { Type = hitResult }); ((TaikoPlayfield)drawableRuleset.Playfield).OnNewResult(h, new JudgementResult(new TaikoJudgement()) { Type = hitResult });
} }
private void addStrongHitJudgement(bool kiai) private void addStrongHitJudgement(bool kiai)
@ -154,33 +154,33 @@ namespace osu.Game.Rulesets.Taiko.Tests
var h = new DrawableTestHit(hit) { X = RNG.NextSingle(hitResult == HitResult.Good ? -0.1f : -0.05f, hitResult == HitResult.Good ? 0.1f : 0.05f) }; var h = new DrawableTestHit(hit) { X = RNG.NextSingle(hitResult == HitResult.Good ? -0.1f : -0.05f, hitResult == HitResult.Good ? 0.1f : 0.05f) };
((TaikoPlayfield)rulesetContainer.Playfield).OnNewResult(h, new JudgementResult(new TaikoJudgement()) { Type = hitResult }); ((TaikoPlayfield)drawableRuleset.Playfield).OnNewResult(h, new JudgementResult(new TaikoJudgement()) { Type = hitResult });
((TaikoPlayfield)rulesetContainer.Playfield).OnNewResult(new TestStrongNestedHit(h), new JudgementResult(new TaikoStrongJudgement()) { Type = HitResult.Great }); ((TaikoPlayfield)drawableRuleset.Playfield).OnNewResult(new TestStrongNestedHit(h), new JudgementResult(new TaikoStrongJudgement()) { Type = HitResult.Great });
} }
private void addMissJudgement() private void addMissJudgement()
{ {
((TaikoPlayfield)rulesetContainer.Playfield).OnNewResult(new DrawableTestHit(new Hit()), new JudgementResult(new TaikoJudgement()) { Type = HitResult.Miss }); ((TaikoPlayfield)drawableRuleset.Playfield).OnNewResult(new DrawableTestHit(new Hit()), new JudgementResult(new TaikoJudgement()) { Type = HitResult.Miss });
} }
private void addBarLine(bool major, double delay = scroll_time) private void addBarLine(bool major, double delay = scroll_time)
{ {
BarLine bl = new BarLine { StartTime = rulesetContainer.Playfield.Time.Current + delay }; BarLine bl = new BarLine { StartTime = drawableRuleset.Playfield.Time.Current + delay };
rulesetContainer.Playfield.Add(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl)); drawableRuleset.Playfield.Add(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl));
} }
private void addSwell(double duration = default_duration) private void addSwell(double duration = default_duration)
{ {
var swell = new Swell var swell = new Swell
{ {
StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, StartTime = drawableRuleset.Playfield.Time.Current + scroll_time,
Duration = duration, Duration = duration,
}; };
swell.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); swell.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
rulesetContainer.Playfield.Add(new DrawableSwell(swell)); drawableRuleset.Playfield.Add(new DrawableSwell(swell));
} }
private void addDrumRoll(bool strong, double duration = default_duration) private void addDrumRoll(bool strong, double duration = default_duration)
@ -190,40 +190,40 @@ namespace osu.Game.Rulesets.Taiko.Tests
var d = new DrumRoll var d = new DrumRoll
{ {
StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, StartTime = drawableRuleset.Playfield.Time.Current + scroll_time,
IsStrong = strong, IsStrong = strong,
Duration = duration, Duration = duration,
}; };
d.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); d.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
rulesetContainer.Playfield.Add(new DrawableDrumRoll(d)); drawableRuleset.Playfield.Add(new DrawableDrumRoll(d));
} }
private void addCentreHit(bool strong) private void addCentreHit(bool strong)
{ {
Hit h = new Hit Hit h = new Hit
{ {
StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, StartTime = drawableRuleset.Playfield.Time.Current + scroll_time,
IsStrong = strong IsStrong = strong
}; };
h.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); h.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
rulesetContainer.Playfield.Add(new DrawableCentreHit(h)); drawableRuleset.Playfield.Add(new DrawableCentreHit(h));
} }
private void addRimHit(bool strong) private void addRimHit(bool strong)
{ {
Hit h = new Hit Hit h = new Hit
{ {
StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, StartTime = drawableRuleset.Playfield.Time.Current + scroll_time,
IsStrong = strong IsStrong = strong
}; };
h.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); h.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
rulesetContainer.Playfield.Add(new DrawableRimHit(h)); drawableRuleset.Playfield.Add(new DrawableRimHit(h));
} }
private class TestStrongNestedHit : DrawableStrongNestedHit private class TestStrongNestedHit : DrawableStrongNestedHit

View File

@ -22,10 +22,10 @@ namespace osu.Game.Rulesets.Taiko.Mods
private TaikoPlayfield playfield; private TaikoPlayfield playfield;
public override void ApplyToRulesetContainer(RulesetContainer<TaikoHitObject> rulesetContainer) public override void ApplyToDrawableRuleset(DrawableRuleset<TaikoHitObject> drawableRuleset)
{ {
playfield = (TaikoPlayfield)rulesetContainer.Playfield; playfield = (TaikoPlayfield)drawableRuleset.Playfield;
base.ApplyToRulesetContainer(rulesetContainer); base.ApplyToDrawableRuleset(drawableRuleset);
} }
private class TaikoFlashlight : Flashlight private class TaikoFlashlight : Flashlight

View File

@ -32,8 +32,8 @@ namespace osu.Game.Rulesets.Taiko.Scoring
/// </summary> /// </summary>
private double hpMissMultiplier; private double hpMissMultiplier;
public TaikoScoreProcessor(RulesetContainer<TaikoHitObject> rulesetContainer) public TaikoScoreProcessor(DrawableRuleset<TaikoHitObject> drawableRuleset)
: base(rulesetContainer) : base(drawableRuleset)
{ {
} }

View File

@ -11,6 +11,7 @@ using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Replays.Types; using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Taiko.Replays; using osu.Game.Rulesets.Taiko.Replays;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Difficulty;
@ -22,7 +23,7 @@ namespace osu.Game.Rulesets.Taiko
{ {
public class TaikoRuleset : Ruleset public class TaikoRuleset : Ruleset
{ {
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap) => new TaikoRulesetContainer(this, beatmap); public override DrawableRuleset CreateDrawableRulesetWith(WorkingBeatmap beatmap) => new DrawableTaikoRuleset(this, beatmap);
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TaikoBeatmapConverter(beatmap); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new TaikoBeatmapConverter(beatmap);
public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) => new[] public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) => new[]
@ -99,6 +100,11 @@ namespace osu.Game.Rulesets.Taiko
new MultiMod(new TaikoModAutoplay(), new ModCinema()), new MultiMod(new TaikoModAutoplay(), new ModCinema()),
new TaikoModRelax(), new TaikoModRelax(),
}; };
case ModType.Fun:
return new Mod[]
{
new MultiMod(new ModWindUp<TaikoHitObject>(), new ModWindDown<TaikoHitObject>())
};
default: default:
return new Mod[] { }; return new Mod[] { };
} }

View File

@ -39,12 +39,10 @@ namespace osu.Game.Rulesets.Taiko.UI
} }
} }
protected override void LoadComplete() protected override void ApplyHitAnimations()
{ {
if (Result.IsHit)
this.MoveToY(-100, 500); this.MoveToY(-100, 500);
base.ApplyHitAnimations();
base.LoadComplete();
} }
} }
} }

View File

@ -20,13 +20,13 @@ using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Taiko.UI namespace osu.Game.Rulesets.Taiko.UI
{ {
public class TaikoRulesetContainer : ScrollingRulesetContainer<TaikoPlayfield, TaikoHitObject> public class DrawableTaikoRuleset : DrawableScrollingRuleset<TaikoHitObject>
{ {
protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping; protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping;
protected override bool UserScrollSpeedAdjustment => false; protected override bool UserScrollSpeedAdjustment => false;
public TaikoRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public DrawableTaikoRuleset(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {
Direction.Value = ScrollingDirection.Left; Direction.Value = ScrollingDirection.Left;
@ -81,7 +81,7 @@ namespace osu.Game.Rulesets.Taiko.UI
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this); public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this);
public override PassThroughInputManager CreateInputManager() => new TaikoInputManager(Ruleset.RulesetInfo); protected override PassThroughInputManager CreateInputManager() => new TaikoInputManager(Ruleset.RulesetInfo);
protected override Playfield CreatePlayfield() => new TaikoPlayfield(Beatmap.ControlPointInfo); protected override Playfield CreatePlayfield() => new TaikoPlayfield(Beatmap.ControlPointInfo);

View File

@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Taiko.UI
public class TaikoPlayfield : ScrollingPlayfield public class TaikoPlayfield : ScrollingPlayfield
{ {
/// <summary> /// <summary>
/// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="TaikoRulesetContainer"/>. /// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="DrawableTaikoRuleset"/>.
/// </summary> /// </summary>
public const float DEFAULT_HEIGHT = 178; public const float DEFAULT_HEIGHT = 178;

View File

@ -0,0 +1,72 @@
// 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.
using System;
using System.Globalization;
using NUnit.Framework;
using osu.Game.Beatmaps.Formats;
namespace osu.Game.Tests.Beatmaps.Formats
{
[TestFixture]
public class ParsingTest
{
[Test]
public void TestNaNHandling() => allThrow<FormatException>("NaN");
[Test]
public void TestBadStringHandling() => allThrow<FormatException>("Random string 123");
[TestCase(Parsing.MAX_PARSE_VALUE)]
[TestCase(-1)]
[TestCase(0)]
[TestCase(1)]
[TestCase(-Parsing.MAX_PARSE_VALUE)]
[TestCase(10, 10)]
[TestCase(-10, 10)]
public void TestValidRanges(double input, double limit = Parsing.MAX_PARSE_VALUE)
{
Assert.AreEqual(Parsing.ParseInt((input).ToString(CultureInfo.InvariantCulture), (int)limit), (int)input);
Assert.AreEqual(Parsing.ParseFloat((input).ToString(CultureInfo.InvariantCulture), (float)limit), (float)input);
Assert.AreEqual(Parsing.ParseDouble((input).ToString(CultureInfo.InvariantCulture), limit), input);
}
[TestCase(double.PositiveInfinity)]
[TestCase(double.NegativeInfinity)]
[TestCase(999999999999)]
[TestCase(Parsing.MAX_PARSE_VALUE * 1.1)]
[TestCase(-Parsing.MAX_PARSE_VALUE * 1.1)]
[TestCase(11, 10)]
[TestCase(-11, 10)]
public void TestOutOfRangeHandling(double input, double limit = Parsing.MAX_PARSE_VALUE)
=> allThrow<OverflowException>(input.ToString(CultureInfo.InvariantCulture), limit);
private void allThrow<T>(string input, double limit = Parsing.MAX_PARSE_VALUE)
where T : Exception
{
Assert.Throws(getIntParseException(input) ?? typeof(T), () => Parsing.ParseInt(input, (int)limit));
Assert.Throws<T>(() => Parsing.ParseFloat(input, (float)limit));
Assert.Throws<T>(() => Parsing.ParseDouble(input, limit));
}
/// <summary>
/// <see cref="int"/> may not be able to parse some inputs.
/// In this case we expect to receive the raw parsing exception.
/// </summary>
/// <param name="input">The input attempting to be parsed.</param>
/// <returns>The type of exception thrown by <see cref="int.Parse(string)"/>. Null if no exception is thrown.</returns>
private Type getIntParseException(string input)
{
try
{
var _ = int.Parse(input);
}
catch (Exception e)
{
return e.GetType();
}
return null;
}
}
}

View File

@ -207,6 +207,96 @@ namespace osu.Game.Tests.Beatmaps.IO
} }
} }
[TestCase(true)]
[TestCase(false)]
public void TestImportThenDeleteThenImportWithOnlineIDMismatch(bool set)
{
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
using (HeadlessGameHost host = new CleanRunHeadlessGameHost($"TestImportThenDeleteThenImport-{set}"))
{
try
{
var osu = loadOsu(host);
var imported = LoadOszIntoOsu(osu);
if (set)
imported.OnlineBeatmapSetID = 1234;
else
imported.Beatmaps.First().OnlineBeatmapID = 1234;
osu.Dependencies.Get<BeatmapManager>().Update(imported);
deleteBeatmapSet(imported, osu);
var importedSecondTime = LoadOszIntoOsu(osu);
// check the newly "imported" beatmap has been reimported due to mismatch (even though hashes matched)
Assert.IsTrue(imported.ID != importedSecondTime.ID);
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Beatmaps.First().ID);
}
finally
{
host.Exit();
}
}
}
[Test]
public void TestImportWithDuplicateBeatmapIDs()
{
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWithDuplicateBeatmapID"))
{
try
{
var osu = loadOsu(host);
var metadata = new BeatmapMetadata
{
Artist = "SomeArtist",
AuthorString = "SomeAuthor"
};
var difficulty = new BeatmapDifficulty();
var toImport = new BeatmapSetInfo
{
OnlineBeatmapSetID = 1,
Metadata = metadata,
Beatmaps = new List<BeatmapInfo>
{
new BeatmapInfo
{
OnlineBeatmapID = 2,
Metadata = metadata,
BaseDifficulty = difficulty
},
new BeatmapInfo
{
OnlineBeatmapID = 2,
Metadata = metadata,
Status = BeatmapSetOnlineStatus.Loved,
BaseDifficulty = difficulty
}
}
};
var manager = osu.Dependencies.Get<BeatmapManager>();
var imported = manager.Import(toImport);
Assert.NotNull(imported);
Assert.AreEqual(null, imported.Beatmaps[0].OnlineBeatmapID);
Assert.AreEqual(null, imported.Beatmaps[1].OnlineBeatmapID);
}
finally
{
host.Exit();
}
}
}
[Test] [Test]
[NonParallelizable] [NonParallelizable]
[Ignore("Binding IPC on Appveyor isn't working (port in use). Need to figure out why")] [Ignore("Binding IPC on Appveyor isn't working (port in use). Need to figure out why")]

View File

@ -1,12 +0,0 @@
// 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.
using NUnit.Framework;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseAllPlayers : TestCasePlayer
{
}
}

View File

@ -1,7 +1,6 @@
// 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;
@ -11,7 +10,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
[Description("Player instantiated with an autoplay mod.")] [Description("Player instantiated with an autoplay mod.")]
public class TestCaseAutoplay : TestCasePlayer public class TestCaseAutoplay : AllPlayersTestCase
{ {
protected override Player CreatePlayer(Ruleset ruleset) protected override Player CreatePlayer(Ruleset ruleset)
{ {
@ -24,11 +23,10 @@ namespace osu.Game.Tests.Visual
}; };
} }
protected override void AddCheckSteps(Func<Player> player) protected override void AddCheckSteps()
{ {
base.AddCheckSteps(player); AddUntilStep("score above zero", () => ((ScoreAccessiblePlayer)Player).ScoreProcessor.TotalScore.Value > 0);
AddUntilStep(() => ((ScoreAccessiblePlayer)player()).ScoreProcessor.TotalScore.Value > 0, "score above zero"); AddUntilStep("key counter counted keys", () => ((ScoreAccessiblePlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0));
AddUntilStep(() => ((ScoreAccessiblePlayer)player()).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0), "key counter counted keys");
} }
private class ScoreAccessiblePlayer : Player private class ScoreAccessiblePlayer : Player

View File

@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual
{ {
setupUserSettings(); setupUserSettings();
AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer()))); AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())));
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load"); AddUntilStep("Wait for Player Loader to load", () => playerLoader?.IsLoaded ?? false);
AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent()); AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent());
AddStep("Trigger background preview", () => AddStep("Trigger background preview", () =>
{ {
@ -220,7 +220,7 @@ namespace osu.Game.Tests.Visual
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed()); AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
} }
private void waitForDim() => AddWaitStep(5, "Wait for dim"); private void waitForDim() => AddWaitStep("Wait for dim", 5);
private void createFakeStoryboard() => AddStep("Create storyboard", () => private void createFakeStoryboard() => AddStep("Create storyboard", () =>
{ {
@ -249,14 +249,14 @@ namespace osu.Game.Tests.Visual
Ready = true, Ready = true,
})); }));
}); });
AddUntilStep(() => playerLoader.IsLoaded, "Wait for Player Loader to load"); AddUntilStep("Wait for Player Loader to load", () => playerLoader.IsLoaded);
AddStep("Move mouse to center of screen", () => InputManager.MoveMouseTo(playerLoader.ScreenPos)); AddStep("Move mouse to center of screen", () => InputManager.MoveMouseTo(playerLoader.ScreenPos));
AddUntilStep(() => player.IsLoaded, "Wait for player to load"); AddUntilStep("Wait for player to load", () => player.IsLoaded);
} }
private void setupUserSettings() private void setupUserSettings()
{ {
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "Song select has selection"); AddUntilStep("Song select has selection", () => songSelect.Carousel.SelectedBeatmap != null);
AddStep("Set default user settings", () => AddStep("Set default user settings", () =>
{ {
Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }); Beatmap.Value.Mods.Value = Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() });
@ -350,7 +350,7 @@ namespace osu.Game.Tests.Visual
Thread.Sleep(1); Thread.Sleep(1);
StoryboardEnabled = config.GetBindable<bool>(OsuSetting.ShowStoryboard); StoryboardEnabled = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
ReplacesBackground.BindTo(Background.StoryboardReplacesBackground); ReplacesBackground.BindTo(Background.StoryboardReplacesBackground);
RulesetContainer.IsPaused.BindTo(IsPaused); DrawableRuleset.IsPaused.BindTo(IsPaused);
} }
} }

View File

@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual
carousel.BeatmapSetsChanged = () => changed = true; carousel.BeatmapSetsChanged = () => changed = true;
carousel.BeatmapSets = beatmapSets; carousel.BeatmapSets = beatmapSets;
}); });
AddUntilStep(() => changed, "Wait for load"); AddUntilStep("Wait for load", () => changed);
} }
private void ensureRandomFetchSuccess() => private void ensureRandomFetchSuccess() =>
@ -214,7 +214,7 @@ namespace osu.Game.Tests.Visual
checkSelected(3, 2); checkSelected(3, 2);
AddStep("Un-filter (debounce)", () => carousel.Filter(new FilterCriteria())); AddStep("Un-filter (debounce)", () => carousel.Filter(new FilterCriteria()));
AddUntilStep(() => !carousel.PendingFilterTask, "Wait for debounce"); AddUntilStep("Wait for debounce", () => !carousel.PendingFilterTask);
checkVisibleItemCount(diff: false, count: set_count); checkVisibleItemCount(diff: false, count: set_count);
checkVisibleItemCount(diff: true, count: 3); checkVisibleItemCount(diff: true, count: 3);
@ -327,13 +327,13 @@ namespace osu.Game.Tests.Visual
AddStep("Remove first", () => carousel.RemoveBeatmapSet(carousel.BeatmapSets.First())); AddStep("Remove first", () => carousel.RemoveBeatmapSet(carousel.BeatmapSets.First()));
checkSelected(1); checkSelected(1);
AddUntilStep(() => AddUntilStep("Remove all", () =>
{ {
if (!carousel.BeatmapSets.Any()) return true; if (!carousel.BeatmapSets.Any()) return true;
carousel.RemoveBeatmapSet(carousel.BeatmapSets.Last()); carousel.RemoveBeatmapSet(carousel.BeatmapSets.Last());
return false; return false;
}, "Remove all"); });
checkNoSelection(); checkNoSelection();
} }

View File

@ -1,8 +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.Collections.Generic;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
using osuTK; using osuTK;
@ -12,14 +16,145 @@ namespace osu.Game.Tests.Visual
[System.ComponentModel.Description("PlaySongSelect leaderboard/details area")] [System.ComponentModel.Description("PlaySongSelect leaderboard/details area")]
public class TestCaseBeatmapDetailArea : OsuTestCase public class TestCaseBeatmapDetailArea : OsuTestCase
{ {
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(BeatmapDetails) };
public TestCaseBeatmapDetailArea() public TestCaseBeatmapDetailArea()
{ {
Add(new BeatmapDetailArea BeatmapDetailArea detailsArea;
Add(detailsArea = new BeatmapDetailArea
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(550f, 450f), Size = new Vector2(550f, 450f),
}); });
AddStep("all metrics", () => detailsArea.Beatmap = new DummyWorkingBeatmap
{
BeatmapInfo =
{
Version = "All Metrics",
Metadata = new BeatmapMetadata
{
Source = "osu!lazer",
Tags = "this beatmap has all the metrics",
},
BaseDifficulty = new BeatmapDifficulty
{
CircleSize = 7,
DrainRate = 1,
OverallDifficulty = 5.7f,
ApproachRate = 3.5f,
},
StarDifficulty = 5.3f,
Metrics = new BeatmapMetrics
{
Ratings = Enumerable.Range(0, 11),
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6),
},
}
}
);
AddStep("all except source", () => detailsArea.Beatmap = new DummyWorkingBeatmap
{
BeatmapInfo =
{
Version = "All Metrics",
Metadata = new BeatmapMetadata
{
Tags = "this beatmap has all the metrics",
},
BaseDifficulty = new BeatmapDifficulty
{
CircleSize = 7,
DrainRate = 1,
OverallDifficulty = 5.7f,
ApproachRate = 3.5f,
},
StarDifficulty = 5.3f,
Metrics = new BeatmapMetrics
{
Ratings = Enumerable.Range(0, 11),
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6),
},
}
});
AddStep("ratings", () => detailsArea.Beatmap = new DummyWorkingBeatmap
{
BeatmapInfo =
{
Version = "Only Ratings",
Metadata = new BeatmapMetadata
{
Source = "osu!lazer",
Tags = "this beatmap has ratings metrics but not retries or fails",
},
BaseDifficulty = new BeatmapDifficulty
{
CircleSize = 6,
DrainRate = 9,
OverallDifficulty = 6,
ApproachRate = 6,
},
StarDifficulty = 4.8f,
Metrics = new BeatmapMetrics
{
Ratings = Enumerable.Range(0, 11),
},
}
});
AddStep("fails+retries", () => detailsArea.Beatmap = new DummyWorkingBeatmap
{
BeatmapInfo =
{
Version = "Only Retries and Fails",
Metadata = new BeatmapMetadata
{
Source = "osu!lazer",
Tags = "this beatmap has retries and fails but no ratings",
},
BaseDifficulty = new BeatmapDifficulty
{
CircleSize = 3.7f,
DrainRate = 6,
OverallDifficulty = 6,
ApproachRate = 7,
},
StarDifficulty = 2.91f,
Metrics = new BeatmapMetrics
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6),
},
}
});
AddStep("null metrics", () => detailsArea.Beatmap = new DummyWorkingBeatmap
{
BeatmapInfo =
{
Version = "No Metrics",
Metadata = new BeatmapMetadata
{
Source = "osu!lazer",
Tags = "this beatmap has no metrics",
},
BaseDifficulty = new BeatmapDifficulty
{
CircleSize = 5,
DrainRate = 5,
OverallDifficulty = 5.5f,
ApproachRate = 6.5f,
},
StarDifficulty = 1.97f,
}
});
AddStep("null beatmap", () => detailsArea.Beatmap = null);
} }
} }
} }

View File

@ -56,11 +56,11 @@ namespace osu.Game.Tests.Visual
// select part is redundant, but wait for load isn't // select part is redundant, but wait for load isn't
selectBeatmap(Beatmap.Value.Beatmap); selectBeatmap(Beatmap.Value.Beatmap);
AddWaitStep(3); AddWaitStep("wait for select", 3);
AddStep("hide", () => { infoWedge.State = Visibility.Hidden; }); AddStep("hide", () => { infoWedge.State = Visibility.Hidden; });
AddWaitStep(3); AddWaitStep("wait for hide", 3);
AddStep("show", () => { infoWedge.State = Visibility.Visible; }); AddStep("show", () => { infoWedge.State = Visibility.Visible; });
@ -135,7 +135,7 @@ namespace osu.Game.Tests.Visual
infoWedge.Beatmap = Beatmap.Value = b == null ? Beatmap.Default : new TestWorkingBeatmap(b); infoWedge.Beatmap = Beatmap.Value = b == null ? Beatmap.Default : new TestWorkingBeatmap(b);
}); });
AddUntilStep(() => infoWedge.Info != infoBefore, "wait for async load"); AddUntilStep("wait for async load", () => infoWedge.Info != infoBefore);
} }
private IBeatmap createTestBeatmap(RulesetInfo ruleset) private IBeatmap createTestBeatmap(RulesetInfo ruleset)

View File

@ -90,7 +90,7 @@ namespace osu.Game.Tests.Visual
AddStep("set second channel", () => channelTabControl.Current.Value = channelTabControl.Items.Skip(1).First()); AddStep("set second channel", () => channelTabControl.Current.Value = channelTabControl.Items.Skip(1).First());
AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value); AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value);
AddUntilStep(() => AddUntilStep("remove all channels", () =>
{ {
var first = channelTabControl.Items.First(); var first = channelTabControl.Items.First();
if (first.Name == "+") if (first.Name == "+")
@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual
channelTabControl.RemoveChannel(first); channelTabControl.RemoveChannel(first);
return false; return false;
}, "remove all channels"); });
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value); AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
} }

View File

@ -159,7 +159,7 @@ namespace osu.Game.Tests.Visual
Scheduler.AddDelayed(() => newLine.Message = new DummyMessage(completeText ?? text), delay); Scheduler.AddDelayed(() => newLine.Message = new DummyMessage(completeText ?? text), delay);
}); });
AddUntilStep(() => textContainer.All(line => line.Message is DummyMessage), $"wait for msg #{echoCounter}"); AddUntilStep($"wait for msg #{echoCounter}", () => textContainer.All(line => line.Message is DummyMessage));
} }
} }

View File

@ -2,16 +2,31 @@
// 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.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Users;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
public class TestCaseDisclaimer : ScreenTestCase public class TestCaseDisclaimer : ScreenTestCase
{ {
[Cached(typeof(IAPIProvider))]
private readonly DummyAPIAccess api = new DummyAPIAccess();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
LoadScreen(new Disclaimer()); AddStep("load disclaimer", () => LoadScreen(new Disclaimer()));
AddStep("toggle support", () =>
{
api.LocalUser.Value = new User
{
Username = api.LocalUser.Value.Username,
Id = api.LocalUser.Value.Id,
IsSupporter = !api.LocalUser.Value.IsSupporter,
};
});
} }
} }
} }

View File

@ -32,9 +32,9 @@ namespace osu.Game.Tests.Visual
var text = holdForMenuButton.Children.OfType<SpriteText>().First(); var text = holdForMenuButton.Children.OfType<SpriteText>().First();
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(holdForMenuButton)); AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(holdForMenuButton));
AddUntilStep(() => text.IsPresent && !exitAction, "Text visible"); AddUntilStep("Text visible", () => text.IsPresent && !exitAction);
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One)); AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
AddUntilStep(() => !text.IsPresent && !exitAction, "Text is not visible"); AddUntilStep("Text is not visible", () => !text.IsPresent && !exitAction);
AddStep("Trigger exit action", () => AddStep("Trigger exit action", () =>
{ {
@ -47,7 +47,7 @@ namespace osu.Game.Tests.Visual
AddAssert("action not triggered", () => !exitAction); AddAssert("action not triggered", () => !exitAction);
AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left)); AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left));
AddUntilStep(() => exitAction, $"{nameof(holdForMenuButton.Action)} was triggered"); AddUntilStep($"{nameof(holdForMenuButton.Action)} was triggered", () => exitAction);
} }
} }
} }

View File

@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual
AddStep("start confirming", () => overlay.Begin()); AddStep("start confirming", () => overlay.Begin());
AddUntilStep(() => fired, "wait until confirmed"); AddUntilStep("wait until confirmed", () => fired);
} }
private class TestHoldToConfirmOverlay : ExitConfirmOverlay private class TestHoldToConfirmOverlay : ExitConfirmOverlay

View File

@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual
{ {
AddStep("move mouse to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre)); AddStep("move mouse to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre));
AddUntilStep(() => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle, "Wait for all idle"); AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle);
AddStep("nudge mouse", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre + new Vector2(1))); AddStep("nudge mouse", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre + new Vector2(1)));
@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual
AddAssert("check idle", () => !box3.IsIdle); AddAssert("check idle", () => !box3.IsIdle);
AddAssert("check idle", () => !box4.IsIdle); AddAssert("check idle", () => !box4.IsIdle);
AddUntilStep(() => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle, "Wait for all idle"); AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle);
} }
[Test] [Test]
@ -96,13 +96,13 @@ namespace osu.Game.Tests.Visual
AddStep("move mouse", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre)); AddStep("move mouse", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre));
AddAssert("check not idle", () => !box1.IsIdle && !box2.IsIdle && !box3.IsIdle && !box4.IsIdle); AddAssert("check not idle", () => !box1.IsIdle && !box2.IsIdle && !box3.IsIdle && !box4.IsIdle);
AddUntilStep(() => box1.IsIdle, "Wait for idle"); AddUntilStep("Wait for idle", () => box1.IsIdle);
AddAssert("check not idle", () => !box2.IsIdle && !box3.IsIdle && !box4.IsIdle); AddAssert("check not idle", () => !box2.IsIdle && !box3.IsIdle && !box4.IsIdle);
AddUntilStep(() => box2.IsIdle, "Wait for idle"); AddUntilStep("Wait for idle", () => box2.IsIdle);
AddAssert("check not idle", () => !box3.IsIdle && !box4.IsIdle); AddAssert("check not idle", () => !box3.IsIdle && !box4.IsIdle);
AddUntilStep(() => box3.IsIdle, "Wait for idle"); AddUntilStep("Wait for idle", () => box3.IsIdle);
AddUntilStep(() => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle, "Wait for all idle"); AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle);
} }
private class IdleTrackingBox : CompositeDrawable private class IdleTrackingBox : CompositeDrawable

View File

@ -25,30 +25,30 @@ namespace osu.Game.Tests.Visual
bool logoVisible = false; bool logoVisible = false;
AddStep("almost instant display", () => Child = loader = new TestLoader(250)); AddStep("almost instant display", () => Child = loader = new TestLoader(250));
AddUntilStep(() => AddUntilStep("loaded", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; return loader.Logo != null && loader.ScreenLoaded;
}, "loaded"); });
AddAssert("logo not visible", () => !logoVisible); AddAssert("logo not visible", () => !logoVisible);
AddStep("short load", () => Child = loader = new TestLoader(800)); AddStep("short load", () => Child = loader = new TestLoader(800));
AddUntilStep(() => AddUntilStep("loaded", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; return loader.Logo != null && loader.ScreenLoaded;
}, "loaded"); });
AddAssert("logo visible", () => logoVisible); AddAssert("logo visible", () => logoVisible);
AddUntilStep(() => loader.Logo?.Alpha == 0, "logo gone"); AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
AddStep("longer load", () => Child = loader = new TestLoader(1400)); AddStep("longer load", () => Child = loader = new TestLoader(1400));
AddUntilStep(() => AddUntilStep("loaded", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; return loader.Logo != null && loader.ScreenLoaded;
}, "loaded"); });
AddAssert("logo visible", () => logoVisible); AddAssert("logo visible", () => logoVisible);
AddUntilStep(() => loader.Logo?.Alpha == 0, "logo gone"); AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
} }
private class TestLoader : Loader private class TestLoader : Loader

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual
} }
[Resolved] [Resolved]
private APIAccess api { get; set; } private IAPIProvider api { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()

View File

@ -111,7 +111,7 @@ namespace osu.Game.Tests.Visual
settings.ApplyButton.Action.Invoke(); settings.ApplyButton.Action.Invoke();
}); });
AddUntilStep(() => !settings.ErrorText.IsPresent, "error not displayed"); AddUntilStep("error not displayed", () => !settings.ErrorText.IsPresent);
} }
private class TestRoomSettings : MatchSettingsOverlay private class TestRoomSettings : MatchSettingsOverlay

View File

@ -208,22 +208,22 @@ namespace osu.Game.Tests.Visual
{ {
checkLabelColor(Color4.White); checkLabelColor(Color4.White);
selectNext(mod); selectNext(mod);
AddWaitStep(1, "wait for changing colour"); AddWaitStep("wait for changing colour", 1);
checkLabelColor(colour); checkLabelColor(colour);
selectPrevious(mod); selectPrevious(mod);
AddWaitStep(1, "wait for changing colour"); AddWaitStep("wait for changing colour", 1);
checkLabelColor(Color4.White); checkLabelColor(Color4.White);
} }
private void testRankedText(Mod mod) private void testRankedText(Mod mod)
{ {
AddWaitStep(1, "wait for fade"); AddWaitStep("wait for fade", 1);
AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0); AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0);
selectNext(mod); selectNext(mod);
AddWaitStep(1, "wait for fade"); AddWaitStep("wait for fade", 1);
AddAssert("check for unranked", () => modSelect.UnrankedLabel.Alpha != 0); AddAssert("check for unranked", () => modSelect.UnrankedLabel.Alpha != 0);
selectPrevious(mod); selectPrevious(mod);
AddWaitStep(1, "wait for fade"); AddWaitStep("wait for fade", 1);
AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0); AddAssert("check for ranked", () => modSelect.UnrankedLabel.Alpha == 0);
} }

View File

@ -60,7 +60,7 @@ namespace osu.Game.Tests.Visual
setState(Visibility.Hidden); setState(Visibility.Hidden);
AddRepeatStep(@"add many simple", sendManyNotifications, 3); AddRepeatStep(@"add many simple", sendManyNotifications, 3);
AddWaitStep(5); AddWaitStep("wait some", 5);
checkProgressingCount(0); checkProgressingCount(0);
@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual
AddAssert("Displayed count is 33", () => manager.UnreadCount.Value == 33); AddAssert("Displayed count is 33", () => manager.UnreadCount.Value == 33);
AddWaitStep(10); AddWaitStep("wait some", 10);
checkProgressingCount(0); checkProgressingCount(0);

View File

@ -112,10 +112,10 @@ namespace osu.Game.Tests.Visual
createSongSelect(); createSongSelect();
AddAssert("dummy selected", () => songSelect.CurrentBeatmap == defaultBeatmap); AddAssert("dummy selected", () => songSelect.CurrentBeatmap == defaultBeatmap);
AddUntilStep(() => songSelect.CurrentBeatmapDetailsBeatmap == defaultBeatmap, "dummy shown on wedge"); AddUntilStep("dummy shown on wedge", () => songSelect.CurrentBeatmapDetailsBeatmap == defaultBeatmap);
addManyTestMaps(); addManyTestMaps();
AddWaitStep(3); AddWaitStep("wait for select", 3);
AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap); AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap);
} }
@ -125,7 +125,7 @@ namespace osu.Game.Tests.Visual
{ {
createSongSelect(); createSongSelect();
addManyTestMaps(); addManyTestMaps();
AddWaitStep(3); AddWaitStep("wait for add", 3);
AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap); AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap);
@ -142,7 +142,7 @@ namespace osu.Game.Tests.Visual
createSongSelect(); createSongSelect();
changeRuleset(2); changeRuleset(2);
importForRuleset(0); importForRuleset(0);
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap == null, "no selection"); AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmap == null);
} }
[Test] [Test]
@ -152,13 +152,13 @@ namespace osu.Game.Tests.Visual
changeRuleset(2); changeRuleset(2);
importForRuleset(2); importForRuleset(2);
importForRuleset(1); importForRuleset(1);
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap.RulesetID == 2, "has selection"); AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 2);
changeRuleset(1); changeRuleset(1);
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap.RulesetID == 1, "has selection"); AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 1);
changeRuleset(0); changeRuleset(0);
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap == null, "no selection"); AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmap == null);
} }
[Test] [Test]
@ -196,7 +196,7 @@ namespace osu.Game.Tests.Visual
{ {
createSongSelect(); createSongSelect();
addManyTestMaps(); addManyTestMaps();
AddUntilStep(() => songSelect.Carousel.SelectedBeatmap != null, "has selection"); AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap != null);
bool startRequested = false; bool startRequested = false;
@ -225,7 +225,7 @@ namespace osu.Game.Tests.Visual
private void createSongSelect() private void createSongSelect()
{ {
AddStep("create song select", () => LoadScreen(songSelect = new TestSongSelect())); AddStep("create song select", () => LoadScreen(songSelect = new TestSongSelect()));
AddUntilStep(() => songSelect.IsCurrentScreen(), "wait for present"); AddUntilStep("wait for present", () => songSelect.IsCurrentScreen());
} }
private void addManyTestMaps() private void addManyTestMaps()

View File

@ -37,15 +37,15 @@ namespace osu.Game.Tests.Visual
AllowResults = false, AllowResults = false,
}))); })));
AddUntilStep(() => loader.IsCurrentScreen(), "wait for current"); AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre)); AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
AddUntilStep(() => !loader.IsCurrentScreen(), "wait for no longer current"); AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
AddStep("exit loader", () => loader.Exit()); AddStep("exit loader", () => loader.Exit());
AddUntilStep(() => !loader.IsAlive, "wait for no longer alive"); AddUntilStep("wait for no longer alive", () => !loader.IsAlive);
AddStep("load slow dummy beatmap", () => AddStep("load slow dummy beatmap", () =>
{ {
@ -61,7 +61,7 @@ namespace osu.Game.Tests.Visual
Scheduler.AddDelayed(() => slow.Ready = true, 5000); Scheduler.AddDelayed(() => slow.Ready = true, 5000);
}); });
AddUntilStep(() => !loader.IsCurrentScreen(), "wait for no longer current"); AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
} }
protected class SlowLoadPlayer : Player protected class SlowLoadPlayer : Player

View File

@ -0,0 +1,56 @@
// 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.
using System;
using osu.Framework.Lists;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
public class TestCasePlayerReferenceLeaking : AllPlayersTestCase
{
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();
private readonly WeakList<Player> playerWeakReferences = new WeakList<Player>();
protected override void AddCheckSteps()
{
AddUntilStep("no leaked beatmaps", () =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
int count = 0;
workingWeakReferences.ForEachAlive(_ => count++);
return count == 1;
});
AddUntilStep("no leaked players", () =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
int count = 0;
playerWeakReferences.ForEachAlive(_ => count++);
return count == 1;
});
}
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, IFrameBasedClock clock)
{
var working = base.CreateWorkingBeatmap(beatmap, clock);
workingWeakReferences.Add(working);
return working;
}
protected override Player CreatePlayer(Ruleset ruleset)
{
var player = base.CreatePlayer(ruleset);
playerWeakReferences.Add(player);
return player;
}
}
}

View File

@ -1,7 +1,6 @@
// 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;
@ -12,7 +11,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
[Description("Player instantiated with a replay.")] [Description("Player instantiated with a replay.")]
public class TestCaseReplay : TestCasePlayer public class TestCaseReplay : AllPlayersTestCase
{ {
protected override Player CreatePlayer(Ruleset ruleset) protected override Player CreatePlayer(Ruleset ruleset)
{ {
@ -21,11 +20,10 @@ namespace osu.Game.Tests.Visual
return new ScoreAccessibleReplayPlayer(ruleset.GetAutoplayMod().CreateReplayScore(beatmap)); return new ScoreAccessibleReplayPlayer(ruleset.GetAutoplayMod().CreateReplayScore(beatmap));
} }
protected override void AddCheckSteps(Func<Player> player) protected override void AddCheckSteps()
{ {
base.AddCheckSteps(player); AddUntilStep("score above zero", () => ((ScoreAccessibleReplayPlayer)Player).ScoreProcessor.TotalScore.Value > 0);
AddUntilStep(() => ((ScoreAccessibleReplayPlayer)player()).ScoreProcessor.TotalScore.Value > 0, "score above zero"); AddUntilStep("key counter counted keys", () => ((ScoreAccessibleReplayPlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0));
AddUntilStep(() => ((ScoreAccessibleReplayPlayer)player()).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0), "key counter counted keys");
} }
private class ScoreAccessibleReplayPlayer : ReplayPlayer private class ScoreAccessibleReplayPlayer : ReplayPlayer

View File

@ -74,7 +74,7 @@ namespace osu.Game.Tests.Visual
} }
private void pushNext() => AddStep(@"push next screen", () => ((TestScreen)screenStack.CurrentScreen).PushNext()); private void pushNext() => AddStep(@"push next screen", () => ((TestScreen)screenStack.CurrentScreen).PushNext());
private void waitForCurrent() => AddUntilStep(() => screenStack.CurrentScreen.IsCurrentScreen(), "current screen"); private void waitForCurrent() => AddUntilStep("current screen", () => screenStack.CurrentScreen.IsCurrentScreen());
private abstract class TestScreen : OsuScreen private abstract class TestScreen : OsuScreen
{ {

View File

@ -46,23 +46,23 @@ namespace osu.Game.Tests.Visual
Origin = Anchor.TopLeft, Origin = Anchor.TopLeft,
}); });
AddWaitStep(5); AddWaitStep("wait some", 5);
AddAssert("ensure not created", () => graph.CreationCount == 0); AddAssert("ensure not created", () => graph.CreationCount == 0);
AddStep("display values", displayNewValues); AddStep("display values", displayNewValues);
AddWaitStep(5); AddWaitStep("wait some", 5);
AddUntilStep(() => graph.CreationCount == 1, "wait for creation count"); AddUntilStep("wait for creation count", () => graph.CreationCount == 1);
AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking); AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking);
AddWaitStep(5); AddWaitStep("wait some", 5);
AddUntilStep(() => graph.CreationCount == 1, "wait for creation count"); AddUntilStep("wait for creation count", () => graph.CreationCount == 1);
AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking); AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking);
AddWaitStep(5); AddWaitStep("wait some", 5);
AddUntilStep(() => graph.CreationCount == 1, "wait for creation count"); AddUntilStep("wait for creation count", () => graph.CreationCount == 1);
AddRepeatStep("New Values", displayNewValues, 5); AddRepeatStep("New Values", displayNewValues, 5);
AddWaitStep(5); AddWaitStep("wait some", 5);
AddAssert("ensure debounced", () => graph.CreationCount == 2); AddAssert("ensure debounced", () => graph.CreationCount == 2);
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Tests.Visual
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osu, APIAccess api, RulesetStore rulesets) private void load(OsuGameBase osu, IAPIProvider api, RulesetStore rulesets)
{ {
Bindable<BeatmapInfo> beatmapBindable = new Bindable<BeatmapInfo>(); Bindable<BeatmapInfo> beatmapBindable = new Bindable<BeatmapInfo>();
@ -36,18 +36,18 @@ namespace osu.Game.Tests.Visual
api.Queue(req); api.Queue(req);
AddStep("load null beatmap", () => beatmapBindable.Value = null); AddStep("load null beatmap", () => beatmapBindable.Value = null);
AddUntilStep(() => backgroundSprite.ChildCount == 1, "wait for cleanup..."); AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
AddStep("load imported beatmap", () => beatmapBindable.Value = imported.Beatmaps.First()); AddStep("load imported beatmap", () => beatmapBindable.Value = imported.Beatmaps.First());
AddUntilStep(() => backgroundSprite.ChildCount == 1, "wait for cleanup..."); AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
if (api.IsLoggedIn) if (api.IsLoggedIn)
{ {
AddUntilStep(() => req.Result != null, "wait for api response"); AddUntilStep("wait for api response", () => req.Result != null);
AddStep("load online beatmap", () => beatmapBindable.Value = new BeatmapInfo AddStep("load online beatmap", () => beatmapBindable.Value = new BeatmapInfo
{ {
BeatmapSet = req.Result?.ToBeatmapSet(rulesets) BeatmapSet = req.Result?.ToBeatmapSet(rulesets)
}); });
AddUntilStep(() => backgroundSprite.ChildCount == 1, "wait for cleanup..."); AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
} }
else else
{ {

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual
public class TestCaseUserProfile : OsuTestCase public class TestCaseUserProfile : OsuTestCase
{ {
private readonly TestUserProfileOverlay profile; private readonly TestUserProfileOverlay profile;
private APIAccess api; private IAPIProvider api;
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
{ {
@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api) private void load(IAPIProvider api)
{ {
this.api = api; this.api = api;
} }
@ -108,7 +108,7 @@ namespace osu.Game.Tests.Visual
private void checkSupporterTag(bool isSupporter) private void checkSupporterTag(bool isSupporter)
{ {
AddUntilStep(() => profile.Header.User != null, "wait for load"); AddUntilStep("wait for load", () => profile.Header.User != null);
if (isSupporter) if (isSupporter)
AddAssert("is supporter", () => profile.Header.SupporterTag.Alpha == 1); AddAssert("is supporter", () => profile.Header.SupporterTag.Alpha == 1);
else else

View File

@ -64,7 +64,7 @@ namespace osu.Game.Beatmaps
private readonly BeatmapStore beatmaps; private readonly BeatmapStore beatmaps;
private readonly APIAccess api; private readonly IAPIProvider api;
private readonly AudioManager audioManager; private readonly AudioManager audioManager;
@ -72,7 +72,7 @@ namespace osu.Game.Beatmaps
private readonly List<DownloadBeatmapSetRequest> currentDownloads = new List<DownloadBeatmapSetRequest>(); private readonly List<DownloadBeatmapSetRequest> currentDownloads = new List<DownloadBeatmapSetRequest>();
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, AudioManager audioManager, GameHost host = null, public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, AudioManager audioManager, GameHost host = null,
WorkingBeatmap defaultBeatmap = null) WorkingBeatmap defaultBeatmap = null)
: base(storage, contextFactory, new BeatmapStore(contextFactory), host) : base(storage, contextFactory, new BeatmapStore(contextFactory), host)
{ {
@ -102,10 +102,16 @@ namespace osu.Game.Beatmaps
b.BeatmapSet = beatmapSet; b.BeatmapSet = beatmapSet;
} }
validateOnlineIds(beatmapSet.Beatmaps); validateOnlineIds(beatmapSet);
foreach (BeatmapInfo b in beatmapSet.Beatmaps) foreach (BeatmapInfo b in beatmapSet.Beatmaps)
fetchAndPopulateOnlineValues(b, beatmapSet.Beatmaps); fetchAndPopulateOnlineValues(b);
}
protected override void PreImport(BeatmapSetInfo beatmapSet)
{
if (beatmapSet.Beatmaps.Any(b => b.BaseDifficulty == null))
throw new InvalidOperationException($"Cannot import {nameof(BeatmapInfo)} with null {nameof(BeatmapInfo.BaseDifficulty)}.");
// check if a set already exists with the same online id, delete if it does. // check if a set already exists with the same online id, delete if it does.
if (beatmapSet.OnlineBeatmapSetID != null) if (beatmapSet.OnlineBeatmapSetID != null)
@ -120,14 +126,30 @@ namespace osu.Game.Beatmaps
} }
} }
private void validateOnlineIds(List<BeatmapInfo> beatmaps) private void validateOnlineIds(BeatmapSetInfo beatmapSet)
{ {
var beatmapIds = beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList(); var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList();
// ensure all IDs are unique in this set and none match existing IDs in the local beatmap store. // ensure all IDs are unique
if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1) || QueryBeatmaps(b => beatmapIds.Contains(b.OnlineBeatmapID)).Any()) if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1))
// remove all online IDs if any problems were found. {
beatmaps.ForEach(b => b.OnlineBeatmapID = null); resetIds();
return;
}
// find any existing beatmaps in the database that have matching online ids
var existingBeatmaps = QueryBeatmaps(b => beatmapIds.Contains(b.OnlineBeatmapID)).ToList();
if (existingBeatmaps.Count > 0)
{
// reset the import ids (to force a re-fetch) *unless* they match the candidate CheckForExisting set.
// we can ignore the case where the new ids are contained by the CheckForExisting set as it will either be used (import skipped) or deleted.
var existing = CheckForExisting(beatmapSet);
if (existing == null || existingBeatmaps.Any(b => !existing.Beatmaps.Contains(b)))
resetIds();
}
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
} }
/// <summary> /// <summary>
@ -254,6 +276,18 @@ namespace osu.Game.Beatmaps
/// <returns>The first result for the provided query, or null if no results were found.</returns> /// <returns>The first result for the provided query, or null if no results were found.</returns>
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query); public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query);
protected override bool CanUndelete(BeatmapSetInfo existing, BeatmapSetInfo import)
{
if (!base.CanUndelete(existing, import))
return false;
var existingIds = existing.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
var importIds = import.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
// force re-import if we are not in a sane state.
return existing.OnlineBeatmapSetID == import.OnlineBeatmapSetID && existingIds.SequenceEqual(importIds);
}
/// <summary> /// <summary>
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s. /// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
/// </summary> /// </summary>
@ -351,7 +385,7 @@ namespace osu.Game.Beatmaps
/// <param name="otherBeatmaps">The other beatmaps contained within this set.</param> /// <param name="otherBeatmaps">The other beatmaps contained within this set.</param>
/// <param name="force">Whether to re-query if the provided beatmap already has populated values.</param> /// <param name="force">Whether to re-query if the provided beatmap already has populated values.</param>
/// <returns>True if population was successful.</returns> /// <returns>True if population was successful.</returns>
private bool fetchAndPopulateOnlineValues(BeatmapInfo beatmap, IEnumerable<BeatmapInfo> otherBeatmaps, bool force = false) private bool fetchAndPopulateOnlineValues(BeatmapInfo beatmap, bool force = false)
{ {
if (api?.State != APIState.Online) if (api?.State != APIState.Online)
return false; return false;
@ -374,13 +408,6 @@ namespace osu.Game.Beatmaps
beatmap.Status = res.Status; beatmap.Status = res.Status;
beatmap.BeatmapSet.Status = res.BeatmapSet.Status; beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
if (otherBeatmaps.Any(b => b.OnlineBeatmapID == res.OnlineBeatmapID))
{
Logger.Log("Another beatmap in the same set already mapped to this ID. We'll skip adding it this time.", LoggingTarget.Database);
return false;
}
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID; beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
beatmap.OnlineBeatmapID = res.OnlineBeatmapID; beatmap.OnlineBeatmapID = res.OnlineBeatmapID;

View File

@ -45,32 +45,26 @@ namespace osu.Game.Beatmaps.Drawables
protected override Drawable CreateDrawable(BeatmapInfo model) protected override Drawable CreateDrawable(BeatmapInfo model)
{ {
Drawable drawable; Drawable drawable = getDrawableForModel(model);
var localBeatmap = beatmaps.GetWorkingBeatmap(model);
if (model?.BeatmapSet?.OnlineInfo != null)
{
drawable = new BeatmapSetCover(model.BeatmapSet, beatmapSetCoverType);
}
else if (localBeatmap.BeatmapInfo.ID != 0)
{
// Fall back to local background if one exists
drawable = new BeatmapBackgroundSprite(localBeatmap);
}
else
{
// Use the default background if somehow an online set does not exist and we don't have a local copy.
drawable = new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
}
drawable.RelativeSizeAxes = Axes.Both; drawable.RelativeSizeAxes = Axes.Both;
drawable.Anchor = Anchor.Centre; drawable.Anchor = Anchor.Centre;
drawable.Origin = Anchor.Centre; drawable.Origin = Anchor.Centre;
drawable.FillMode = FillMode.Fill; drawable.FillMode = FillMode.Fill;
drawable.OnLoadComplete = d => d.FadeInFromZero(400); drawable.OnLoadComplete += d => d.FadeInFromZero(400);
return drawable; return drawable;
} }
private Drawable getDrawableForModel(BeatmapInfo model)
{
// prefer online cover where available.
if (model?.BeatmapSet?.OnlineInfo != null)
return new BeatmapSetCover(model.BeatmapSet, beatmapSetCoverType);
return model?.ID > 0
? new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(model))
: new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
}
} }
} }

View File

@ -67,16 +67,19 @@ namespace osu.Game.Beatmaps.Drawables
if (beatmapSet != null) if (beatmapSet != null)
{ {
BeatmapSetCover cover;
Add(displayedCover = new DelayedLoadWrapper( Add(displayedCover = new DelayedLoadWrapper(
new BeatmapSetCover(beatmapSet, coverType) cover = new BeatmapSetCover(beatmapSet, coverType)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
}) })
); );
cover.OnLoadComplete += d => d.FadeInFromZero(400, Easing.Out);
} }
} }
} }

View File

@ -26,7 +26,12 @@ namespace osu.Game.Beatmaps
Title = "no beatmaps available!" Title = "no beatmaps available!"
}, },
BeatmapSet = new BeatmapSetInfo(), BeatmapSet = new BeatmapSetInfo(),
BaseDifficulty = new BeatmapDifficulty(), BaseDifficulty = new BeatmapDifficulty
{
DrainRate = 0,
CircleSize = 0,
OverallDifficulty = 0,
},
Ruleset = new DummyRulesetInfo() Ruleset = new DummyRulesetInfo()
}) })
{ {
@ -47,7 +52,7 @@ namespace osu.Game.Beatmaps
{ {
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[] { }; public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[] { };
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap) public override DrawableRuleset CreateDrawableRulesetWith(WorkingBeatmap beatmap)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -2,10 +2,10 @@
// 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;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using osu.Framework.IO.File; using osu.Framework.IO.File;
using osu.Framework.Logging;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -25,7 +25,7 @@ namespace osu.Game.Beatmaps.Formats
public static void Register() public static void Register()
{ {
AddDecoder<Beatmap>(@"osu file format v", m => new LegacyBeatmapDecoder(int.Parse(m.Split('v').Last()))); AddDecoder<Beatmap>(@"osu file format v", m => new LegacyBeatmapDecoder(Parsing.ParseInt(m.Split('v').Last())));
} }
/// <summary> /// <summary>
@ -104,25 +104,25 @@ namespace osu.Game.Beatmaps.Formats
metadata.AudioFile = FileSafety.PathStandardise(pair.Value); metadata.AudioFile = FileSafety.PathStandardise(pair.Value);
break; break;
case @"AudioLeadIn": case @"AudioLeadIn":
beatmap.BeatmapInfo.AudioLeadIn = int.Parse(pair.Value); beatmap.BeatmapInfo.AudioLeadIn = Parsing.ParseInt(pair.Value);
break; break;
case @"PreviewTime": case @"PreviewTime":
metadata.PreviewTime = getOffsetTime(int.Parse(pair.Value)); metadata.PreviewTime = getOffsetTime(Parsing.ParseInt(pair.Value));
break; break;
case @"Countdown": case @"Countdown":
beatmap.BeatmapInfo.Countdown = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.Countdown = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"SampleSet": case @"SampleSet":
defaultSampleBank = (LegacySampleBank)Enum.Parse(typeof(LegacySampleBank), pair.Value); defaultSampleBank = (LegacySampleBank)Enum.Parse(typeof(LegacySampleBank), pair.Value);
break; break;
case @"SampleVolume": case @"SampleVolume":
defaultSampleVolume = int.Parse(pair.Value); defaultSampleVolume = Parsing.ParseInt(pair.Value);
break; break;
case @"StackLeniency": case @"StackLeniency":
beatmap.BeatmapInfo.StackLeniency = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.StackLeniency = Parsing.ParseFloat(pair.Value);
break; break;
case @"Mode": case @"Mode":
beatmap.BeatmapInfo.RulesetID = int.Parse(pair.Value); beatmap.BeatmapInfo.RulesetID = Parsing.ParseInt(pair.Value);
switch (beatmap.BeatmapInfo.RulesetID) switch (beatmap.BeatmapInfo.RulesetID)
{ {
@ -142,13 +142,13 @@ namespace osu.Game.Beatmaps.Formats
break; break;
case @"LetterboxInBreaks": case @"LetterboxInBreaks":
beatmap.BeatmapInfo.LetterboxInBreaks = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.LetterboxInBreaks = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"SpecialStyle": case @"SpecialStyle":
beatmap.BeatmapInfo.SpecialStyle = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.SpecialStyle = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"WidescreenStoryboard": case @"WidescreenStoryboard":
beatmap.BeatmapInfo.WidescreenStoryboard = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.WidescreenStoryboard = Parsing.ParseInt(pair.Value) == 1;
break; break;
} }
} }
@ -163,16 +163,16 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.StoredBookmarks = pair.Value; beatmap.BeatmapInfo.StoredBookmarks = pair.Value;
break; break;
case @"DistanceSpacing": case @"DistanceSpacing":
beatmap.BeatmapInfo.DistanceSpacing = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.DistanceSpacing = Math.Max(0, Parsing.ParseDouble(pair.Value));
break; break;
case @"BeatDivisor": case @"BeatDivisor":
beatmap.BeatmapInfo.BeatDivisor = int.Parse(pair.Value); beatmap.BeatmapInfo.BeatDivisor = Parsing.ParseInt(pair.Value);
break; break;
case @"GridSize": case @"GridSize":
beatmap.BeatmapInfo.GridSize = int.Parse(pair.Value); beatmap.BeatmapInfo.GridSize = Parsing.ParseInt(pair.Value);
break; break;
case @"TimelineZoom": case @"TimelineZoom":
beatmap.BeatmapInfo.TimelineZoom = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.TimelineZoom = Math.Max(0, Parsing.ParseDouble(pair.Value));
break; break;
} }
} }
@ -209,10 +209,10 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.Metadata.Tags = pair.Value; beatmap.BeatmapInfo.Metadata.Tags = pair.Value;
break; break;
case @"BeatmapID": case @"BeatmapID":
beatmap.BeatmapInfo.OnlineBeatmapID = int.Parse(pair.Value); beatmap.BeatmapInfo.OnlineBeatmapID = Parsing.ParseInt(pair.Value);
break; break;
case @"BeatmapSetID": case @"BeatmapSetID":
beatmap.BeatmapInfo.BeatmapSet = new BeatmapSetInfo { OnlineBeatmapSetID = int.Parse(pair.Value) }; beatmap.BeatmapInfo.BeatmapSet = new BeatmapSetInfo { OnlineBeatmapSetID = Parsing.ParseInt(pair.Value) };
break; break;
} }
} }
@ -225,22 +225,22 @@ namespace osu.Game.Beatmaps.Formats
switch (pair.Key) switch (pair.Key)
{ {
case @"HPDrainRate": case @"HPDrainRate":
difficulty.DrainRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.DrainRate = Parsing.ParseFloat(pair.Value);
break; break;
case @"CircleSize": case @"CircleSize":
difficulty.CircleSize = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.CircleSize = Parsing.ParseFloat(pair.Value);
break; break;
case @"OverallDifficulty": case @"OverallDifficulty":
difficulty.OverallDifficulty = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.OverallDifficulty = Parsing.ParseFloat(pair.Value);
break; break;
case @"ApproachRate": case @"ApproachRate":
difficulty.ApproachRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.ApproachRate = Parsing.ParseFloat(pair.Value);
break; break;
case @"SliderMultiplier": case @"SliderMultiplier":
difficulty.SliderMultiplier = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.SliderMultiplier = Parsing.ParseDouble(pair.Value);
break; break;
case @"SliderTickRate": case @"SliderTickRate":
difficulty.SliderTickRate = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.SliderTickRate = Parsing.ParseDouble(pair.Value);
break; break;
} }
} }
@ -260,10 +260,12 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.Metadata.BackgroundFile = FileSafety.PathStandardise(filename); beatmap.BeatmapInfo.Metadata.BackgroundFile = FileSafety.PathStandardise(filename);
break; break;
case EventType.Break: case EventType.Break:
double start = getOffsetTime(Parsing.ParseDouble(split[1]));
var breakEvent = new BreakPeriod var breakEvent = new BreakPeriod
{ {
StartTime = getOffsetTime(double.Parse(split[1], NumberFormatInfo.InvariantInfo)), StartTime = start,
EndTime = getOffsetTime(double.Parse(split[2], NumberFormatInfo.InvariantInfo)) EndTime = Math.Max(start, getOffsetTime(Parsing.ParseDouble(split[2])))
}; };
if (!breakEvent.HasEffect) if (!breakEvent.HasEffect)
@ -280,25 +282,25 @@ namespace osu.Game.Beatmaps.Formats
{ {
string[] split = line.Split(','); string[] split = line.Split(',');
double time = getOffsetTime(double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo)); double time = getOffsetTime(Parsing.ParseDouble(split[0].Trim()));
double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo); double beatLength = Parsing.ParseDouble(split[1].Trim());
double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1; double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;
TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple; TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
if (split.Length >= 3) if (split.Length >= 3)
timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]); timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)Parsing.ParseInt(split[2]);
LegacySampleBank sampleSet = defaultSampleBank; LegacySampleBank sampleSet = defaultSampleBank;
if (split.Length >= 4) if (split.Length >= 4)
sampleSet = (LegacySampleBank)int.Parse(split[3]); sampleSet = (LegacySampleBank)Parsing.ParseInt(split[3]);
int customSampleBank = 0; int customSampleBank = 0;
if (split.Length >= 5) if (split.Length >= 5)
customSampleBank = int.Parse(split[4]); customSampleBank = Parsing.ParseInt(split[4]);
int sampleVolume = defaultSampleVolume; int sampleVolume = defaultSampleVolume;
if (split.Length >= 6) if (split.Length >= 6)
sampleVolume = int.Parse(split[5]); sampleVolume = Parsing.ParseInt(split[5]);
bool timingChange = true; bool timingChange = true;
if (split.Length >= 7) if (split.Length >= 7)
@ -308,7 +310,7 @@ namespace osu.Game.Beatmaps.Formats
bool omitFirstBarSignature = false; bool omitFirstBarSignature = false;
if (split.Length >= 8) if (split.Length >= 8)
{ {
EffectFlags effectFlags = (EffectFlags)int.Parse(split[7]); EffectFlags effectFlags = (EffectFlags)Parsing.ParseInt(split[7]);
kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai); kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine); omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
} }
@ -348,8 +350,13 @@ namespace osu.Game.Beatmaps.Formats
CustomSampleBank = customSampleBank CustomSampleBank = customSampleBank
}); });
} }
catch (FormatException e) catch (FormatException)
{ {
Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
catch (OverflowException)
{
Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
} }
} }

View File

@ -0,0 +1,52 @@
// 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.
using System;
using System.Globalization;
namespace osu.Game.Beatmaps.Formats
{
/// <summary>
/// Helper methods to parse from string to number and perform very basic validation.
/// </summary>
public static class Parsing
{
public const int MAX_COORDINATE_VALUE = 65536;
public const double MAX_PARSE_VALUE = int.MaxValue;
public static float ParseFloat(string input, float parseLimit = (float)MAX_PARSE_VALUE)
{
var output = float.Parse(input, CultureInfo.InvariantCulture);
if (output < -parseLimit) throw new OverflowException("Value is too low");
if (output > parseLimit) throw new OverflowException("Value is too high");
if (float.IsNaN(output)) throw new FormatException("Not a number");
return output;
}
public static double ParseDouble(string input, double parseLimit = MAX_PARSE_VALUE)
{
var output = double.Parse(input, CultureInfo.InvariantCulture);
if (output < -parseLimit) throw new OverflowException("Value is too low");
if (output > parseLimit) throw new OverflowException("Value is too high");
if (double.IsNaN(output)) throw new FormatException("Not a number");
return output;
}
public static int ParseInt(string input, int parseLimit = (int)MAX_PARSE_VALUE)
{
var output = int.Parse(input, CultureInfo.InvariantCulture);
if (output < -parseLimit) throw new OverflowException("Value is too low");
if (output > parseLimit) throw new OverflowException("Value is too high");
return output;
}
}
}

View File

@ -300,20 +300,30 @@ namespace osu.Game.Database
{ {
if (!write.IsTransactionLeader) throw new InvalidOperationException($"Ensure there is no parent transaction so errors can correctly be handled by {this}"); if (!write.IsTransactionLeader) throw new InvalidOperationException($"Ensure there is no parent transaction so errors can correctly be handled by {this}");
if (archive != null)
item.Files = createFileInfos(archive, Files);
Populate(item, archive);
var existing = CheckForExisting(item); var existing = CheckForExisting(item);
if (existing != null) if (existing != null)
{
if (CanUndelete(existing, item))
{ {
Undelete(existing); Undelete(existing);
Logger.Log($"Found existing {typeof(TModel)} for {item} (ID {existing.ID}). Skipping import.", LoggingTarget.Database); Logger.Log($"Found existing {typeof(TModel)} for {item} (ID {existing.ID}). Skipping import.", LoggingTarget.Database);
handleEvent(() => ItemAdded?.Invoke(existing, true)); handleEvent(() => ItemAdded?.Invoke(existing, true));
return existing; return existing;
} }
else
{
Delete(existing);
ModelStore.PurgeDeletable(s => s.ID == existing.ID);
}
}
if (archive != null) PreImport(item);
item.Files = createFileInfos(archive, Files);
Populate(item, archive);
// import to store // import to store
ModelStore.Add(item); ModelStore.Add(item);
@ -542,12 +552,29 @@ namespace osu.Game.Database
{ {
} }
/// <summary>
/// Perform any final actions before the import to database executes.
/// </summary>
/// <param name="model">The model prepared for import.</param>
protected virtual void PreImport(TModel model)
{
}
/// <summary> /// <summary>
/// Check whether an existing model already exists for a new import item. /// Check whether an existing model already exists for a new import item.
/// </summary> /// </summary>
/// <param name="model">The new model proposed for import. Note that <see cref="Populate"/> has not yet been run on this model.</param> /// <param name="model">The new model proposed for import.
/// <returns>An existing model which matches the criteria to skip importing, else null.</returns> /// <returns>An existing model which matches the criteria to skip importing, else null.</returns>
protected virtual TModel CheckForExisting(TModel model) => model.Hash == null ? null : ModelStore.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash); protected TModel CheckForExisting(TModel model) => model.Hash == null ? null : ModelStore.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
/// <summary>
/// After an existing <see cref="TModel"/> is found during an import process, the default behaviour is to restore the existing
/// item and skip the import. This method allows changing that behaviour.
/// </summary>
/// <param name="existing">The existing model.</param>
/// <param name="import">The newly imported model.</param>
/// <returns>Whether the existing model should be restored and used. Returning false will delete the existing a force a re-import.</returns>
protected virtual bool CanUndelete(TModel existing, TModel import) => true;
private DbSet<TModel> queryModel() => ContextFactory.Get().Set<TModel>(); private DbSet<TModel> queryModel() => ContextFactory.Get().Set<TModel>();

View File

@ -13,7 +13,6 @@ namespace osu.Game.Migrations
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
} }
} }
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Online.API
private readonly OsuConfigManager config; private readonly OsuConfigManager config;
private readonly OAuth authentication; private readonly OAuth authentication;
public string Endpoint = @"https://osu.ppy.sh"; public string Endpoint => @"https://osu.ppy.sh";
private const string client_id = @"5"; private const string client_id = @"5";
private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk"; private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";

View File

@ -61,9 +61,12 @@ namespace osu.Game.Online.API
private Action pendingFailure; private Action pendingFailure;
public void Perform(APIAccess api) public void Perform(IAPIProvider api)
{ {
API = api; if (!(api is APIAccess apiAccess))
throw new NotSupportedException($"A {nameof(APIAccess)} is required to perform requests.");
API = apiAccess;
if (checkAndScheduleFailure()) if (checkAndScheduleFailure())
return; return;
@ -71,7 +74,7 @@ namespace osu.Game.Online.API
WebRequest = CreateWebRequest(); WebRequest = CreateWebRequest();
WebRequest.Failed += Fail; WebRequest.Failed += Fail;
WebRequest.AllowRetryOnTimeout = false; WebRequest.AllowRetryOnTimeout = false;
WebRequest.AddHeader("Authorization", $"Bearer {api.AccessToken}"); WebRequest.AddHeader("Authorization", $"Bearer {API.AccessToken}");
if (checkAndScheduleFailure()) if (checkAndScheduleFailure())
return; return;
@ -85,7 +88,7 @@ namespace osu.Game.Online.API
if (checkAndScheduleFailure()) if (checkAndScheduleFailure())
return; return;
api.Schedule(delegate { Success?.Invoke(); }); API.Schedule(delegate { Success?.Invoke(); });
} }
public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled")); public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled"));

View File

@ -11,14 +11,16 @@ namespace osu.Game.Online.API
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
{ {
Username = @"Dummy", Username = @"Dummy",
Id = 1, Id = 1001,
}); });
public bool IsLoggedIn => true; public bool IsLoggedIn => true;
public void Update() public string ProvidedUsername => LocalUser.Value.Username;
{
} public string Endpoint => "http://localhost";
public APIState State => LocalUser.Value.Id == 1 ? APIState.Offline : APIState.Online;
public virtual void Queue(APIRequest request) public virtual void Queue(APIRequest request)
{ {
@ -26,6 +28,28 @@ namespace osu.Game.Online.API
public void Register(IOnlineComponent component) public void Register(IOnlineComponent component)
{ {
} // todo: add support
}
public void Unregister(IOnlineComponent component)
{
// todo: add support
}
public void Login(string username, string password)
{
LocalUser.Value = new User
{
Username = @"Dummy",
Id = 1001,
};
}
public void Logout()
{
LocalUser.Value = new GuestUser();
}
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) => null;
} }
} }

View File

@ -18,6 +18,19 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
bool IsLoggedIn { get; } bool IsLoggedIn { get; }
/// <summary>
/// The last username provided by the end-user.
/// May not be authenticated.
/// </summary>
string ProvidedUsername { get; }
/// <summary>
/// The URL endpoint for this API. Does not include a trailing slash.
/// </summary>
string Endpoint { get; }
APIState State { get; }
/// <summary> /// <summary>
/// Queue a new request. /// Queue a new request.
/// </summary> /// </summary>
@ -29,5 +42,32 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
/// <param name="component">The component to register.</param> /// <param name="component">The component to register.</param>
void Register(IOnlineComponent component); void Register(IOnlineComponent component);
/// <summary>
/// Unregisters a component to receive state changes.
/// </summary>
/// <param name="component">The component to unregister.</param>
void Unregister(IOnlineComponent component);
/// <summary>
/// Attempt to login using the provided credentials. This is a non-blocking operation.
/// </summary>
/// <param name="username">The user's username.</param>
/// <param name="password">The user's password.</param>
void Login(string username, string password);
/// <summary>
/// Log out the current user.
/// </summary>
void Logout();
/// <summary>
/// Create a new user account. This is a blocking operation.
/// </summary>
/// <param name="email">The email to create the account with.</param>
/// <param name="username">The username to create the account with.</param>
/// <param name="password">The password to create the account with.</param>
/// <returns>Any errors encoutnered during account creation.</returns>
RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password);
} }
} }

View File

@ -5,6 +5,6 @@ namespace osu.Game.Online.API
{ {
public interface IOnlineComponent public interface IOnlineComponent
{ {
void APIStateChanged(APIAccess api, APIState state); void APIStateChanged(IAPIProvider api, APIState state);
} }
} }

View File

@ -174,12 +174,12 @@ namespace osu.Game.Online.Leaderboards
}; };
} }
private APIAccess api; private IAPIProvider api;
private ScheduledDelegate pendingUpdateScores; private ScheduledDelegate pendingUpdateScores;
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(APIAccess api) private void load(IAPIProvider api)
{ {
this.api = api; this.api = api;
api?.Register(this); api?.Register(this);
@ -195,7 +195,7 @@ namespace osu.Game.Online.Leaderboards
private APIRequest getScoresRequest; private APIRequest getScoresRequest;
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state)
{ {
if (state == APIState.Online) if (state == APIState.Online)
UpdateScores(); UpdateScores();

View File

@ -64,6 +64,8 @@ namespace osu.Game.Online.Leaderboards
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
Avatar innerAvatar;
Children = new Drawable[] Children = new Drawable[]
{ {
new Container new Container
@ -109,12 +111,11 @@ namespace osu.Game.Online.Leaderboards
Children = new[] Children = new[]
{ {
avatar = new DelayedLoadWrapper( avatar = new DelayedLoadWrapper(
new Avatar(user) innerAvatar = new Avatar(user)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius, CornerRadius = corner_radius,
Masking = true, Masking = true,
OnLoadComplete = d => d.FadeInFromZero(200),
EdgeEffect = new EdgeEffectParameters EdgeEffect = new EdgeEffectParameters
{ {
Type = EdgeEffectType.Shadow, Type = EdgeEffectType.Shadow,
@ -214,6 +215,8 @@ namespace osu.Game.Online.Leaderboards
}, },
}, },
}; };
innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200);
} }
public override void Show() public override void Show()

View File

@ -152,7 +152,6 @@ namespace osu.Game
API = new APIAccess(LocalConfig); API = new APIAccess(LocalConfig);
dependencies.Cache(API);
dependencies.CacheAs<IAPIProvider>(API); dependencies.CacheAs<IAPIProvider>(API);
var defaultBeatmap = new DummyWorkingBeatmap(this); var defaultBeatmap = new DummyWorkingBeatmap(this);

View File

@ -33,7 +33,7 @@ namespace osu.Game.Overlays.AccountCreation
private OsuTextBox emailTextBox; private OsuTextBox emailTextBox;
private OsuPasswordTextBox passwordTextBox; private OsuPasswordTextBox passwordTextBox;
private APIAccess api; private IAPIProvider api;
private ShakeContainer registerShake; private ShakeContainer registerShake;
private IEnumerable<Drawable> characterCheckText; private IEnumerable<Drawable> characterCheckText;
@ -42,7 +42,7 @@ namespace osu.Game.Overlays.AccountCreation
private GameHost host; private GameHost host;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api, GameHost host) private void load(OsuColour colours, IAPIProvider api, GameHost host)
{ {
this.api = api; this.api = api;
this.host = host; this.host = host;

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.AccountCreation
{ {
private OsuTextFlowContainer multiAccountExplanationText; private OsuTextFlowContainer multiAccountExplanationText;
private LinkFlowContainer furtherAssistance; private LinkFlowContainer furtherAssistance;
private APIAccess api; private IAPIProvider api;
private const string help_centre_url = "/help/wiki/Help_Centre#login"; private const string help_centre_url = "/help/wiki/Help_Centre#login";
@ -39,7 +39,7 @@ namespace osu.Game.Overlays.AccountCreation
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuColour colours, APIAccess api, OsuGame game, TextureStore textures) private void load(OsuColour colours, IAPIProvider api, OsuGame game, TextureStore textures)
{ {
this.api = api; this.api = api;

View File

@ -30,7 +30,7 @@ namespace osu.Game.Overlays
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api) private void load(OsuColour colours, IAPIProvider api)
{ {
api.Register(this); api.Register(this);
@ -96,7 +96,7 @@ namespace osu.Game.Overlays
this.FadeOut(100); this.FadeOut(100);
} }
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state)
{ {
switch (state) switch (state)
{ {

View File

@ -39,7 +39,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api, BeatmapManager beatmaps) private void load(IAPIProvider api, BeatmapManager beatmaps)
{ {
FillFlowContainer textSprites; FillFlowContainer textSprites;

View File

@ -31,7 +31,7 @@ namespace osu.Game.Overlays
private readonly Header header; private readonly Header header;
private APIAccess api; private IAPIProvider api;
private RulesetStore rulesets; private RulesetStore rulesets;
private readonly ScrollContainer scroll; private readonly ScrollContainer scroll;
@ -101,7 +101,7 @@ namespace osu.Game.Overlays
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets) private void load(IAPIProvider api, RulesetStore rulesets)
{ {
this.api = api; this.api = api;
this.rulesets = rulesets; this.rulesets = rulesets;

View File

@ -28,6 +28,8 @@ namespace osu.Game.Overlays.Chat.Tabs
if (value.Type != ChannelType.PM) if (value.Type != ChannelType.PM)
throw new ArgumentException("Argument value needs to have the targettype user!"); throw new ArgumentException("Argument value needs to have the targettype user!");
Avatar avatar;
AddRange(new Drawable[] AddRange(new Drawable[]
{ {
new Container new Container
@ -49,11 +51,10 @@ namespace osu.Game.Overlays.Chat.Tabs
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Masking = true, Masking = true,
Child = new DelayedLoadWrapper(new Avatar(value.Users.First()) Child = new DelayedLoadWrapper(avatar = new Avatar(value.Users.First())
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
OpenOnClick = { Value = false }, OpenOnClick = { Value = false },
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
}) })
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -63,6 +64,8 @@ namespace osu.Game.Overlays.Chat.Tabs
}, },
}); });
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
Text.X = ChatOverlay.TAB_AREA_HEIGHT; Text.X = ChatOverlay.TAB_AREA_HEIGHT;
TextBold.X = ChatOverlay.TAB_AREA_HEIGHT; TextBold.X = ChatOverlay.TAB_AREA_HEIGHT;
} }

View File

@ -320,6 +320,8 @@ namespace osu.Game.Overlays
this.MoveToY(Height, transition_length, Easing.InSine); this.MoveToY(Height, transition_length, Easing.InSine);
this.FadeOut(transition_length, Easing.InSine); this.FadeOut(transition_length, Easing.InSine);
channelSelectionOverlay.State = Visibility.Hidden;
textbox.HoldFocus = false; textbox.HoldFocus = false;
base.PopOut(); base.PopOut();
} }

View File

@ -185,10 +185,7 @@ namespace osu.Game.Overlays.Direct
Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding },
Children = new[] Children = new[]
{ {
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0) new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0),
{
Margin = new MarginPadding { Right = 1 },
},
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0), new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
}, },
}, },

View File

@ -160,10 +160,7 @@ namespace osu.Game.Overlays.Direct
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0) new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0),
{
Margin = new MarginPadding { Right = 1 },
},
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0), new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
new FillFlowContainer new FillFlowContainer
{ {

View File

@ -28,7 +28,7 @@ namespace osu.Game.Overlays
{ {
private const float panel_padding = 10f; private const float panel_padding = 10f;
private APIAccess api; private IAPIProvider api;
private RulesetStore rulesets; private RulesetStore rulesets;
private readonly FillFlowContainer resultCountsContainer; private readonly FillFlowContainer resultCountsContainer;
@ -134,9 +134,9 @@ namespace osu.Game.Overlays
Filter.Tabs.Current.Value = DirectSortCriteria.Ranked; Filter.Tabs.Current.Value = DirectSortCriteria.Ranked;
} }
}; };
((FilterControl)Filter).Ruleset.ValueChanged += _ => Scheduler.AddOnce(updateSearch); ((FilterControl)Filter).Ruleset.ValueChanged += _ => queueUpdateSearch();
Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += style => recreatePanels(style.NewValue);
Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => Scheduler.AddOnce(updateSearch); Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += _ => queueUpdateSearch();
Header.Tabs.Current.ValueChanged += tab => Header.Tabs.Current.ValueChanged += tab =>
{ {
@ -144,24 +144,11 @@ namespace osu.Game.Overlays
{ {
currentQuery.Value = string.Empty; currentQuery.Value = string.Empty;
Filter.Tabs.Current.Value = (DirectSortCriteria)Header.Tabs.Current.Value; Filter.Tabs.Current.Value = (DirectSortCriteria)Header.Tabs.Current.Value;
Scheduler.AddOnce(updateSearch); queueUpdateSearch();
} }
}; };
currentQuery.ValueChanged += text => currentQuery.ValueChanged += text => queueUpdateSearch(!string.IsNullOrEmpty(text.NewValue));
{
queryChangedDebounce?.Cancel();
if (string.IsNullOrEmpty(text.NewValue))
Scheduler.AddOnce(updateSearch);
else
{
BeatmapSets = null;
ResultAmounts = null;
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500);
}
};
currentQuery.BindTo(Filter.Search.Current); currentQuery.BindTo(Filter.Search.Current);
@ -170,14 +157,14 @@ namespace osu.Game.Overlays
if (Header.Tabs.Current.Value != DirectTab.Search && tab.NewValue != (DirectSortCriteria)Header.Tabs.Current.Value) if (Header.Tabs.Current.Value != DirectTab.Search && tab.NewValue != (DirectSortCriteria)Header.Tabs.Current.Value)
Header.Tabs.Current.Value = DirectTab.Search; Header.Tabs.Current.Value = DirectTab.Search;
Scheduler.AddOnce(updateSearch); queueUpdateSearch();
}; };
updateResultCounts(); updateResultCounts();
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api, RulesetStore rulesets, PreviewTrackManager previewTrackManager) private void load(OsuColour colours, IAPIProvider api, RulesetStore rulesets, PreviewTrackManager previewTrackManager)
{ {
this.api = api; this.api = api;
this.rulesets = rulesets; this.rulesets = rulesets;
@ -242,37 +229,42 @@ namespace osu.Game.Overlays
// Queries are allowed to be run only on the first pop-in // Queries are allowed to be run only on the first pop-in
if (getSetsRequest == null) if (getSetsRequest == null)
Scheduler.AddOnce(updateSearch); queueUpdateSearch();
} }
private SearchBeatmapSetsRequest getSetsRequest; private SearchBeatmapSetsRequest getSetsRequest;
private readonly Bindable<string> currentQuery = new Bindable<string>(); private readonly Bindable<string> currentQuery = new Bindable<string>(string.Empty);
private ScheduledDelegate queryChangedDebounce; private ScheduledDelegate queryChangedDebounce;
private PreviewTrackManager previewTrackManager; private PreviewTrackManager previewTrackManager;
private void queueUpdateSearch(bool queryTextChanged = false)
{
BeatmapSets = null;
ResultAmounts = null;
getSetsRequest?.Cancel();
queryChangedDebounce?.Cancel();
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, queryTextChanged ? 500 : 100);
}
private void updateSearch() private void updateSearch()
{ {
queryChangedDebounce?.Cancel();
if (!IsLoaded) if (!IsLoaded)
return; return;
if (State == Visibility.Hidden) if (State == Visibility.Hidden)
return; return;
BeatmapSets = null;
ResultAmounts = null;
getSetsRequest?.Cancel();
if (api == null) if (api == null)
return; return;
previewTrackManager.StopAnyPlaying(this); previewTrackManager.StopAnyPlaying(this);
getSetsRequest = new SearchBeatmapSetsRequest(currentQuery.Value ?? string.Empty, getSetsRequest = new SearchBeatmapSetsRequest(
currentQuery.Value,
((FilterControl)Filter).Ruleset.Value, ((FilterControl)Filter).Ruleset.Value,
Filter.DisplayStyleControl.Dropdown.Current.Value, Filter.DisplayStyleControl.Dropdown.Current.Value,
Filter.Tabs.Current.Value); //todo: sort direction (?) Filter.Tabs.Current.Value); //todo: sort direction (?)

View File

@ -109,7 +109,7 @@ namespace osu.Game.Overlays.MedalSplash
s.Font = s.Font.With(size: 16); s.Font = s.Font.With(size: 16);
}); });
medalContainer.OnLoadComplete = d => medalContainer.OnLoadComplete += d =>
{ {
unlocked.Position = new Vector2(0f, medalContainer.DrawSize.Y / 2 + 10); unlocked.Position = new Vector2(0f, medalContainer.DrawSize.Y / 2 + 10);
infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90); infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90);

View File

@ -335,9 +335,12 @@ namespace osu.Game.Overlays.Profile
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(200),
Depth = float.MaxValue, Depth = float.MaxValue,
}, coverContainer.Add); }, background =>
{
coverContainer.Add(background);
background.FadeInFromZero(200);
});
if (user.IsSupporter) if (user.IsSupporter)
SupporterTag.Show(); SupporterTag.Show();

View File

@ -28,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Sections
protected readonly Bindable<User> User = new Bindable<User>(); protected readonly Bindable<User> User = new Bindable<User>();
protected APIAccess Api; protected IAPIProvider Api;
protected APIRequest RetrievalRequest; protected APIRequest RetrievalRequest;
protected RulesetStore Rulesets; protected RulesetStore Rulesets;
@ -84,7 +84,7 @@ namespace osu.Game.Overlays.Profile.Sections
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets) private void load(IAPIProvider api, RulesetStore rulesets)
{ {
Api = api; Api = api;
Rulesets = rulesets; Rulesets = rulesets;

View File

@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
{ {
public class DrawableRecentActivity : DrawableProfileRow public class DrawableRecentActivity : DrawableProfileRow
{ {
private APIAccess api; private IAPIProvider api;
private readonly APIRecentActivity activity; private readonly APIRecentActivity activity;
@ -28,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api) private void load(IAPIProvider api)
{ {
this.api = api; this.api = api;

View File

@ -58,14 +58,14 @@ namespace osu.Game.Overlays.Settings.Sections.General
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, APIAccess api) private void load(OsuColour colours, IAPIProvider api)
{ {
this.colours = colours; this.colours = colours;
api?.Register(this); api?.Register(this);
} }
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state)
{ {
form = null; form = null;
@ -194,7 +194,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
{ {
private TextBox username; private TextBox username;
private TextBox password; private TextBox password;
private APIAccess api; private IAPIProvider api;
public Action RequestHide; public Action RequestHide;
@ -205,7 +205,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api, OsuConfigManager config, AccountCreationOverlay accountCreation) private void load(IAPIProvider api, OsuConfigManager config, AccountCreationOverlay accountCreation)
{ {
this.api = api; this.api = api;
Direction = FillDirection.Vertical; Direction = FillDirection.Vertical;

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays
{ {
public class SocialOverlay : SearchableListOverlay<SocialTab, SocialSortCriteria, SortDirection>, IOnlineComponent public class SocialOverlay : SearchableListOverlay<SocialTab, SocialSortCriteria, SortDirection>, IOnlineComponent
{ {
private APIAccess api; private IAPIProvider api;
private readonly LoadingAnimation loading; private readonly LoadingAnimation loading;
private FillFlowContainer<SocialPanel> panels; private FillFlowContainer<SocialPanel> panels;
@ -89,7 +89,7 @@ namespace osu.Game.Overlays
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api) private void load(IAPIProvider api)
{ {
this.api = api; this.api = api;
api.Register(this); api.Register(this);
@ -193,7 +193,7 @@ namespace osu.Game.Overlays
} }
} }
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state)
{ {
switch (state) switch (state)
{ {

Some files were not shown because too many files have changed in this diff Show More