Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from techno-dwarf-works/feature/clean-up
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
uurha authored Mar 8, 2024
2 parents 3b72a85 + f48b5c4 commit bc922e7
Show file tree
Hide file tree
Showing 78 changed files with 624 additions and 474 deletions.
8 changes: 8 additions & 0 deletions Assets/Better/Validation/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Assets/Better/Validation/Resources/ValidationSettings.asset

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions Assets/BetterValidation/Editor/BetterValidation.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"name": "Better.Validation.Editor",
"rootNamespace": "Better.Validation",
"name": "BetterValidation.Editor",
"rootNamespace": "Better.Validation.EditorAddons",
"references": [
"GUID:441b78e90a9cf724ab41c6eed8c0b93d",
"GUID:19891d5296046644cbc12fcf3702cca3",
"GUID:01df13aca8d01e24a911bcc3e8277031",
"GUID:443314a5a4e67c14a88ae223776b6554",
"GUID:1ac867a6259e45a1856740fe8f7623aa",
"GUID:28da8d3b12e3efa47928e0c9070f853d",
"GUID:a59e3daedde9ca94bba45364d4ead25f"
"GUID:19891d5296046644cbc12fcf3702cca3",
"GUID:a59e3daedde9ca94bba45364d4ead25f",
"GUID:ecdd0819e3429eb44b13a432679a1135",
"GUID:1862b35041b066d42ab4d3caf773657b",
"GUID:af7fffdf1d83bc842b0f6e3a01efda16",
"GUID:441b78e90a9cf724ab41c6eed8c0b93d"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Better.Validation.EditorAddons.Utilities;
using Better.Singletons.Runtime;
using Better.Validation.EditorAddons.Utility;
using UnityEditor;
using UnityEngine;

namespace Better.Validation.EditorAddons.ContextResolver
{
public class AssetResolver : IContextResolver
public class AssetPathResolver : PocoSingleton<AssetPathResolver>, IPathResolver
{
public static IContextResolver Instance { get; } = new AssetResolver();

public string Resolve(Object obj)
{
if (obj is GameObject gameObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Better.Validation.EditorAddons.ContextResolver
{
public interface IContextResolver
public interface IPathResolver
{
public string Resolve(Object obj);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Better.Validation.EditorAddons.Utilities;
using Better.Singletons.Runtime;
using Better.Validation.EditorAddons.Utility;
using UnityEngine;

namespace Better.Validation.EditorAddons.ContextResolver
{
public class SceneResolver : IContextResolver
public class SceneResolver : PocoSingleton<SceneResolver>, IPathResolver
{
public static IContextResolver Instance { get; } = new SceneResolver();

public string Resolve(Object obj)
{
return obj.FullPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;
using Better.EditorTools.Attributes;
using Better.EditorTools.Drawers.Base;
using Better.EditorTools.Helpers;
using Better.EditorTools.Helpers.Caching;
using Better.Tools.Runtime.Attributes;
using Better.Validation.EditorAddons.Utilities;
using Better.EditorTools.EditorAddons.Attributes;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.EditorTools.EditorAddons.Helpers;
using Better.EditorTools.EditorAddons.Helpers.Caching;
using Better.EditorTools.Runtime.Attributes;
using Better.Validation.EditorAddons.Utility;
using Better.Validation.EditorAddons.Wrappers;
using Better.Validation.Runtime.Attributes;
using UnityEditor;
Expand All @@ -15,15 +15,15 @@ namespace Better.Validation.EditorAddons.Drawers
[MultiCustomPropertyDrawer(typeof(ValidationAttribute))]
public class ValidationDrawer : MultiFieldDrawer<PropertyValidationWrapper>
{
private Cache<MutableTuple<string, ValidationType>> _validationResult = new Cache<MutableTuple<string, ValidationType>>();
private CacheValue<MutableTuple<string, ValidationType>> _validationResult = new CacheValue<MutableTuple<string, ValidationType>>();

public ValidationDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute)
{
}

protected override bool PreDraw(ref Rect position, SerializedProperty property, GUIContent label)
{
var cache = ValidateCachedProperties(property, ValidationUtility.Instance);
var cache = ValidateCachedProperties(property, ValidationAttributeUtility.Instance);
var validationWrapper = cache.Value;
var wrapper = validationWrapper.Wrapper;
if (!cache.IsValid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class IterationData
{
public Object Target { get; private set; }

public IContextResolver ContextResolver { get; private set; }
public IPathResolver PathResolver { get; private set; }

public SerializedProperty Property { get; private set; }
public SerializedObject Context { get; private set; }


public void SetResolver(IContextResolver context)
public void SetResolver(IPathResolver path)
{
ContextResolver = context;
PathResolver = path;
}

public void SetTarget(Object target)
Expand Down
28 changes: 16 additions & 12 deletions Assets/BetterValidation/Editor/EditorAddons/Iteration/Iterator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Better.Extensions.Runtime;
using Better.Validation.EditorAddons.ContextResolver;
using Better.Validation.EditorAddons.Utilities;
using Better.Validation.EditorAddons.Utility;
using Better.Validation.EditorAddons.Wrappers;
using UnityEditor;
using UnityEngine;
Expand All @@ -9,21 +10,26 @@ namespace Better.Validation.EditorAddons.Iteration
{
public static class Iterator
{
private static IContextResolver _context;
private static IPathResolver _path;
private static readonly IterationData CacheData = new IterationData();

public delegate IEnumerable<ValidationCommandData> OnPropertyIteration(IterationData commandData);

public static void SetContext(IContextResolver context)
public static void SetContext(IPathResolver path)
{
_context = context;
CacheData.SetResolver(context);
_path = path;
CacheData.SetResolver(path);
}

public static List<ValidationCommandData> ObjectIteration(Object go, OnPropertyIteration onPropertyIteration)
public static List<ValidationCommandData> ObjectIteration(Object reference, OnPropertyIteration onPropertyIteration)
{
var gameObject = go as GameObject;
var components = gameObject ? gameObject.GetComponents<Component>() : new[] { go };
if (reference.IsNullOrDestroyed())
{
return new List<ValidationCommandData>();
}

var gameObject = reference as GameObject;
var components = gameObject ? gameObject.GetComponents<Component>() : new[] { reference };

var commandData = new List<ValidationCommandData>();
EditorUtility.DisplayProgressBar("Validating components...", "", 0);
Expand All @@ -32,9 +38,9 @@ public static List<ValidationCommandData> ObjectIteration(Object go, OnPropertyI
var obj = components[index];
if (!obj)
{
CacheData.SetTarget(go);
CacheData.SetTarget(reference);
var missingReference = new ValidationCommandData(CacheData, new MissingComponentWrapper(gameObject));
missingReference.SetResultCompiler((data, result) => $"Missing Component on GameObject: {_context.Resolve(data.Target)}");
missingReference.SetResultCompiler((data, result) => $"Missing Component on GameObject: {_path.Resolve(data.Target)}");
missingReference.Revalidate();
commandData.Add(missingReference);
continue;
Expand Down Expand Up @@ -86,7 +92,5 @@ public static List<ValidationCommandData> ObjectsIteration(IReadOnlyList<Object>
EditorUtility.ClearProgressBar();
return list;
}


}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System.Collections.Generic;
using Better.EditorTools;
using Better.EditorTools.Drawers.Base;
using Better.EditorTools.Helpers.Caching;
using System.Text;
using Better.EditorTools.EditorAddons.Drawers.Base;
using Better.EditorTools.EditorAddons.Helpers.Caching;
using Better.Extensions.EditorAddons;
using Better.Extensions.Runtime;
using Better.Validation.EditorAddons.Utilities;
using Better.Validation.EditorAddons.Utility;
using Better.Validation.EditorAddons.Wrappers;
using Better.Validation.Runtime.Attributes;

namespace Better.Validation.EditorAddons.Iteration
{
public static class IteratorFilter
{
private class LocalCache : Cache<WrapperCollectionValue<PropertyValidationWrapper>>
private class LocalCache : CacheValue<WrapperCollectionValue<PropertyValidationWrapper>>
{
}

Expand All @@ -26,11 +27,16 @@ public static IEnumerable<ValidationCommandData> PropertyIterationWithAttributes
var list = data.Property.GetAttributes<ValidationAttribute>();
if (fieldInfo == null || list == null) return null;

var fieldType = fieldInfo.FieldInfo.GetFieldOrElementType();
var fieldType = fieldInfo.FieldInfo.FieldType;
if (fieldType.IsArrayOrList())
{
fieldType = fieldType.GetCollectionElementType();
}

var dataList = new List<ValidationCommandData>();
foreach (var validationAttribute in list)
{
Wrappers.ValidateCachedProperties(CacheField, data.Property, fieldType, validationAttribute.GetType(), ValidationUtility.Instance);
ValidateCachedPropertiesUtility.Validate(Wrappers, CacheField, data.Property, fieldType, validationAttribute.GetType(), ValidationAttributeUtility.Instance);

var fieldValue = CacheField.Value;
if (fieldValue == null)
Expand Down Expand Up @@ -81,10 +87,17 @@ private static string ObjectCompiler(ValidationCommandData commandData, string r
var property = commandData.Property;
var path = property.IsArrayElement() ? property.GetArrayPath() : property.displayName;
var target = commandData.Target;
var str =
$"Validation failed with: <b>{result}</b>.\nPath: <i><b>{commandData.ContextResolver.Resolve(target)}</b></i>. Component: <i><b>{target.GetType().Name}</b></i>, Property: <i><b>{path}</b></i>";

return str;
var resolvedPath = commandData.PathResolver.Resolve(target);
var typeName = target.GetType().Name;

var stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("Validation failed with: <b>{0}</b>.", result);
stringBuilder.AppendLine();
stringBuilder.AppendFormat("Path: <i><b>{0}</b></i>.", resolvedPath);
stringBuilder.AppendLine();
stringBuilder.AppendFormat("Component: <i><b>{0}</b></i>, Property: <i><b>{1}</b></i>", typeName, path);

return stringBuilder.ToString();
}
}
}
2 changes: 1 addition & 1 deletion Assets/BetterValidation/Editor/EditorAddons/MenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Better.Validation.EditorAddons
{
public static class MenuItems
{
[MenuItem(ValidationSettingsTool.MenuItemPrefix + "/Open Validation Window", false, 50)]
[MenuItem(ValidationSettingProvider.Path + "/Open Validation Window", false, 50)]
private static void ValidateInProject()
{
ValidationWindow.OpenWindow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;

namespace Better.Validation.EditorAddons.PreBuildValidation.Interfaces
namespace Better.Validation.EditorAddons.PreBuildValidation
{
public interface IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData();
public List<ValidationCommandData> GatherValidationData(ValidatorCommands commands);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;

namespace Better.Validation.EditorAddons.PreBuildValidation
{
[Serializable]
public class AllSceneValidationStep : IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData(ValidatorCommands commands)
{
return commands.ValidateAttributesInAllScenes();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
using System;
using System.Collections.Generic;
using Better.Validation.EditorAddons.PreBuildValidation.Interfaces;

namespace Better.Validation.EditorAddons.PreBuildValidation.Models
namespace Better.Validation.EditorAddons.PreBuildValidation
{
[Serializable]
public class ProjectValidationStep : IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData()
public List<ValidationCommandData> GatherValidationData(ValidatorCommands commands)
{
var commands = new ValidatorCommands();
return commands.ValidateAttributesInProject();
}
}

[Serializable]
public class AllSceneValidationStep : IBuildValidationStep
{
public List<ValidationCommandData> GatherValidationData()
{
var commands = new ValidatorCommands();
return commands.ValidateAttributesInAllScenes();
}
}
}
Loading

0 comments on commit bc922e7

Please sign in to comment.