1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Code quality, read position offsets

This commit is contained in:
voidedWarranties 2020-03-08 14:02:39 -07:00
parent 48282dea8b
commit 22dd93a4f6
7 changed files with 26 additions and 16 deletions

View File

@ -92,8 +92,10 @@ namespace osu.Game.Beatmaps.Formats
{
var offset = Parsing.ParseInt(split[1]);
var filename = CleanFilename(split[2]);
var xOffset = split.Length > 3 ? Parsing.ParseInt(split[3]) : 0;
var yOffset = split.Length > 4 ? Parsing.ParseInt(split[4]) : 0;
storyboard.GetLayer("Video").Add(new StoryboardVideo(filename, offset));
storyboard.GetLayer(LegacyStoryLayer.Video).Add(new StoryboardVideo(filename, offset, xOffset, yOffset));
break;
}

View File

@ -3,11 +3,12 @@
namespace osu.Game.Beatmaps.Legacy
{
internal enum LegacyStoryLayer
public enum LegacyStoryLayer
{
Background = 0,
Fail = 1,
Pass = 2,
Foreground = 3
Foreground = 3,
Video = 4
}
}

View File

@ -141,8 +141,6 @@ namespace osu.Game.Migrations
b.Property<string>("VideoFile");
b.Property<int>("VideoOffset");
b.HasKey("ID");
b.ToTable("BeatmapMetadata");

View File

@ -14,6 +14,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Configuration;
using osu.Game.Rulesets.Mods;
@ -117,15 +118,12 @@ namespace osu.Game.Screens.Play
startTime = Math.Min(startTime, firstHitObjectTime - beatmap.BeatmapInfo.AudioLeadIn);
// some beatmaps have no AudioLeadIn but the video starts before the first object
var videoLayer = beatmap.Storyboard.GetLayer("Video");
var videoLayer = beatmap.Storyboard.GetLayer(LegacyStoryLayer.Video);
if (videoLayer.Elements.Any())
{
var videoOffset = videoLayer.Elements.First().StartTime;
var videoOffset = videoLayer.Elements.SingleOrDefault()?.StartTime;
if (videoOffset != 0)
startTime = Math.Min(startTime, videoOffset);
}
if (videoOffset != null)
startTime = Math.Min(startTime, videoOffset.GetValueOrDefault());
Seek(startTime);

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Video;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Storyboards.Drawables
{
@ -57,7 +58,8 @@ namespace osu.Game.Storyboards.Drawables
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AlwaysPresent = true,
Alpha = 0
Alpha = 0,
Position = new Vector2(Video.XOffset, Video.YOffset)
});
videoClock = new ManualClock();

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Storyboards.Drawables;
using System.Collections.Generic;
using System.Linq;
@ -28,6 +29,8 @@ namespace osu.Game.Storyboards
layers.Add("Foreground", new StoryboardLayer("Foreground", 0));
}
public StoryboardLayer GetLayer(LegacyStoryLayer layer) => GetLayer(layer.ToString());
public StoryboardLayer GetLayer(string name)
{
if (!layers.TryGetValue(name, out var layer))
@ -47,14 +50,14 @@ namespace osu.Game.Storyboards
if (backgroundPath == null)
return false;
return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
return GetLayer(LegacyStoryLayer.Background).Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
}
}
public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
{
var drawable = new DrawableStoryboard(this);
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard || GetLayer("Video").Elements.Any() ? 16 / 9f : 4 / 3f);
drawable.Width = drawable.Height * (BeatmapInfo.WidescreenStoryboard || GetLayer(LegacyStoryLayer.Video).Elements.Any() ? 16 / 9f : 4 / 3f);
return drawable;
}
}

View File

@ -14,10 +14,16 @@ namespace osu.Game.Storyboards
public double StartTime { get; }
public StoryboardVideo(string path, int offset)
public int XOffset { get; }
public int YOffset { get; }
public StoryboardVideo(string path, int offset, int xOffset, int yOffset)
{
Path = path;
StartTime = offset;
XOffset = xOffset;
YOffset = yOffset;
}
public Drawable CreateDrawable() => new DrawableStoryboardVideo(this);