Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All package updates & migration steps will be listed in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.3.0] - 2024-11-22
### Added
- `Warning` and `Error` severity levels for `ValidatorError`
- Updated UI to display and filter warnings & errors.
- Some missing coverage.
- Built-in warnings for slow validation execution.
### Changed
- Only mark data generation as an error for `ValidaitonError` with severity error.
- Missing validators are considered warnings. This reduces the noisiness of compilation errors causing this.
- Do not force open the Validation window for warnings.

## [4.2.1] - 2024-11-19
### Fixed
- Issue where nested structs in scriptable object drawers have glitching UI.
Expand Down
6 changes: 6 additions & 0 deletions Editor/Common/Util/ParameterDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public static void LogVerbose(string log)
/// <param name="log">String to log</param>
public static void LogError(string log) => Debug.LogError(log);

/// <summary>
/// Warning logs to the console.
/// </summary>
/// <param name="log">String to log</param>
public static void LogWarning(string log) => Debug.LogWarning(log);

/// <summary>
/// Logs to the console.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Editor/DataGeneration/Operation/DataOperationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using PocketGems.Parameters.Common.Models.Editor;
using PocketGems.Parameters.Common.Operation.Editor;
using PocketGems.Parameters.DataGeneration.LocalCSV.Editor;
using PocketGems.Parameters.Validation;

namespace PocketGems.Parameters.DataGeneration.Operation.Editor
{
Expand All @@ -14,6 +15,7 @@ public DataOperationContext()
InfoCSVFileCache = new InfoCSVFileCache(GeneratedLocalCSVDirectory, true);
StructCSVFileCache = new StructCSVFileCache(GeneratedLocalCSVDirectory, true);
ScriptableObjectMetadatas = new Dictionary<IParameterInfo, List<IScriptableObjectMetadata>>();
AllValidationErrors = new();
}

public GenerateDataType GenerateDataType { get; set; }
Expand All @@ -36,5 +38,7 @@ public DataOperationContext()
#endif
public Dictionary<IParameterInfo, List<IScriptableObjectMetadata>> ScriptableObjectMetadatas { get; }
public List<string> GeneratedFilePaths { get; }

public List<ValidationError> AllValidationErrors { get; }
}
}
6 changes: 6 additions & 0 deletions Editor/DataGeneration/Operation/IDataOperationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using PocketGems.Parameters.Common.Models.Editor;
using PocketGems.Parameters.Common.Operation.Editor;
using PocketGems.Parameters.DataGeneration.LocalCSV.Editor;
using PocketGems.Parameters.Validation;

namespace PocketGems.Parameters.DataGeneration.Operation.Editor
{
Expand Down Expand Up @@ -41,5 +42,10 @@ public interface IDataOperationContext : ICommonOperationContext
/// Asset files that were generated through this data generation
/// </summary>
List<string> GeneratedFilePaths { get; }

/// <summary>
/// Validation errors & warnings
/// </summary>
List<ValidationError> AllValidationErrors { get; }
}
}
14 changes: 12 additions & 2 deletions Editor/DataGeneration/Operations/DataValidationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ public override void Execute(IDataOperationContext context)
// validate assets
var assetErrors = AssetValidator.ValidateScriptableObjects(context.ScriptableObjectMetadatas);
for (int i = 0; i < assetErrors?.Count; i++)
Error(assetErrors[i]);
{
var validationError = assetErrors[i];
context.AllValidationErrors.Add(validationError);
if (validationError.ErrorSeverity == ValidationError.Severity.Error)
Error(assetErrors[i]);
}

// validate parameters
IParameterManager parameterManager = EditorParams.ParameterManager;
var parameterErrors = InvokeParamsValidation(context, parameterManager);
for (int i = 0; i < parameterErrors?.Count; i++)
Error(parameterErrors[i]);
{
var validationError = parameterErrors[i];
context.AllValidationErrors.Add(validationError);
if (validationError.ErrorSeverity == ValidationError.Severity.Error)
Error(parameterErrors[i]);
}
}

/// <summary>
Expand Down
73 changes: 60 additions & 13 deletions Editor/Editor/ParameterScriptableObjectInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,38 @@ protected void DrawParameterToolGUI()
EditorGUILayout.Space();
}

#region hack for backwards compatibility

private static string warningMessageHolder = null;

[Obsolete]
private void InternalDrawProperty(SerializedProperty property, string errorMessage = null, string warningMessage = null)
{
warningMessageHolder = warningMessage;
DrawProperty(property, errorMessage);
}

[Obsolete]
protected virtual void DrawProperty(SerializedProperty property, string errorMessage = null)
{
DrawProperty(property, errorMessage, warningMessageHolder);
}

#endregion

/// <summary>
/// Allow for subclasses to draw custom visualizers for the property
/// </summary>
/// <param name="property">property to render</param>
/// <param name="errorMessage">error message to show if any</param>
protected virtual void DrawProperty(SerializedProperty property, string errorMessage = null)
protected virtual void DrawProperty(SerializedProperty property, string errorMessage = null, string warningMessage = null)
{
var propLabel = new GUIContent(property.displayName);
EditorGUILayout.PropertyField(property, propLabel, true);
if (errorMessage != null)
EditorGUILayout.HelpBox(errorMessage, MessageType.Error);
if (warningMessage != null)
EditorGUILayout.HelpBox(warningMessage, MessageType.Warning);
}

