<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;
using System.Text.RegularExpressions;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Skinning;

namespace osu.Game.Tests.Visual
{
    public abstract class SkinnableTestScene : OsuGridTestScene
    {
        private Skin metricsSkin;
        private Skin defaultSkin;
        private Skin specialSkin;
        private Skin oldSkin;

        protected SkinnableTestScene()
            : base(2, 3)
        {
        }

        [BackgroundDependencyLoader]
        private void load(AudioManager audio, SkinManager skinManager)
        {
            var dllStore = new DllResourceStore(GetType().Assembly);

            metricsSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/metrics_skin"), audio, true);
            defaultSkin = skinManager.GetSkin(DefaultLegacySkin.Info);
            specialSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/special_skin"), audio, true);
            oldSkin = new TestLegacySkin(new SkinInfo(), new NamespacedResourceStore<byte[]>(dllStore, "Resources/old_skin"), audio, true);
        }

        public void SetContents(Func<Drawable> creationFunction)
        {
            Cell(0).Child = createProvider(null, creationFunction);
            Cell(1).Child = createProvider(metricsSkin, creationFunction);
            Cell(2).Child = createProvider(defaultSkin, creationFunction);
            Cell(3).Child = createProvider(specialSkin, creationFunction);
            Cell(4).Child = createProvider(oldSkin, creationFunction);
        }

        private Drawable createProvider(Skin skin, Func<Drawable> creationFunction)
        {
            var mainProvider = new SkinProvidingContainer(skin);

            return mainProvider
                .WithChild(new SkinProvidingContainer(Ruleset.Value.CreateInstance().CreateLegacySkinProvider(mainProvider))
                {
                    Child = creationFunction()
                });
        }

        private class TestLegacySkin : LegacySkin
        {
            private readonly bool extrapolateAnimations;

            public TestLegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, bool extrapolateAnimations)
                : base(skin, storage, audioManager, "skin.ini")
            {
                this.extrapolateAnimations = extrapolateAnimations;
            }

            public override Texture GetTexture(string componentName)
            {
                // extrapolate frames to test longer animations
                if (extrapolateAnimations)<commit_msg>Show skinnable test skin names and autosized component sizes<commit_after>// 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;
using System.Text.RegularExpressions;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Graphics.Sprites;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Tests.Visual
{
    public abstract class SkinnableTestScene : OsuGridTestScene
    {
        private Skin metricsSkin;
        private Skin defaultSkin;
        private Skin specialSkin;
        private Skin oldSkin;

        protected SkinnableTestScene()
            : base(2, 3)
        {
        }

        [BackgroundDependencyLoader]
        private void load(AudioManager audio, SkinManager skinManager)
        {
            var dllStore = new DllResourceStore(GetType().Assembly);

            metricsSkin = new TestLegacySkin(new SkinInfo { Name = "metrics-skin" }, new NamespacedResourceStore<byte[]>(dllStore, "Resources/metrics_skin"), audio, true);
            defaultSkin = skinManager.GetSkin(DefaultLegacySkin.Info);
            specialSkin = new TestLegacySkin(new SkinInfo { Name = "special-skin" }, new NamespacedResourceStore<byte[]>(dllStore, "Resources/special_skin"), audio, true);
            oldSkin = new TestLegacySkin(new SkinInfo { Name = "old-skin" }, new NamespacedResourceStore<byte[]>(dllStore, "Resources/old_skin"), audio, true);
        }

        public void SetContents(Func<Drawable> creationFunction)
        {
            Cell(0).Child = createProvider(null, creationFunction);
            Cell(1).Child = createProvider(metricsSkin, creationFunction);
            Cell(2).Child = createProvider(defaultSkin, creationFunction);
            Cell(3).Child = createProvider(specialSkin, creationFunction);
            Cell(4).Child = createProvider(oldSkin, creationFunction);
        }

        private Drawable createProvider(Skin skin, Func<Drawable> creationFunction)
        {
            var created = creationFunction();
            var autoSize = created.RelativeSizeAxes == Axes.None;

            var mainProvider = new SkinProvidingContainer(skin)
            {
                RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None,
                AutoSizeAxes = autoSize ? Axes.Both : Axes.None,
            };

            return new Container
            {
                RelativeSizeAxes = Axes.Both,
                BorderColour = Color4.White,
                BorderThickness = 5,
                Masking = true,

                Children = new Drawable[]
                {
                    new Box
                    {
                        AlwaysPresent = true,
                        Alpha = 0,
                        RelativeSizeAxes = Axes.Both,
                    },
                    new OsuSpriteText
                    {
                        Text = skin?.SkinInfo?.Name ?? "none",
                        Scale = new Vector2(1.5f),
                        Padding = new MarginPadding(5),
                    },
                    new Container
                    {
                        RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None,
                        AutoSizeAxes = autoSize ? Axes.Both : Axes.None,
                        Anchor = Anchor.Centre,
                        Origin = Anchor.Centre,
                        Children = new Drawable[]
                        {
                            new OutlineBox { Alpha = autoSize ? 1 : 0 },
                            mainProvider.WithChild(
                                new SkinProvidingContainer(Ruleset.Value.CreateInstance().CreateLegacySkinProvider(mainProvider))
                                {
                                    Child = created,
                                    RelativeSizeAxes = !autoSize ? Axes.Both : Axes.None,
                                    AutoSizeAxes = autoSize ? Axes.Both : Axes.None,
                                }
                            )
                        }
                    },
                }
            };
        }

        private class OutlineBox : CompositeDrawable
        {
            public OutlineBox()
            {
                BorderColour = Color4.IndianRed;
                BorderThickness = 5;
                Masking = true;
                RelativeSizeAxes = Axes.Both;

                InternalChild = new Box
                {
                    RelativeSizeAxes = Axes.Both,
                    Alpha = 0,
                    Colour = Color4.Brown,
                    AlwaysPresent = true
                };
            }
        }

        private class TestLegacySkin : LegacySkin
        {
            private readonly bool extrapolateAnimations;

            public TestLegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, bool extrapolateAnimations)
                : base(skin, storage, audioManager, "skin.ini")
            {
                this.extrapolateAnimations = extrapolateAnimations;
            }

            public override Texture GetTexture(string componentName)
            {
                // extrapolate frames to test longer animations
                if (extrapolateAnimations)
{'fraction_non_alphanumeric': 0.0787979176526266, 'fraction_numerical': 0.003194510175106484, 'mean_word_length': 1.8129783693843593, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5703887', 'n_tokens_mistral': 2232, 'n_tokens_neox': 2054, 'n_words': 476}