<commit_before>﻿using Aurora.EffectsEngine;
using Aurora.EffectsEngine.Animations;
using Aurora.Profiles;
using Aurora.Profiles.Desktop;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Controls;
using Gma.System.MouseKeyHook;

namespace Aurora.Settings.Layers
{
    public class input_item
    {
        public enum input_type
        {
            AnimationMix,
            Spectrum
        };

        public Devices.DeviceKeys key;
        public float progress;
        public bool waitOnKeyUp;
        public AnimationMix animation;
        public ColorSpectrum spectrum;
        public readonly input_type type;

        public input_item(Devices.DeviceKeys key, float progress, bool waitOnKeyUp, AnimationMix animation)
        {
            this.key = key;
            this.progress = progress;
            this.waitOnKeyUp = waitOnKeyUp;
            this.animation = animation;

            type = input_type.AnimationMix;
        }

        public input_item(Devices.DeviceKeys key, float progress, bool waitOnKeyUp, ColorSpectrum spectrum)
        {
            this.key = key;
            this.progress = progress;
            this.waitOnKeyUp = waitOnKeyUp;
            this.spectrum = spectrum;

            type = input_type.Spectrum;
        }
    }

    public class InteractiveLayerHandlerProperties : LayerHandlerProperties2Color<InteractiveLayerHandlerProperties>
    {
        public bool? _RandomPrimaryColor { get; set; }

        [JsonIgnore]
        public bool RandomPrimaryColor { get { return Logic._RandomPrimaryColor ?? _RandomPrimaryColor ?? false; } }

        public bool? _RandomSecondaryColor { get; set; }

        [JsonIgnore]
        public bool RandomSecondaryColor { get { return Logic._RandomSecondaryColor ?? _RandomSecondaryColor ?? false; } }

        public float? _EffectSpeed { get; set; }

        public bool? _WaitOnKeyUp { get; set; }

        [JsonIgnore]
        public bool WaitOnKeyUp { get { return Logic._WaitOnKeyUp ?? _WaitOnKeyUp ?? false; } }

        [JsonIgnore]
        public float EffectSpeed { get { return Logic._EffectSpeed ?? _EffectSpeed ?? 0.0f; } }

        public InteractiveEffects? _InteractiveEffect { get; set; }

        [JsonIgnore]
        public InteractiveEffects InteractiveEffect { get { return Logic._InteractiveEffect ?? _InteractiveEffect ?? InteractiveEffects.None; } }

        public int? _EffectWidth { get; set; }

        [JsonIgnore]
        public int EffectWidth { get { return Logic._EffectWidth ?? _EffectWidth ?? 0; } }

        public InteractiveLayerHandlerProperties() : base() { }

        public InteractiveLayerHandlerProperties(bool assign_default = false) : base(assign_default) { }

        public override void Default()
        {
            base.Default();
            this._RandomPrimaryColor = false;
            this._RandomSecondaryColor = false;
            this._WaitOnKeyUp = false;
            this._EffectSpeed = 1.0f;
            this._InteractiveEffect = InteractiveEffects.None;
            this._EffectWidth = 2;
        }
    }

    public class InteractiveLayerHandler : LayerHandler<InteractiveLayerHandlerProperties>
    {
        private List<input_item> _input_list = new List<input_item>();
        private Keys previous_key = Keys.None;

        private long previoustime = 0;
        private long currenttime = 0;

        private input_item holdKeyInputItem;

        private float getDeltaTime()
        {
            return (currenttime - previoustime) / 1000.0f;
        }

        public InteractiveLayerHandler()
        {
            _ID = "Interactive";

            Global.input_subscriptions.KeyDown += Input_subscriptions_KeyDown;
            Global.input_subscriptions.KeyUp += Input_subscriptions_KeyUp;
        }

        protected override System.Windows.Controls.UserControl CreateControl()
        {
            return new Control_InteractiveLayer(this);
        }

        private void Input_subscriptions_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (Utils.Time.GetMillisecondsSinceEpoch() - previoustime > 1000L)
                return; //This event wasn't used for at least 1 second

            Devices.DeviceKeys deviceKey = Utils.KeyUtils.GetDeviceKey(e.KeyCode, ((KeyEventArgsExt)e).ScanCode, ((KeyEventArgsExt)e).IsExtendedKey);
            foreach (var input in _input_list.ToArray())
            {
                if (input.waitOnKeyUp && input.key == deviceKey)
                    input.waitOnKeyUp = false;
            }

            if (previous_key == e.KeyCode)
                previous_key = Keys.None;
        }

        private Dictionary<Devices.DeviceKeys, long> TimeOfLastPress = new Dictionary<Devices.DeviceKeys, long>();
        private const long pressBuffer = 300L;

        private void Input_subscriptions_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (Utils.Time.GetMillisecondsSinceEpoch() - previoustime > 1000L)
                return; //This event wasn't used for at least 1 second


            if (previous_key == e.KeyCode)
                return;

            long? currentTime = null;
            Devices.DeviceKeys device_key = Utils.KeyUtils.GetDeviceKey(e.KeyCode, ((KeyEventArgsExt)e).ScanCode, ((KeyEventArgsExt)e).IsExtendedKey);

            lock (TimeOfLastPress)
            {
                if (TimeOfLastPress.ContainsKey(device_key))
                {
                    if ((currentTime = Utils.Time.GetMillisecondsSinceEpoch()) - TimeOfLastPress[device_key] < pressBuffer)
                        return;
                    else
                        TimeOfLastPress.Remove(device_key);
                }
            }<commit_msg>Added check for DeviceKeys.NONE<commit_after>﻿using Aurora.EffectsEngine;
using Aurora.EffectsEngine.Animations;
using Aurora.Profiles;
using Aurora.Profiles.Desktop;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Controls;
using Gma.System.MouseKeyHook;

namespace Aurora.Settings.Layers
{
    public class input_item
    {
        public enum input_type
        {
            AnimationMix,
            Spectrum
        };

