From 367049384aef03190b4313f201065d2a4558337a29b696e5bdcf3afdbccca663 Mon Sep 17 00:00:00 2001 From: copecone Date: Tue, 7 Jul 2026 15:59:53 +0900 Subject: [PATCH] Refactor Input Validators --- Data/DoubleInputValidator.cs | 14 ++++---------- Data/IntegerInputValidator.cs | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Data/DoubleInputValidator.cs b/Data/DoubleInputValidator.cs index dac92cc..7cd8a3b 100644 --- a/Data/DoubleInputValidator.cs +++ b/Data/DoubleInputValidator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using MelonLoader; using UnityEngine.UIElements; @@ -46,11 +47,8 @@ namespace ADOFAIRenderer.Data /// public void SetupValidation() { - foreach (var kvp in _fields) + foreach (var (fieldName, entry) in _fields) { - var fieldName = kvp.Key; - var entry = kvp.Value; - var field = _rootVisualElement.Q(fieldName); if (field == null) { @@ -68,13 +66,9 @@ namespace ADOFAIRenderer.Data return; } - foreach (var limit in limits) + if (limits.Any(limit => !limit.Validate(evt.newValue, out _))) { - if (!limit.Validate(evt.newValue, out _)) - { - field.SetValueWithoutNotify(evt.previousValue); - return; - } + field.SetValueWithoutNotify(evt.previousValue); } }); } diff --git a/Data/IntegerInputValidator.cs b/Data/IntegerInputValidator.cs index 85b006d..5c6b726 100644 --- a/Data/IntegerInputValidator.cs +++ b/Data/IntegerInputValidator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using MelonLoader; using UnityEngine.UIElements; @@ -46,11 +47,8 @@ namespace ADOFAIRenderer.Data /// public void SetupValidation() { - foreach (var kvp in _fields) + foreach (var (fieldName, entry) in _fields) { - var fieldName = kvp.Key; - var entry = kvp.Value; - var field = _rootVisualElement.Q(fieldName); if (field == null) { @@ -68,13 +66,9 @@ namespace ADOFAIRenderer.Data return; } - foreach (var limit in limits) + if (limits.Any(limit => !limit.Validate(evt.newValue, out _))) { - if (!limit.Validate(evt.newValue, out _)) - { - field.SetValueWithoutNotify(evt.previousValue); - return; - } + field.SetValueWithoutNotify(evt.previousValue); } }); }