Refactor Input Validators

This commit is contained in:
copecone committed 2026-07-07 15:59:53 +09:00
1 parent d79ff3333a
commit 367049384a
2 files changed
+6 -18

No files matched your search

+3 -9
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using MelonLoader; using MelonLoader;
using UnityEngine.UIElements; using UnityEngine.UIElements;
@@ -46,11 +47,8 @@ namespace ADOFAIRenderer.Data
/// </summary> /// </summary>
public void SetupValidation() 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<DoubleField>(fieldName); var field = _rootVisualElement.Q<DoubleField>(fieldName);
if (field == null) if (field == null)
{ {
@@ -68,13 +66,9 @@ namespace ADOFAIRenderer.Data
return; 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); field.SetValueWithoutNotify(evt.previousValue);
return;
}
} }
}); });
} }
+3 -9
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using MelonLoader; using MelonLoader;
using UnityEngine.UIElements; using UnityEngine.UIElements;
@@ -46,11 +47,8 @@ namespace ADOFAIRenderer.Data
/// </summary> /// </summary>
public void SetupValidation() 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<IntegerField>(fieldName); var field = _rootVisualElement.Q<IntegerField>(fieldName);
if (field == null) if (field == null)
{ {
@@ -68,13 +66,9 @@ namespace ADOFAIRenderer.Data
return; 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); field.SetValueWithoutNotify(evt.previousValue);
return;
}
} }
}); });
} }