public override void OnInspectorGUI()
Expand Down Expand Up @@ -147,8 +168,8 @@ public override void OnInspectorGUI()
errors.Add(error);
}

// collect properties & errors
List<(SerializedProperty, string)> properties = new();
// collect properties, errors & warnings
List<(SerializedProperty, string, string)> properties = new();
// call to ensure the values are up to date with the target in case it was modified in another inspector/drawer
serializedObject.Update();
var serializedProp = serializedObject.GetIterator();
Expand All @@ -159,17 +180,28 @@ public override void OnInspectorGUI()
// don't draw class file
if (serializedProp.name == "m_Script") continue;
var interfacePropertyGetterName = GetPropertyGetterName(serializedProp);
string errorMessage = null;
StringBuilder errorMessage = null;
StringBuilder warningMessage = null;
if (_propertyToError.ContainsKey(interfacePropertyGetterName))
{
StringBuilder s = new StringBuilder();
s.Append($"{interfacePropertyGetterName} Validation Error(s):");
var propertyErrors = _propertyToError[interfacePropertyGetterName];
_propertyToError.Remove(interfacePropertyGetterName);
for (int i = 0; i < propertyErrors.Count; i++)
{
StringBuilder s;
var error = propertyErrors[i];
s.AppendLine();
if (error.ErrorSeverity == ValidationError.Severity.Error)
{
errorMessage ??= new();
s = errorMessage;
}
else
{
warningMessage ??= new();
s = warningMessage;
}
if (s.Length != 0)
s.AppendLine();
s.Append(" ");
if (!string.IsNullOrEmpty(error.StructKeyPath))
{
Expand All @@ -190,29 +222,43 @@ public override void OnInspectorGUI()
}
s.Append($"{error.Message}");
}

errorMessage = s.ToString();
}
properties.Add((serializedProp.Copy(), errorMessage));
properties.Add((serializedProp.Copy(), errorMessage?.ToString(), warningMessage?.ToString()));
}

// display missing maps (shouldn't ever happen but just in case...)
if (_propertyToError.Count != 0)
{
StringBuilder s = new StringBuilder("Unexpected Errors:");
StringBuilder errorMessage = null;
StringBuilder warningMessage = null;
foreach (var kvp in _propertyToError)
{
var errors = kvp.Value;
for (int i = 0; i < errors.Count; i++)
{
StringBuilder s;
var error = errors[i];
if (error.ErrorSeverity == ValidationError.Severity.Error)
{
errorMessage ??= new("Unexpected Error(s):");
s = errorMessage;
}
else
{
warningMessage ??= new("Unexpected Warning(s):");
s = warningMessage;
}
s.AppendLine();
if (!string.IsNullOrEmpty(errors[i].InfoProperty))
s.Append($"{errors[i].InfoProperty}: ");
s.Append(errors[i].Message);
}
}
EditorGUILayout.Space();
EditorGUILayout.HelpBox(s.ToString(), MessageType.Error);
if (errorMessage != null)
EditorGUILayout.HelpBox(errorMessage.ToString(), MessageType.Error);
if (warningMessage != null)
EditorGUILayout.HelpBox(warningMessage.ToString(), MessageType.Warning);
EditorGUILayout.Space();
}

Expand All @@ -227,6 +273,7 @@ public override void OnInspectorGUI()
{
serializedProp = properties[i].Item1;
var errorMessage = properties[i].Item2;
var warningMessage = properties[i].Item3;

// don't draw class file
if (serializedProp.name == "m_Script") continue;
Expand Down Expand Up @@ -255,7 +302,7 @@ public override void OnInspectorGUI()

// draw property
if (foldOutAttribute == null || isFoldoutOpen)
DrawProperty(serializedProp, errorMessage);
InternalDrawProperty(serializedProp, errorMessage, warningMessage);
}
scope?.Dispose();

Expand Down
2 changes: 1 addition & 1 deletion Editor/Editor/SerializableDateTimeDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int DrawComponent(string componentLabel, int componentDigits, int componentValue
var second = DrawComponent("s", 2, dateTime.Second);
dateTime = new DateTime(year, month, day, hour, minute, second);
}
catch (Exception _)
catch
{
// ignored
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/Editor/SerializableTimeSpanDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ float DrawComponent(string componentLabel, int componentDigits, int componentVal
newTimeSpan += TimeSpan.FromSeconds(DrawComponent("s", 2, timeSpan.Seconds));
newTimeSpan += TimeSpan.FromMilliseconds(DrawComponent("ms", 3, timeSpan.Milliseconds));
}
catch (Exception e)
catch
{
// ignored
}
Expand Down
8 changes: 7 additions & 1 deletion Editor/Editor/Validation/ValidationTreeView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using PocketGems.Parameters.Editor.Validation.TreeDataModel.Editor;
using PocketGems.Parameters.Validation;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
Expand Down Expand Up @@ -134,7 +135,12 @@ void CellGUI(Rect cellRect, TreeViewItem<ValidationTreeElement> item, Columns co
case Columns.Icon:
{
if (!string.IsNullOrEmpty(item.data.ValidationError?.Message))
GUI.DrawTexture(cellRect, _errorIcon, ScaleMode.ScaleToFit);
{
var icon = _errorIcon;
if (item.data.ValidationError.ErrorSeverity == ValidationError.Severity.Warning)
icon = _warningIcon;
GUI.DrawTexture(cellRect, icon, ScaleMode.ScaleToFit);
}
}
break;
case Columns.PropertyName:
Expand Down
Loading
Loading