<commit_before>﻿using System;
using System.Windows.Threading;
using TCC.Test;

namespace TCC
{
    public class ForegroundManager
    {
        private readonly DispatcherTimer _dimTimer;

        public bool ForceUndim
        {
            get => _forceUndim;
            set
            {
                if (_forceUndim == value) return;
                _forceUndim = value;
                NotifyDimChanged();
            }
        }

        private bool _forceVisible = Tester.Enabled;
        private bool _forceUndim = Tester.Enabled;
        public event Action VisibilityChanged;
        public event Action DimChanged;
        public event Action ClickThruChanged;

        public ForegroundManager()
        {
            Game.LoadingScreenChanged += NotifyVisibilityChanged;
            Game.LoggedChanged += NotifyVisibilityChanged;
            Game.EncounterChanged += NotifyDimChanged;
            Game.GameUiModeChanged += OnGameUiModeChanged;
            Game.SkillStarted += OnSkillStarted;

            FocusManager.ForegroundChanged += NotifyVisibilityChanged;

            _dimTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
            _dimTimer.Tick += (_, __) =>
            {
                _dimTimer.Stop();
                NotifyDimChanged();
            };
        }

        private void OnGameUiModeChanged()
        {
            App.BaseDispatcher.Invoke(() => ClickThruChanged?.Invoke());
        }

        private void OnSkillStarted()
        {
            _dimTimer.Stop();
            _dimTimer.Start();
            NotifyDimChanged();
        }

        private void NotifyVisibilityChanged()
        {
            App.BaseDispatcher?.BeginInvoke(new Action(() =>
                VisibilityChanged?.Invoke()), DispatcherPriority.Background);
        }

        private void NotifyDimChanged()
        {
            App.BaseDispatcher?.BeginInvoke(new Action(() =>
                DimChanged?.Invoke()), DispatcherPriority.Background);
        }


        public bool Dim => !_dimTimer.IsEnabled &&
                                !Game.Encounter &&
                                !ForceUndim;

        public bool Visible => Game.Logged &&
                               !Game.LoadingScreen &&
                                FocusManager.IsForeground ||
                                _forceVisible;

        public bool ForceVisible
        {
            get => _forceVisible;
            set
            {
                if (_forceVisible == value) return;
                _forceVisible = value;
                NotifyVisibilityChanged();
            }
        }

        public void RefreshDim()
        {
            if (App.Loading) return;
            App.BaseDispatcher?.Invoke(() =>
        {
            ForceUndim = true;
            DimChanged?.Invoke();
            ForceUndim = false;
            DimChanged?.Invoke();<commit_msg>fix visibility when testing<commit_after>﻿using System;
using System.Windows.Threading;
using TCC.Test;

namespace TCC
{
    public class ForegroundManager
    {
        private readonly DispatcherTimer _dimTimer;

        public bool ForceUndim
        {
            get => _forceUndim;
            set
            {
                if (_forceUndim == value) return;
                _forceUndim = value;
                NotifyDimChanged();
            }
        }

        private bool _forceVisible = Tester.Enabled;
        private bool _forceUndim = Tester.Enabled;
        public event Action VisibilityChanged;
        public event Action DimChanged;
        public event Action ClickThruChanged;

        public ForegroundManager()
        {
            Game.LoadingScreenChanged += NotifyVisibilityChanged;
            Game.LoggedChanged += NotifyVisibilityChanged;
            Game.EncounterChanged += NotifyDimChanged;
            Game.GameUiModeChanged += OnGameUiModeChanged;
            Game.SkillStarted += OnSkillStarted;

            FocusManager.ForegroundChanged += NotifyVisibilityChanged;

            _dimTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
            _dimTimer.Tick += (_, __) =>
            {
                _dimTimer.Stop();
                NotifyDimChanged();
            };
        }

        private void OnGameUiModeChanged()
        {
            App.BaseDispatcher.Invoke(() => ClickThruChanged?.Invoke());
        }

        private void OnSkillStarted()
        {
            _dimTimer.Stop();
            _dimTimer.Start();
            NotifyDimChanged();
        }

        private void NotifyVisibilityChanged()
        {
            App.BaseDispatcher?.BeginInvoke(new Action(() =>
                VisibilityChanged?.Invoke()), DispatcherPriority.Background);
        }

        private void NotifyDimChanged()
        {
            App.BaseDispatcher?.BeginInvoke(new Action(() =>
                DimChanged?.Invoke()), DispatcherPriority.Background);
        }


        public bool Dim => !_dimTimer.IsEnabled &&
                                !Game.Encounter &&
                                !ForceUndim;

        public bool Visible => Game.Logged &&
                               !Game.LoadingScreen &&
                                FocusManager.IsForeground ||
                                Tester.Enabled;

        public bool ForceVisible
        {
            get => _forceVisible;
            set
            {
                if (_forceVisible == value) return;
                _forceVisible = value;
                NotifyVisibilityChanged();
            }
        }

        public void RefreshDim()
        {
            if (App.Loading) return;
            App.BaseDispatcher?.Invoke(() =>
        {
            ForceUndim = true;
            DimChanged?.Invoke();
            ForceUndim = false;
            DimChanged?.Invoke();
{'fraction_non_alphanumeric': 0.08280473169895422, 'fraction_numerical': 0.0003428767358134751, 'mean_word_length': 1.4522908785203867, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4911985', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1328, 'n_words': 270}