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 @@ private void handleEvents(string line)
{
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 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("VideoFile");
b.Property<int>("VideoOffset");
b.HasKey("ID");
b.ToTable("BeatmapMetadata");

View File

@ -14,6 +14,7 @@
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 @@ private void load(OsuConfigManager config)
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.Timing;
using osu.Game.Beatmaps;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Storyboards.Drawables
{
@ -57,7 +58,8 @@ private void load(GameplayClock clock, IBindable<WorkingBeatmap> beatmap, Textur
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 @@ public Storyboard()
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 @@ public bool ReplacesBackground
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 @@ public class StoryboardVideo : IStoryboardElement
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);