<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Storyboards.Drawables;

namespace osu.Game.Storyboards
{
    public class Storyboard
    {
        private readonly Dictionary<string, StoryboardLayer> layers = new Dictionary<string, StoryboardLayer>();
        public IEnumerable<StoryboardLayer> Layers => layers.Values;

        public BeatmapInfo BeatmapInfo = new BeatmapInfo();

        public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));

        public double FirstEventTime => Layers.Min(l => l.Elements.FirstOrDefault()?.StartTime ?? 0);

        public Storyboard()
        {
            layers.Add("Video", new StoryboardLayer("Video", 4, false));
            layers.Add("Background", new StoryboardLayer("Background", 3));
            layers.Add("Fail", new StoryboardLayer("Fail", 2) { VisibleWhenPassing = false, });
            layers.Add("Pass", new StoryboardLayer("Pass", 1) { VisibleWhenFailing = false, });
            layers.Add("Foreground", new StoryboardLayer("Foreground", 0));
        }

        public StoryboardLayer GetLayer(string name)
        {
            if (!layers.TryGetValue(name, out var layer))
                layers[name] = layer = new StoryboardLayer(name, layers.Values.Min(l => l.Depth) - 1);

            return layer;
        }

        /// <summary>
        /// Whether the beatmap's background should be hidden while this storyboard is being displayed.
        /// </summary>
        public bool ReplacesBackground
        {
            get
            {
                var backgroundPath = BeatmapInfo.BeatmapSet?.Metadata?.BackgroundFile?.ToLowerInvariant();
                if (backgroundPath == null)
                    return false;

                return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
            }
        }

        public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
        {
            var drawable = new DrawableStoryboard(this);<commit_msg>Add overlay layer to storyboard definition<commit_after>﻿// Copyright (c) ppy P<NAME> <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Storyboards.Drawables;

namespace osu.Game.Storyboards
{
    public class Storyboard
    {
        private readonly Dictionary<string, StoryboardLayer> layers = new Dictionary<string, StoryboardLayer>();
        public IEnumerable<StoryboardLayer> Layers => layers.Values;

        public BeatmapInfo BeatmapInfo = new BeatmapInfo();

        public bool HasDrawable => Layers.Any(l => l.Elements.Any(e => e.IsDrawable));

        public double FirstEventTime => Layers.Min(l => l.Elements.FirstOrDefault()?.StartTime ?? 0);

        /// <summary>
        /// Depth of the currently front-most storyboard layer, excluding the overlay layer.
        /// </summary>
        private int minimumLayerDepth;

        public Storyboard()
        {
            layers.Add("Video", new StoryboardLayer("Video", 4, false));
            layers.Add("Background", new StoryboardLayer("Background", 3));
            layers.Add("Fail", new StoryboardLayer("Fail", 2) { VisibleWhenPassing = false, });
            layers.Add("Pass", new StoryboardLayer("Pass", 1) { VisibleWhenFailing = false, });
            layers.Add("Foreground", new StoryboardLayer("Foreground", minimumLayerDepth = 0));

            layers.Add("Overlay", new StoryboardLayer("Overlay", int.MinValue));
        }

        public StoryboardLayer GetLayer(string name)
        {
            if (!layers.TryGetValue(name, out var layer))
                layers[name] = layer = new StoryboardLayer(name, --minimumLayerDepth);

            return layer;
        }

        /// <summary>
        /// Whether the beatmap's background should be hidden while this storyboard is being displayed.
        /// </summary>
        public bool ReplacesBackground
        {
            get
            {
                var backgroundPath = BeatmapInfo.BeatmapSet?.Metadata?.BackgroundFile?.ToLowerInvariant();
                if (backgroundPath == null)
                    return false;

                return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
            }
        }

        public DrawableStoryboard CreateDrawable(WorkingBeatmap working = null)
        {
            var drawable = new DrawableStoryboard(this);
{'fraction_non_alphanumeric': 0.11019283746556474, 'fraction_numerical': 0.0027548209366391185, 'mean_word_length': 2.5014836795252227, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3379020', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1195, 'n_words': 324}