<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 osuTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables.Connections;
using osu.Game.Rulesets.UI;
using System.Linq;
using osu.Game.Rulesets.Judgements;

namespace osu.Game.Rulesets.Osu.UI
{
    public class OsuPlayfield : Playfield
    {
        private readonly ApproachCircleProxyContainer approachCircles;
        private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
        private readonly ConnectionRenderer<OsuHitObject> connectionLayer;

        public static readonly Vector2 BASE_SIZE = new Vector2(512, 384);

        public OsuPlayfield()
        {
            Anchor = Anchor.Centre;
            Origin = Anchor.Centre;

            Size = new Vector2(0.75f);

            InternalChild = new PlayfieldAdjustmentContainer
            {
                RelativeSizeAxes = Axes.Both,
                Children = new Drawable[]
                {
                    connectionLayer = new FollowPointRenderer
                    {
                        RelativeSizeAxes = Axes.Both,
                        Depth = 2,
                    },
                    judgementLayer = new JudgementContainer<DrawableOsuJudgement>
                    {
                        RelativeSizeAxes = Axes.Both,
                        Depth = 1,
                    },
                    HitObjectContainer,
                    approachCircles = new ApproachCircleProxyContainer
                    {
                        RelativeSizeAxes = Axes.Both,
                        Depth = -1,
                    },
                }
            };
        }

        public override void Add(DrawableHitObject h)
        {
            h.OnNewResult += onNewResult;

            var c = h as IDrawableHitObjectWithProxiedApproach;
            if (c != null)
            {
                var original = c.ProxiedLayer;
                // lifetime is set on LoadComplete so wait until it.
                original.OnLoadComplete += addApproachCircleProxy;
            }

            base.Add(h);
        }

        private void addApproachCircleProxy(Drawable d)
        {
            var proxy = d.CreateProxy();
            proxy.LifetimeStart = d.LifetimeStart;
            proxy.LifetimeEnd = d.LifetimeEnd;
            approachCircles.Add(proxy);
        }

        public override void PostProcess()
        {
            connectionLayer.HitObjects = HitObjectContainer.Objects.Select(d => d.HitObject).OfType<OsuHitObject>();
        }

        private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
        {
            if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
                return;
<commit_msg>Adjust comment for readability<commit_after>﻿// Copyright (c) <NAME> <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osuTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables.Connections;
using osu.Game.Rulesets.UI;
using System.Linq;
using osu.Game.Rulesets.Judgements;

namespace osu.Game.Rulesets.Osu.UI
{
    public class OsuPlayfield : Playfield
    {
        private readonly ApproachCircleProxyContainer approachCircles;
        private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
        private readonly ConnectionRenderer<OsuHitObject> connectionLayer;

        public static readonly Vector2 BASE_SIZE = new Vector2(512, 384);

        public OsuPlayfield()
        {
            Anchor = Anchor.Centre;
            Origin = Anchor.Centre;

            Size = new Vector2(0.75f);

            InternalChild = new PlayfieldAdjustmentContainer
            {
                RelativeSizeAxes = Axes.Both,
                Children = new Drawable[]
                {
                    connectionLayer = new FollowPointRenderer
                    {
                        RelativeSizeAxes = Axes.Both,
                        Depth = 2,
                    },
                    judgementLayer = new JudgementContainer<DrawableOsuJudgement>
                    {
                        RelativeSizeAxes = Axes.Both,
                        Depth = 1,
                    },
                    HitObjectContainer,
                    approachCircles = new ApproachCircleProxyContainer
                    {
                        RelativeSizeAxes = Axes.Both,
                        Depth = -1,
                    },
                }
            };
        }

        public override void Add(DrawableHitObject h)
        {
            h.OnNewResult += onNewResult;

            var c = h as IDrawableHitObjectWithProxiedApproach;
            if (c != null)
            {
                var original = c.ProxiedLayer;

                // Hitobjects only have lifetimes set on LoadComplete, so approach circles should not be added until that point
                original.OnLoadComplete += addApproachCircleProxy;
            }

            base.Add(h);
        }

        private void addApproachCircleProxy(Drawable d)
        {
            var proxy = d.CreateProxy();
            proxy.LifetimeStart = d.LifetimeStart;
            proxy.LifetimeEnd = d.LifetimeEnd;
            approachCircles.Add(proxy);
        }

        public override void PostProcess()
        {
            connectionLayer.HitObjects = HitObjectContainer.Objects.Select(d => d.HitObject).OfType<OsuHitObject>();
        }

        private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
        {
            if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
                return;

{'fraction_non_alphanumeric': 0.07145187601957585, 'fraction_numerical': 0.004893964110929853, 'mean_word_length': 1.6702961672473868, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, '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': '3617373', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1526, 'n_words': 345}