mirror of
https://github.com/ppy/osu.git
synced 2026-05-25 08:29:54 +08:00
Handle background offset when encoding/decoding beatmaps (#37841)
- Part of https://github.com/ppy/osu/issues/14238 (doesn't close, because the property doesn't do anything yet). - Supersedes / closes https://github.com/ppy/osu/pull/37467.
This commit is contained in:
committed by
GitHub
Unverified
parent
f5c70679f5
commit
21938eea96
@@ -30,6 +30,23 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
Assert.That(decodedAfterEncode.Beatmap.BeatmapInfo.Metadata.BackgroundFile, Is.EqualTo("bg.jpg"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBackgroundOffset()
|
||||
{
|
||||
var initial = createComponents();
|
||||
initial.Beatmap.BeatmapInfo.Metadata.BackgroundFile = "bg_offset.jpg";
|
||||
initial.Storyboard.BackgroundOffset = new Vector2(0, 45);
|
||||
|
||||
var encoded = encode(initial);
|
||||
var decodedAfterEncode = decode(encoded);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(decodedAfterEncode.Beatmap.BeatmapInfo.Metadata.BackgroundFile, Is.EqualTo("bg_offset.jpg"));
|
||||
Assert.That(decodedAfterEncode.Storyboard.BackgroundOffset, Is.EqualTo(new Vector2(0, 45)));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestVideos()
|
||||
{
|
||||
|
||||
@@ -120,6 +120,20 @@ namespace osu.Game.Beatmaps.Formats
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LegacyEventType.Background:
|
||||
{
|
||||
// the actual filename is handled in `LegacyBeatmapDecoder`.
|
||||
// this only handles the background offset, because it does not logically belong in `Beatmap` or related classes.
|
||||
if (split.Length > 4)
|
||||
{
|
||||
float x = Parsing.ParseFloat(split[3]);
|
||||
float y = Parsing.ParseFloat(split[4]);
|
||||
storyboard.BackgroundOffset = new Vector2(x, y);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case LegacyEventType.Video:
|
||||
{
|
||||
int offset = Parsing.ParseInt(split[1]);
|
||||
|
||||
@@ -54,10 +54,9 @@ namespace osu.Game.Beatmaps.Formats
|
||||
if (target == StoryboardElementSource.Beatmap)
|
||||
{
|
||||
// https://github.com/peppy/osu-stable-reference/blob/c34a74fb61c17c5667486a12548485d1f03baa2e/osu!/GameplayElements/HitObjectManager_LoadSave.cs#L1499
|
||||
// TODO: handle nonzero background offset (https://github.com/ppy/osu/issues/14238)
|
||||
writer.WriteLine(string.Format(CultureInfo.InvariantCulture,
|
||||
@"{0},{1},""{2}"",{3},{4}",
|
||||
(int)LegacyEventType.Background, 0, storyboard.BeatmapInfo.Metadata.BackgroundFile, 0, 0));
|
||||
(int)LegacyEventType.Background, 0, storyboard.BeatmapInfo.Metadata.BackgroundFile, storyboard.BackgroundOffset.X, storyboard.BackgroundOffset.Y));
|
||||
}
|
||||
|
||||
// https://github.com/peppy/osu-stable-reference/blob/c34a74fb61c17c5667486a12548485d1f03baa2e/osu!/GameplayElements/HitObjectManager_LoadSave.cs#L1496
|
||||
|
||||
@@ -9,6 +9,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Storyboards.Drawables;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Storyboards
|
||||
{
|
||||
@@ -98,6 +99,12 @@ namespace osu.Game.Storyboards
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Offset to be applied to the beatmap background.
|
||||
/// TODO: Unused yet. See https://github.com/ppy/osu/issues/14238.
|
||||
/// </summary>
|
||||
public Vector2 BackgroundOffset { get; set; } = Vector2.Zero;
|
||||
|
||||
public virtual DrawableStoryboard CreateDrawable(IReadOnlyList<Mod>? mods = null) =>
|
||||
new DrawableStoryboard(this, mods);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user