<commit_before>﻿namespace SexyFishHorse.CitiesSkylines.Birdcage
{
    using System;
    using ICities;
    using Infrastructure;
    using Logger;
    using UnityEngine;
    using ILogger = Logger.ILogger;

    public class BirdcageUserMod : UserModBase, IChirperExtension
    {
        public const string ModName = "Birdcage";

        private readonly FilterService filterService;

        private readonly InputService inputService;

        private readonly ILogger logger;

        private readonly PositionService positionService;

        private bool dragging;

        private bool initialized;

        private IChirper chirper;

        public BirdcageUserMod()
        {
            logger = LogManager.Instance.GetOrCreateLogger(ModName);

            filterService = new FilterService();
            inputService = new InputService();
            positionService = new PositionService();

            OptionsPanelManager = new OptionsPanelManager(logger, positionService);
        }

        public override string Description
        {
            get
            {
                return "More Chirper controls";
            }
        }

        public override string Name
        {
            get
            {
                return ModName;
            }
        }

        public AudioClip NotificationSound { get; set; }

        public void OnMessagesUpdated()
        {
        }

        public void OnNewMessage(IChirperMessage message)
        {
            if (ModConfig.Instance.GetSetting<bool>(SettingKeys.FilterMessages))
            {
                filterService.HandleNewMessage(message);
            }
        }

        public void OnCreated(IChirper chirper)
        {
            this.chirper = chirper;
            ((OptionsPanelManager)OptionsPanelManager).Chirper = chirper;
        }

        public void OnReleased()
        {
        }

        public void OnUpdate()
        {
            Initialize();

            try
            {
                if (ChirpPanel.instance == null)
                {
                    return;
                }

                if (ModConfig.Instance.GetSetting<bool>(SettingKeys.FilterMessages))
                {
                    filterService.RemovePendingMessages(NotificationSound);
                }

                if (ModConfig.Instance.GetSetting<bool>(SettingKeys.Draggable))
                {
                    inputService.SetPrimaryMouseButtonDownState();
                    inputService.SetAnyControlDownState();

                    if (dragging && !inputService.PrimaryMouseButtonDownState)
                    {
                        dragging = false;
                        StopDragging();
                    }
                    else if (!dragging && inputService.PrimaryMouseButtonDownState && inputService.AnyControlDown)
                    {
                        if (positionService.IsMouseOnChirper())
                        {
                            dragging = true;
                        }
                    }
                    else if (dragging)
                    {
                        positionService.Dragging();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(ex);
            }
        }

        // TODO: Move this to OnCreated when CO fixes the initial state position mismatch
        private void Initialize()
        {
            if (initialized)
            {
                return;
            }

            positionService.Chirper = chirper;
            positionService.DefaultPosition = chirper.builtinChirperPosition;
            positionService.UiView = ChirpPanel.instance.component.GetUIView();

            NotificationSound = ChirpPanel.instance.m_NotificationSound;

            if (ModConfig.Instance.GetSetting<bool>(SettingKeys.Draggable))
            {
                chirper.SetBuiltinChirperFree(true);

                if (ModConfig.Instance.GetSetting<int>(SettingKeys.ChirperPositionX) > 0)
                {
                    var chirperX = ModConfig.Instance.GetSetting<int>(SettingKeys.ChirperPositionX);
                    var chirperY = ModConfig.Instance.GetSetting<int>(SettingKeys.ChirperPositionY);
                    var chirperPosition = new Vector2(chirperX, chirperY);

                    positionService.UpdateChirperPosition(chirperPosition);
                }
            }

            var hideChirper = ModConfig.Instance.GetSetting<bool>(SettingKeys.HideChirper);
            chirper.ShowBuiltinChirper(!hideChirper);

            initialized = true;
        }

        private void StopDragging()
        {
            positionService.UpdateChirperAnchor();
            positionService.SaveChirperPosition();
        }
    }
}<commit_msg>added more logging for exceptions<commit_after>﻿namespace SexyFishHorse.CitiesSkylines.Birdcage
{
    using System;
    using ICities;
    using Infrastructure;
    using Logger;
    using UnityEngine;
    using ILogger = Logger.ILogger;

    public class BirdcageUserMod : UserModBase, IChirperExtension
    {
        public const string ModName = "Birdcage";

        private readonly FilterService filterService;

        private readonly InputService inputService;

        private readonly ILogger logger;

        private readonly PositionService positionService;

        private bool dragging;

        private bool initialized;

        private IChirper chirperWrapper;

        public BirdcageUserMod()
        {
            logger = LogManager.Instance.GetOrCreateLogger(ModName);

            filterService = new FilterService();
            inputService = new InputService();
            positionService = new PositionService();

            OptionsPanelManager = new OptionsPanelManager(logger, positionService);
        }

        public override string Description
        {
            get
            {
                return "More Chirper controls";
            }
        }

        public override string Name
        {
            get
            {
                return ModName;
            }
        }

        public AudioClip NotificationSound { get; set; }

        public void OnMessagesUpdated()
        {
        }

        public void OnNewMessage(IChirperMessage message)
        {
            try
            {
                if (ModConfig.Instance.GetSetting<bool>(SettingKeys.FilterMessages))
                {
                    filterService.HandleNewMessage(message);
                }
            }
            catch (Exception ex)
            {
                logger.LogException(ex);

                throw;
            }
        }

        public void OnCreated(IChirper chirper)
        {
            try
            {
                chirperWrapper = chirper;
                ((OptionsPanelManager)OptionsPanelManager).Chirper = chirper;
            }
            catch (Exception ex)
            {

                logger.LogException(ex);

                throw;
            }
        }

        public void OnReleased()
        {
        }

        public void OnUpdate()
        {
            try
            {
                Initialize();

                if (ChirpPanel.instance == null)
                {
                    return;
                }

                if (ModConfig.Instance.GetSetting<bool>(SettingKeys.FilterMessages))
                {
                    filterService.RemovePendingMessages(NotificationSound);
                }

                if (ModConfig.Instance.GetSetting<bool>(SettingKeys.Draggable))
                {
                    inputService.SetPrimaryMouseButtonDownState();
                    inputService.SetAnyControlDownState();

                    if (dragging && !inputService.PrimaryMouseButtonDownState)
                    {
                        dragging = false;
                        StopDragging();
                    }
                    else if (!dragging && inputService.PrimaryMouseButtonDownState && inputService.AnyControlDown)
                    {
                        if (positionService.IsMouseOnChirper())
                        {
                            dragging = true;
                        }
                    }
                    else if (dragging)
                    {
                        positionService.Dragging();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(ex);

                throw;
            }
        }

        // TODO: Move this to OnCreated when CO fixes the initial state position mismatch
        private void Initialize()
        {
            if (initialized)
            {
                return;
            }

            positionService.Chirper = chirperWrapper;
            positionService.DefaultPosition = chirperWrapper.builtinChirperPosition;
            positionService.UiView = ChirpPanel.instance.component.GetUIView();

            NotificationSound = ChirpPanel.instance.m_NotificationSound;

            if (ModConfig.Instance.GetSetting<bool>(SettingKeys.Draggable))
            {
                chirperWrapper.SetBuiltinChirperFree(true);

                if (ModConfig.Instance.GetSetting<int>(SettingKeys.ChirperPositionX) > 0)
                {
                    var chirperX = ModConfig.Instance.GetSetting<int>(SettingKeys.ChirperPositionX);
                    var chirperY = ModConfig.Instance.GetSetting<int>(SettingKeys.ChirperPositionY);
                    var chirperPosition = new Vector2(chirperX, chirperY);

                    positionService.UpdateChirperPosition(chirperPosition);
                }
            }

            var hideChirper = ModConfig.Instance.GetSetting<bool>(SettingKeys.HideChirper);
            chirperWrapper.ShowBuiltinChirper(!hideChirper);

            initialized = true;
        }

        private void StopDragging()
        {
            positionService.UpdateChirperAnchor();
            positionService.SaveChirperPosition();
        }
    }
}
{'fraction_non_alphanumeric': 0.0671021377672209, 'fraction_numerical': 0.000395882818685669, 'mean_word_length': 1.3726226813806057, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '4303038', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2261, 'n_words': 425}