2019-06-28 08:34:04 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-06-28 08:34:04 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-03-11 20:09:29 +00:00
|
|
|
using NUnit.Framework;
|
2019-06-28 08:34:04 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2020-02-19 09:01:59 +00:00
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
2019-06-28 08:34:04 +00:00
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Tests
|
|
|
|
{
|
|
|
|
public class TestSceneDrawableHitObjects : OsuTestScene
|
|
|
|
{
|
|
|
|
private DrawableCatchRuleset drawableRuleset;
|
|
|
|
private double playfieldTime => drawableRuleset.Playfield.Time.Current;
|
|
|
|
|
2020-03-11 20:09:29 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
2019-06-28 08:34:04 +00:00
|
|
|
{
|
|
|
|
var controlPointInfo = new ControlPointInfo();
|
2019-10-25 10:48:01 +00:00
|
|
|
controlPointInfo.Add(0, new TimingControlPoint());
|
2019-06-28 08:34:04 +00:00
|
|
|
|
2021-11-15 09:46:11 +00:00
|
|
|
IWorkingBeatmap beatmap = CreateWorkingBeatmap(new Beatmap
|
2019-06-28 08:34:04 +00:00
|
|
|
{
|
|
|
|
HitObjects = new List<HitObject> { new Fruit() },
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
2022-01-18 13:57:39 +00:00
|
|
|
Difficulty = new BeatmapDifficulty(),
|
2019-06-28 08:34:04 +00:00
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
Artist = @"Unknown",
|
|
|
|
Title = @"You're breathtaking",
|
2022-01-18 14:30:40 +00:00
|
|
|
Author = { Username = @"Everyone" },
|
2019-06-28 08:34:04 +00:00
|
|
|
},
|
|
|
|
Ruleset = new CatchRuleset().RulesetInfo
|
|
|
|
},
|
|
|
|
ControlPointInfo = controlPointInfo
|
|
|
|
});
|
|
|
|
|
2020-03-11 20:09:29 +00:00
|
|
|
Child = new Container
|
2019-06-28 08:34:04 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2019-12-12 06:58:11 +00:00
|
|
|
drawableRuleset = new DrawableCatchRuleset(new CatchRuleset(), beatmap.GetPlayableBeatmap(new CatchRuleset().RulesetInfo))
|
2019-06-28 08:34:04 +00:00
|
|
|
}
|
2020-03-11 20:09:29 +00:00
|
|
|
};
|
|
|
|
});
|
2019-06-28 08:34:04 +00:00
|
|
|
|
2020-03-11 20:09:29 +00:00
|
|
|
[Test]
|
|
|
|
public void TestFruits()
|
|
|
|
{
|
2019-06-28 08:34:04 +00:00
|
|
|
AddStep("hit fruits", () => spawnFruits(true));
|
2020-03-11 20:09:29 +00:00
|
|
|
AddUntilStep("wait for completion", () => playfieldIsEmpty);
|
|
|
|
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
|
|
|
|
|
|
|
|
AddStep("miss fruits", () => spawnFruits());
|
|
|
|
AddUntilStep("wait for completion", () => playfieldIsEmpty);
|
|
|
|
AddAssert("catcher state is failed", () => catcherState == CatcherAnimationState.Fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-12-10 05:15:00 +00:00
|
|
|
public void TestJuiceStream()
|
2020-03-11 20:09:29 +00:00
|
|
|
{
|
2019-06-28 08:34:04 +00:00
|
|
|
AddStep("hit juicestream", () => spawnJuiceStream(true));
|
2020-03-11 20:09:29 +00:00
|
|
|
AddUntilStep("wait for completion", () => playfieldIsEmpty);
|
|
|
|
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
|
|
|
|
|
|
|
|
AddStep("miss juicestream", () => spawnJuiceStream());
|
|
|
|
AddUntilStep("wait for completion", () => playfieldIsEmpty);
|
|
|
|
AddAssert("catcher state is failed", () => catcherState == CatcherAnimationState.Fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBananas()
|
|
|
|
{
|
2019-06-28 08:34:04 +00:00
|
|
|
AddStep("hit bananas", () => spawnBananas(true));
|
2020-03-11 20:09:29 +00:00
|
|
|
AddUntilStep("wait for completion", () => playfieldIsEmpty);
|
|
|
|
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
|
|
|
|
|
|
|
|
AddStep("miss bananas", () => spawnBananas());
|
|
|
|
AddUntilStep("wait for completion", () => playfieldIsEmpty);
|
|
|
|
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
|
2019-06-28 08:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 20:09:29 +00:00
|
|
|
private bool playfieldIsEmpty => !((CatchPlayfield)drawableRuleset.Playfield).AllHitObjects.Any(h => h.IsAlive);
|
|
|
|
|
2021-07-19 10:52:40 +00:00
|
|
|
private CatcherAnimationState catcherState => ((CatchPlayfield)drawableRuleset.Playfield).Catcher.CurrentState;
|
2020-03-11 20:09:29 +00:00
|
|
|
|
2019-06-28 08:34:04 +00:00
|
|
|
private void spawnFruits(bool hit = false)
|
|
|
|
{
|
|
|
|
for (int i = 1; i <= 4; i++)
|
|
|
|
{
|
|
|
|
var fruit = new Fruit
|
|
|
|
{
|
|
|
|
X = getXCoords(hit),
|
|
|
|
LastInCombo = i % 4 == 0,
|
|
|
|
StartTime = playfieldTime + 800 + (200 * i)
|
|
|
|
};
|
|
|
|
|
|
|
|
fruit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
|
|
|
|
addToPlayfield(new DrawableFruit(fruit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void spawnJuiceStream(bool hit = false)
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
float xCoords = getXCoords(hit);
|
2019-06-28 08:34:04 +00:00
|
|
|
|
|
|
|
var juice = new JuiceStream
|
|
|
|
{
|
|
|
|
X = xCoords,
|
|
|
|
StartTime = playfieldTime + 1000,
|
|
|
|
Path = new SliderPath(PathType.Linear, new[]
|
|
|
|
{
|
|
|
|
Vector2.Zero,
|
|
|
|
new Vector2(0, 200)
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
juice.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
|
|
|
|
if (juice.NestedHitObjects.Last() is CatchHitObject tail)
|
|
|
|
tail.LastInCombo = true; // usually the (Catch)BeatmapProcessor would do this for us when necessary
|
|
|
|
|
2020-11-30 10:19:14 +00:00
|
|
|
addToPlayfield(new DrawableJuiceStream(juice));
|
2019-06-28 08:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void spawnBananas(bool hit = false)
|
|
|
|
{
|
|
|
|
for (int i = 1; i <= 4; i++)
|
|
|
|
{
|
|
|
|
var banana = new Banana
|
|
|
|
{
|
|
|
|
X = getXCoords(hit),
|
|
|
|
LastInCombo = i % 4 == 0,
|
|
|
|
StartTime = playfieldTime + 800 + (200 * i)
|
|
|
|
};
|
|
|
|
|
|
|
|
banana.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
|
|
|
|
addToPlayfield(new DrawableBanana(banana));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private float getXCoords(bool hit)
|
|
|
|
{
|
2020-07-01 15:21:45 +00:00
|
|
|
const float x_offset = 0.2f * CatchPlayfield.WIDTH;
|
|
|
|
float xCoords = CatchPlayfield.CENTER_X;
|
2019-06-28 08:34:04 +00:00
|
|
|
|
|
|
|
if (drawableRuleset.Playfield is CatchPlayfield catchPlayfield)
|
2021-07-19 10:52:40 +00:00
|
|
|
catchPlayfield.Catcher.X = xCoords - x_offset;
|
2019-06-28 08:34:04 +00:00
|
|
|
|
|
|
|
if (hit)
|
|
|
|
xCoords -= x_offset;
|
|
|
|
else
|
|
|
|
xCoords += x_offset;
|
|
|
|
|
|
|
|
return xCoords;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addToPlayfield(DrawableCatchHitObject drawable)
|
|
|
|
{
|
2021-06-16 09:46:29 +00:00
|
|
|
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
|
|
|
|
mod.ApplyToDrawableHitObject(drawable);
|
2019-06-28 08:34:04 +00:00
|
|
|
|
|
|
|
drawableRuleset.Playfield.Add(drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|