        public Devices.DeviceKeys key;
        public float progress;
        public bool waitOnKeyUp;
        public AnimationMix animation;
        public ColorSpectrum spectrum;
        public readonly input_type type;

        public input_item(Devices.DeviceKeys key, float progress, bool waitOnKeyUp, AnimationMix animation)
        {
            this.key = key;
            this.progress = progress;
            this.waitOnKeyUp = waitOnKeyUp;
            this.animation = animation;

            type = input_type.AnimationMix;
        }

        public input_item(Devices.DeviceKeys key, float progress, bool waitOnKeyUp, ColorSpectrum spectrum)
        {
            this.key = key;
            this.progress = progress;
            this.waitOnKeyUp = waitOnKeyUp;
            this.spectrum = spectrum;

            type = input_type.Spectrum;
        }
    }

    public class InteractiveLayerHandlerProperties : LayerHandlerProperties2Color<InteractiveLayerHandlerProperties>
    {
        public bool? _RandomPrimaryColor { get; set; }

        [JsonIgnore]
        public bool RandomPrimaryColor { get { return Logic._RandomPrimaryColor ?? _RandomPrimaryColor ?? false; } }

        public bool? _RandomSecondaryColor { get; set; }

        [JsonIgnore]
        public bool RandomSecondaryColor { get { return Logic._RandomSecondaryColor ?? _RandomSecondaryColor ?? false; } }

        public float? _EffectSpeed { get; set; }

        public bool? _WaitOnKeyUp { get; set; }

        [JsonIgnore]
        public bool WaitOnKeyUp { get { return Logic._WaitOnKeyUp ?? _WaitOnKeyUp ?? false; } }

        [JsonIgnore]
        public float EffectSpeed { get { return Logic._EffectSpeed ?? _EffectSpeed ?? 0.0f; } }

        public InteractiveEffects? _InteractiveEffect { get; set; }

        [JsonIgnore]
        public InteractiveEffects InteractiveEffect { get { return Logic._InteractiveEffect ?? _InteractiveEffect ?? InteractiveEffects.None; } }

        public int? _EffectWidth { get; set; }

        [JsonIgnore]
        public int EffectWidth { get { return Logic._EffectWidth ?? _EffectWidth ?? 0; } }

        public InteractiveLayerHandlerProperties() : base() { }

        public InteractiveLayerHandlerProperties(bool assign_default = false) : base(assign_default) { }

        public override void Default()
        {
            base.Default();
            this._RandomPrimaryColor = false;
            this._RandomSecondaryColor = false;
            this._WaitOnKeyUp = false;
            this._EffectSpeed = 1.0f;
            this._InteractiveEffect = InteractiveEffects.None;
            this._EffectWidth = 2;
        }
    }

    public class InteractiveLayerHandler : LayerHandler<InteractiveLayerHandlerProperties>
    {
        private List<input_item> _input_list = new List<input_item>();
        private Keys previous_key = Keys.None;

        private long previoustime = 0;
        private long currenttime = 0;

        private input_item holdKeyInputItem;

        private float getDeltaTime()
        {
            return (currenttime - previoustime) / 1000.0f;
        }

        public InteractiveLayerHandler()
        {
            _ID = "Interactive";

            Global.input_subscriptions.KeyDown += Input_subscriptions_KeyDown;
            Global.input_subscriptions.KeyUp += Input_subscriptions_KeyUp;
        }

        protected override System.Windows.Controls.UserControl CreateControl()
        {
            return new Control_InteractiveLayer(this);
        }

        private void Input_subscriptions_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (Utils.Time.GetMillisecondsSinceEpoch() - previoustime > 1000L)
                return; //This event wasn't used for at least 1 second

            Devices.DeviceKeys deviceKey = Utils.KeyUtils.GetDeviceKey(e.KeyCode, ((KeyEventArgsExt)e).ScanCode, ((KeyEventArgsExt)e).IsExtendedKey);
            if(deviceKey != Devices.DeviceKeys.NONE)
            {
                foreach (var input in _input_list.ToArray())
                {
                    if (input.waitOnKeyUp && input.key == deviceKey)
                        input.waitOnKeyUp = false;
                }
            }

            if (previous_key == e.KeyCode)
                previous_key = Keys.None;
        }

        private Dictionary<Devices.DeviceKeys, long> TimeOfLastPress = new Dictionary<Devices.DeviceKeys, long>();
        private const long pressBuffer = 300L;

        private void Input_subscriptions_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (Utils.Time.GetMillisecondsSinceEpoch() - previoustime > 1000L)
                return; //This event wasn't used for at least 1 second


            if (previous_key == e.KeyCode)
                return;

            long? currentTime = null;
            Devices.DeviceKeys device_key = Utils.KeyUtils.GetDeviceKey(e.KeyCode, ((KeyEventArgsExt)e).ScanCode, ((KeyEventArgsExt)e).IsExtendedKey);

            lock (TimeOfLastPress)
            {
                if (TimeOfLastPress.ContainsKey(device_key))
                {
                    if ((currentTime = Utils.Time.GetMillisecondsSinceEpoch()) - TimeOfLastPress[device_key] < pressBuffer)
                        return;
                    else
                        TimeOfLastPress.Remove(device_key);
                }
            }
{'fraction_non_alphanumeric': 0.07952736109947205, 'fraction_numerical': 0.0045252660688846055, 'mean_word_length': 2.237655995659251, 'pattern_counts': {'":': 0, '<': 17, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542712', 'n_tokens_mistral': 3231, 'n_tokens_neox': 2995, 'n_words': 711}