1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 02:57:26 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboard.cs

136 lines
4.2 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2023-05-18 11:23:37 +08:00
using System;
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Timing;
2023-05-18 11:23:37 +08:00
using osu.Framework.Utils;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
2018-04-13 17:19:50 +08:00
using osu.Game.Overlays;
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
2024-06-14 19:36:40 +08:00
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Storyboards;
2018-04-13 17:19:50 +08:00
using osu.Game.Storyboards.Drawables;
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
2024-06-14 19:36:40 +08:00
using osu.Game.Tests.Gameplay;
using osu.Game.Tests.Resources;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Gameplay
2018-04-13 17:19:50 +08:00
{
[TestFixture]
2022-11-24 13:32:20 +08:00
public partial class TestSceneStoryboard : OsuTestScene
2018-04-13 17:19:50 +08:00
{
2022-09-07 14:30:48 +08:00
private Container<DrawableStoryboard> storyboardContainer = null!;
private DrawableStoryboard? storyboard;
2018-04-13 17:19:50 +08:00
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
2024-06-14 19:36:40 +08:00
[Cached]
private GameplayState testGameplayState = TestGameplayState.Create(new OsuRuleset());
[Test]
public void TestStoryboard()
{
AddStep("Restart", restart);
Implement toggling visibility of pass and fail storyboard layers Closes https://github.com/ppy/osu/issues/6842. This is a rather barebones implementation, just to get this in place somehow at least. The logic is simple - 50% health or above shows pass layer, anything below shows fail layer. This does not match stable logic all across the board because I have no idea how to package that. Stable defines "passing" in like fifty ways: - in mania it's >80% HP (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Mania/RulesetMania.cs#L333-L336) - in taiko it's >80% *accuracy* (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Rulesets/Taiko/RulesetTaiko.cs#L486-L492) - there's also the part where "geki additions" will unconditionally set passing state (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3561-L3564) - and also the part where at the end of the map, the final passing state is determined by checking whether the user passed more sections than failed (https://github.com/peppy/osu-stable-reference/blob/bb57924c1552adbed11ee3d96cdcde47cf96f2b6/osu!/GameModes/Play/Player.cs#L3320) The biggest issues of these are probably the first two, and they can *probably* be fixed, but would require a new member on `Ruleset` and I'm not sure how to make one look, so I'm not doing that at this time pending collection of ideas on how to do that.
2024-06-14 19:36:40 +08:00
AddToggleStep("Toggle passing state", passing => testGameplayState.HealthProcessor.Health.Value = passing ? 1 : 0);
}
[Test]
public void TestStoryboardMissingVideo()
{
2022-09-07 14:30:48 +08:00
AddStep("Load storyboard with missing video", () => loadStoryboard("storyboard_no_video.osu"));
}
2023-05-18 11:23:37 +08:00
[Test]
public void TestVideoSize()
{
AddStep("load storyboard with only video", () =>
{
// LegacyStoryboardDecoder doesn't parse WidescreenStoryboard, so it is set manually
loadStoryboard("storyboard_only_video.osu", s => s.BeatmapInfo.WidescreenStoryboard = false);
});
AddAssert("storyboard is correct width", () => Precision.AlmostEquals(storyboard?.Width ?? 0f, 480 * 16 / 9f));
}
[BackgroundDependencyLoader]
private void load()
2018-04-13 17:19:50 +08:00
{
Clock = new FramedClock();
AddRange(new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Container
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
storyboardContainer = new Container<DrawableStoryboard>
{
RelativeSizeAxes = Axes.Both,
},
2018-04-13 17:19:50 +08:00
},
},
new NowPlayingOverlay
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
State = { Value = Visibility.Visible },
}
2018-04-13 17:19:50 +08:00
});
Beatmap.BindValueChanged(beatmapChanged, true);
2018-04-13 17:19:50 +08:00
}
2022-09-07 14:30:48 +08:00
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> e) => loadStoryboard(e.NewValue.Storyboard);
2018-04-13 17:19:50 +08:00
private void restart()
{
var track = Beatmap.Value.Track;
track.Reset();
2022-09-07 14:30:48 +08:00
loadStoryboard(Beatmap.Value.Storyboard);
track.Start();
2018-04-13 17:19:50 +08:00
}
2022-09-07 14:30:48 +08:00
private void loadStoryboard(Storyboard toLoad)
2018-04-13 17:19:50 +08:00
{
if (storyboard != null)
storyboardContainer.Remove(storyboard, true);
2018-04-13 17:19:50 +08:00
storyboardContainer.Clock = new FramedClock(Beatmap.Value.Track);
2018-04-13 17:19:50 +08:00
2022-09-07 14:30:48 +08:00
storyboard = toLoad.CreateDrawable(SelectedMods.Value);
2018-04-13 17:19:50 +08:00
storyboardContainer.Add(storyboard);
}
2023-05-18 11:23:37 +08:00
private void loadStoryboard(string filename, Action<Storyboard>? setUpStoryboard = null)
{
2022-09-07 14:30:48 +08:00
Storyboard loaded;
2022-09-07 14:30:48 +08:00
using (var str = TestResources.OpenResource(filename))
using (var bfr = new LineBufferedReader(str))
{
var decoder = new LegacyStoryboardDecoder();
2022-09-07 14:30:48 +08:00
loaded = decoder.Decode(bfr);
}
2023-05-18 11:23:37 +08:00
setUpStoryboard?.Invoke(loaded);
2022-09-07 14:30:48 +08:00
loadStoryboard(loaded);
}
2018-04-13 17:19:50 +08:00
}
}