diff --git a/Spectrum/Config.cs b/Spectrum/Config.cs index 652b6dc..4ed8673 100644 --- a/Spectrum/Config.cs +++ b/Spectrum/Config.cs @@ -25,7 +25,7 @@ namespace Spectrum _configDirectory = configDirectory; _currentConfigName = Path.GetFileNameWithoutExtension(fileName); _data = new T(); - _availableConfigs = new List(); + _availableConfigs = []; if (!Directory.Exists(_configDirectory)) { @@ -37,7 +37,7 @@ namespace Spectrum LoadConfig(); } - public void LoadConfig(bool silent = false, string filename = "") + public void LoadConfig(string filename = "") { if (string.IsNullOrEmpty(filename)) filename = _defaultFilename; @@ -51,7 +51,6 @@ namespace Spectrum var json = File.ReadAllText(filename); _data = JsonConvert.DeserializeObject(json) ?? new T(); _currentConfigName = Path.GetFileNameWithoutExtension(filename); - if (!silent) LogManager.Log($"Loaded config {filename}.", LogLevel.Info); } catch { @@ -83,7 +82,6 @@ namespace Spectrum { File.WriteAllText(filename, JsonConvert.SerializeObject(_data, Formatting.Indented)); _currentConfigName = Path.GetFileNameWithoutExtension(filename); - LogManager.Log($"Saved config to {filename}.", LogLevel.Info); } catch (Exception ex) { @@ -119,7 +117,7 @@ namespace Spectrum return false; } - LoadConfig(false, filePath); + LoadConfig(filePath); return true; } @@ -165,7 +163,6 @@ namespace Spectrum _directoryWatcher.Changed += OnDirectoryChanged; _directoryWatcher.EnableRaisingEvents = true; - LogManager.Log($"Directory watcher started for {_configDirectory}.", LogLevel.Info); } catch (Exception ex) { @@ -185,7 +182,6 @@ namespace Spectrum _directoryWatcher.Dispose(); _directoryWatcher = null; - LogManager.Log($"Directory watcher stopped for {_configDirectory}.", LogLevel.Info); } private void OnDirectoryChanged(object sender, FileSystemEventArgs e) @@ -213,7 +209,6 @@ namespace Spectrum try { File.Delete(filePath); - LogManager.Log($"Deleted config {configName}.", LogLevel.Info); return true; } catch (Exception ex) @@ -251,7 +246,6 @@ namespace Spectrum File.Move(oldPath, newPath); if (_currentConfigName == oldName) _currentConfigName = newName; - LogManager.Log($"Renamed config from {oldName} to {newName}.", LogLevel.Info); return true; } catch (Exception ex) @@ -271,7 +265,6 @@ namespace Spectrum }; _fileWatcher.Changed += OnConfigFileChanged; _fileWatcher.EnableRaisingEvents = true; - LogManager.Log($"File watcher started for {_defaultFilename}.", LogLevel.Info); } public void StopFileWatcher() @@ -281,7 +274,6 @@ namespace Spectrum _fileWatcher.Changed -= OnConfigFileChanged; _fileWatcher.Dispose(); _fileWatcher = null; - LogManager.Log($"File watcher stopped for {_defaultFilename}.", LogLevel.Info); } private void OnConfigFileChanged(object sender, FileSystemEventArgs e) @@ -289,8 +281,7 @@ namespace Spectrum Thread.Sleep(100); try { - LoadConfig(true); - LogManager.Log($"Configuration reloaded successfully for {_defaultFilename}.", LogLevel.Info); + LoadConfig(); } catch (Exception ex) { diff --git a/Spectrum/Detection/DetectionManager.cs b/Spectrum/Detection/DetectionManager.cs index 1b2a5c7..f6fbb2e 100644 --- a/Spectrum/Detection/DetectionManager.cs +++ b/Spectrum/Detection/DetectionManager.cs @@ -1,5 +1,4 @@ -using ImGuiNET; -using OpenCvSharp; +using OpenCvSharp; using Spectrum.Input; using System.Diagnostics; @@ -70,12 +69,12 @@ namespace Spectrum.Detection Thread.Sleep(2); continue; } - + Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(screenshot); screenshot.Dispose(); - + Mat? drawing = (config.AutoLabel || config.CollectData) ? mat.Clone() : null; - + Cv2.CvtColor(mat, mat, ColorConversionCodes.BGR2HSV); Cv2.InRange(mat, config.LowerHSV, config.UpperHSV, mat); Cv2.Dilate(mat, mat, null, iterations: 2); @@ -95,7 +94,7 @@ namespace Spectrum.Detection double minDistSquared = double.MaxValue; OpenCvSharp.Point[]? closestContour = null; Rect bestRect = default; - + bool shouldDrawDetections = config.DrawDetections && renderer != null; foreach (var contour in processedContours) @@ -107,8 +106,8 @@ namespace Spectrum.Detection int absCenterX = centerX + bounds.X; int absCenterY = centerY + bounds.Y; - - double distSquared = (absCenterX - refX) * (absCenterX - refX) + + + double distSquared = (absCenterX - refX) * (absCenterX - refX) + (absCenterY - refY) * (absCenterY - refY); if (distSquared < minDistSquared) @@ -141,14 +140,14 @@ namespace Spectrum.Detection bestRect.Width, bestRect.Height ); - renderer!.AddRect(_rect, config.TargetColor, 2.0f); + renderer!.AddRect(_rect, config.TargetColor, 1.0f); } int groupX; int groupY; if (config.XPixelOffset) groupX = bestRect.X + config.XOffsetPixels; - else + else groupX = (int)(bestRect.X + bestRect.Width * config.XOffsetPercent); if (config.YPixelOffset) groupY = bestRect.Y + config.YOffsetPixels; @@ -269,7 +268,7 @@ namespace Spectrum.Detection var rect = Cv2.BoundingRect(contours[i]); contourRects.Add((rect, new List { i })); } - + bool merged; do { diff --git a/Spectrum/LogManager.cs b/Spectrum/LogManager.cs index ff7d6e9..7e440b5 100644 --- a/Spectrum/LogManager.cs +++ b/Spectrum/LogManager.cs @@ -88,7 +88,6 @@ namespace Spectrum public static void ClearLog() { _logEntries.Clear(); - Log("Log cleared.", LogLevel.Info); } public static void OpenLogFolder() diff --git a/Spectrum/Program.cs b/Spectrum/Program.cs index 3703d8e..8ce7b7d 100644 --- a/Spectrum/Program.cs +++ b/Spectrum/Program.cs @@ -28,7 +28,6 @@ namespace Spectrum mainConfig.Data.CaptureMethod = CaptureMethod.GDI; } renderer.Run(); - LogManager.Log("Renderer started successfully.", LogManager.LogLevel.Info); } catch (Exception ex) { @@ -41,10 +40,7 @@ namespace Spectrum foreach (var dir in dirs) { if (!Directory.Exists(dir)) - { Directory.CreateDirectory(dir); - LogManager.Log($"Created directory: {dir}", LogManager.LogLevel.Info); - } } mainConfig.LoadConfig(); @@ -60,8 +56,8 @@ namespace Spectrum colorConfig.Data.Colors.Add(new ColorInfo("Arsenal [Magenta]", new Scalar(179, 255, 255), new Scalar(150, 255, 255))); colorConfig.Data.Colors.Add(new ColorInfo("Combat Surf [Red]", new Scalar(0, 255, 255), new Scalar(0, 255, 255))); colorConfig.SaveConfig(); - colorConfig.LoadConfig(true); - mainConfig.LoadConfig(true); + colorConfig.LoadConfig(); + mainConfig.LoadConfig(); } Thread.Sleep(1000); diff --git a/Spectrum/Renderer.HSVRangeWindow.cs b/Spectrum/Renderer.HSVRangeWindow.cs index 3a78985..a995f4f 100644 --- a/Spectrum/Renderer.HSVRangeWindow.cs +++ b/Spectrum/Renderer.HSVRangeWindow.cs @@ -216,7 +216,6 @@ namespace Spectrum else { Program.colorConfig.Data.Colors.Add(new ColorInfo(_colorName, _upperHSV, _lowerHSV)); - LogManager.Log($"Created new color: {_colorName}", LogManager.LogLevel.Info); } Program.colorConfig.SaveConfig(); _colorName = "";