mirror of
https://github.com/ppy/osu.git
synced 2026-05-24 06:19:55 +08:00
0e443b1c47
- Closes https://github.com/ppy/osu/issues/37757 Commit-by-commit reading is recommended. Commits will be split to PRs on request but I consider this to be the minimal viable functional increment. ## Done - This adds a first version of a full storyboard encoder (a66dc406f498e35d4e0c8f2a462e946a9a1aeccc). I expect there to be hiccups due to weird corners of the `.osb` format; this is only intended to be somewhat correct as a start to build upon. Storyboarders are asked to file issues as necessary. - Due to the fact that storyboard definitions can reside both in the `.osu` and the `.osb`, b60698a95c4de1bfeb36fbb159fd5a6028920832 adds the required storage to be able to tell which storyboard element lives where, so that it can be decoded properly later. - In c9d3e04a4135886b5b0943c85f3cc6f4fe99c84c, the storyboard decoder is weaved into the beatmap decoder to handle the `.osu` part of the storyboard, via the `LegacyStoryboardEncoder.Encode{General,Events}ToBeatmap()` methods. For `.osb`s, `LegacyStoryboardEncoder.EncodeStandaloneStoryboard()` is intended, but for now is not used outside tests. - Because of the above, dd1c4e43dc51154cd67860f096712f8b4f229661 removes `Beatmap.UnhandledEventLines` as no longer required. - 26ac417ed98a8937c42e5f52c4e15ef065a48902 adds tests. They are mostly handwritten to ensure basic encode-decode roundtripping. Using existing storyboards is difficult, see "Known issues" section as to why. - 5cc542366db7caac38eb0729260d884905a2c0d5 fixes a bug in the storyboard decoder where the trigger group number was not properly negated on decode (see inline comment reference to relevant stable code). ## Known issues - Any and all variables in the `[Variables]` section are inlined into their usages by `LegacyStoryboardDecoder`, and as such `LegacyStoryboardEncoder` will end up inlining them and discarding the `[Variables]` section. As far as I can tell stable will also do this. - `LegacyStoryboardDecoder` splits all `M` (move) commands into `MX`/`MY` commands. Therefore, `LegacyStoryboardEncoder` will write out things in the same split way. I did not put in effort to attempt to reconcile this, for reasons of part laziness, part not wanting to bloat this already-large diff. - Ordering of storyboard samples on decode may not match the order on decode. I'm crossing fingers this doesn't matter.
180 lines
6.3 KiB
C#
180 lines
6.3 KiB
C#
// 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.Linq;
|
|
using NUnit.Framework;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Rulesets.Edit;
|
|
using osu.Game.Rulesets.Edit.Checks;
|
|
using osu.Game.Storyboards;
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
namespace osu.Game.Tests.Editing.Checks
|
|
{
|
|
[TestFixture]
|
|
public class CheckVideoUsageTest
|
|
{
|
|
private CheckVideoUsage check = null!;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
check = new CheckVideoUsage();
|
|
}
|
|
|
|
[Test]
|
|
public void TestConsistentVideoUsage()
|
|
{
|
|
var beatmap1 = createBeatmapWithVideo("Diff 1", "video.mp4", 1000);
|
|
var beatmap2 = createBeatmapWithVideo("Diff 2", "video.mp4", 1000);
|
|
|
|
var context = createContext(beatmap1, [beatmap2]);
|
|
|
|
Assert.That(check.Run(context), Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void TestDifferentVideoFile()
|
|
{
|
|
var beatmap1 = createBeatmapWithVideo("Diff 1", "videoA.mp4", 0);
|
|
var beatmap2 = createBeatmapWithVideo("Diff 2", "videoB.mp4", 500);
|
|
|
|
var context = createContext(beatmap1, [beatmap2]);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckVideoUsage.IssueTemplateDifferentVideo);
|
|
}
|
|
|
|
[Test]
|
|
public void TestDifferentStartTime()
|
|
{
|
|
var beatmap1 = createBeatmapWithVideo("Diff 1", "video.mp4", 0);
|
|
var beatmap2 = createBeatmapWithVideo("Diff 2", "video.mp4", 500);
|
|
|
|
var context = createContext(beatmap1, [beatmap2]);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckVideoUsage.IssueTemplateDifferentStartTime);
|
|
}
|
|
|
|
[Test]
|
|
public void TestOtherDifficultyMissingVideo()
|
|
{
|
|
var beatmap1 = createBeatmapWithVideo("Diff 1", "video.mp4", 0);
|
|
var beatmap2 = createBeatmapWithoutVideo("Diff 2");
|
|
|
|
var context = createContext(beatmap1, [beatmap2]);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckVideoUsage.IssueTemplateMissingVideo);
|
|
}
|
|
|
|
[Test]
|
|
public void TestCurrentDifficultyMissingVideo()
|
|
{
|
|
var beatmap1 = createBeatmapWithoutVideo("Diff 1");
|
|
var beatmap2 = createBeatmapWithVideo("Diff 2", "video.mp4", 0);
|
|
|
|
var context = createContext(beatmap1, [beatmap2]);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(1));
|
|
Assert.That(issues.Single().Template is CheckVideoUsage.IssueTemplateMissingVideo);
|
|
}
|
|
|
|
[Test]
|
|
public void TestBothDifficultiesMissingVideo()
|
|
{
|
|
var beatmap1 = createBeatmapWithoutVideo("Diff 1");
|
|
var beatmap2 = createBeatmapWithoutVideo("Diff 2");
|
|
|
|
var context = createContext(beatmap1, [beatmap2]);
|
|
|
|
Assert.That(check.Run(context), Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void TestPairwiseStartTimeMismatchAcrossNonCurrentDifficulties()
|
|
{
|
|
var beatmapCurrent = createBeatmapWithVideo("Diff A", "A.mp4", 0);
|
|
var beatmapB = createBeatmapWithVideo("Diff B", "X.mp4", 1000);
|
|
var beatmapC = createBeatmapWithVideo("Diff C", "X.mp4", 2000);
|
|
|
|
var context = createContext(beatmapCurrent, [beatmapB, beatmapC]);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(3));
|
|
Assert.That(issues.Count(i => i.Template is CheckVideoUsage.IssueTemplateDifferentVideo), Is.EqualTo(2));
|
|
Assert.That(issues.Count(i => i.Template is CheckVideoUsage.IssueTemplateDifferentStartTime), Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public void TestPairwiseStartTimeMismatchWhenCurrentMissingVideo()
|
|
{
|
|
var beatmapCurrent = createBeatmapWithoutVideo("Diff A");
|
|
var beatmapB = createBeatmapWithVideo("Diff B", "X.mp4", 1000);
|
|
var beatmapC = createBeatmapWithVideo("Diff C", "X.mp4", 2000);
|
|
|
|
var context = createContext(beatmapCurrent, [beatmapB, beatmapC]);
|
|
|
|
var issues = check.Run(context).ToList();
|
|
|
|
Assert.That(issues, Has.Count.EqualTo(2));
|
|
Assert.That(issues.Count(i => i.Template is CheckVideoUsage.IssueTemplateMissingVideo), Is.EqualTo(1));
|
|
Assert.That(issues.Count(i => i.Template is CheckVideoUsage.IssueTemplateDifferentStartTime), Is.EqualTo(1));
|
|
}
|
|
|
|
private BeatmapVerifierContext.VerifiedBeatmap createBeatmapWithVideo(string difficultyName, string path, double startTime)
|
|
{
|
|
var beatmap = new Beatmap
|
|
{
|
|
BeatmapInfo = new BeatmapInfo
|
|
{
|
|
DifficultyName = difficultyName
|
|
}
|
|
};
|
|
|
|
var storyboard = new Storyboard();
|
|
storyboard.GetLayer("Video").Add(new StoryboardVideo(StoryboardElementSource.Beatmap, path, startTime));
|
|
|
|
var working = new TestWorkingBeatmap(beatmap, storyboard);
|
|
return new BeatmapVerifierContext.VerifiedBeatmap(working, beatmap);
|
|
}
|
|
|
|
private BeatmapVerifierContext.VerifiedBeatmap createBeatmapWithoutVideo(string difficultyName)
|
|
{
|
|
var beatmap = new Beatmap
|
|
{
|
|
BeatmapInfo = new BeatmapInfo
|
|
{
|
|
DifficultyName = difficultyName
|
|
}
|
|
};
|
|
|
|
var storyboard = new Storyboard();
|
|
// no video added
|
|
var working = new TestWorkingBeatmap(beatmap, storyboard);
|
|
return new BeatmapVerifierContext.VerifiedBeatmap(working, beatmap);
|
|
}
|
|
|
|
private BeatmapVerifierContext createContext(BeatmapVerifierContext.VerifiedBeatmap current, BeatmapVerifierContext.VerifiedBeatmap[] others)
|
|
{
|
|
return new BeatmapVerifierContext(
|
|
current,
|
|
others.ToList(),
|
|
DifficultyRating.ExpertPlus
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
|