1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 20:03:20 +08:00
osu-lazer/osu.Game/Graphics/Backgrounds/BeatmapBackgroundWithStoryboard.cs
Nathan Alo 277545bb06 refactor BeatmapBackgroundWithStoryboard to reduce overhead
This avoids loading the sprite if its not needed and instead of hiding it, it is removed when the storyboard replaces the background or there is a video.

This also only initializes DrawableStoryboard if there are any elements in any layer.
2021-06-02 20:27:12 +08:00

36 lines
1.1 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 osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Storyboards.Drawables;
namespace osu.Game.Graphics.Backgrounds
{
public class BeatmapBackgroundWithStoryboard : BeatmapBackground
{
public BeatmapBackgroundWithStoryboard(WorkingBeatmap beatmap, string fallbackTextureName = "Backgrounds/bg1")
: base(beatmap, fallbackTextureName)
{
}
protected override void Initialize()
{
if (Beatmap.Storyboard.HasDrawable)
{
LoadComponentAsync(new DrawableStoryboard(Beatmap.Storyboard) { Clock = new InterpolatingFramedClock(Beatmap.Track) }, AddInternal);
}
if (Beatmap.Storyboard.ReplacesBackground || Beatmap.Storyboard.Layers.First(l => l.Name == "Video").Elements.Any())
{
Sprite.Expire();
}
else
{
base.Initialize();
}
}
}
}