141 lines
No EOL
5 KiB
C#
141 lines
No EOL
5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
|
|
namespace Module.ProjectValidator.Editor
|
|
{
|
|
internal sealed class Report
|
|
{
|
|
public static Report Active { get; private set; }
|
|
public static bool HasActive => Active != null;
|
|
|
|
public readonly List<Entry> Entries = new();
|
|
private readonly Dictionary<GUID, MappingEntry> _assetToSeverityMapping = new();
|
|
private readonly Dictionary<int, MappingEntry> _instanceToSeverityMapping = new();
|
|
|
|
public void Add(GUID assetGuid, string scenePath, string fieldPath, Attribute attribute, EValidatorSeverity severity, string message)
|
|
{
|
|
Entries.Add(new Entry
|
|
{
|
|
AssetGuid = assetGuid,
|
|
AssetName = EditorAssetUtility.GetAssetName(assetGuid),
|
|
ScenePath = scenePath,
|
|
FieldPath = fieldPath,
|
|
ScenePathRichText = ProjectValidatorUtility.ApplyRichTextToScenePath(scenePath),
|
|
FieldPathRichText = ProjectValidatorUtility.ApplyRichTextToFieldPath(fieldPath),
|
|
Type = ProjectValidatorUtility.GetAttributeShortName(attribute),
|
|
Severity = severity,
|
|
SeverityStr = severity.ToString(),
|
|
SeverityResult = message
|
|
});
|
|
|
|
if (_assetToSeverityMapping.TryGetValue(assetGuid, out var mapping))
|
|
{
|
|
if (mapping.Severity < severity)
|
|
_assetToSeverityMapping[assetGuid] = new MappingEntry(severity, false);
|
|
}
|
|
else
|
|
{
|
|
_assetToSeverityMapping.Add(assetGuid, new MappingEntry(severity, false));
|
|
}
|
|
}
|
|
|
|
public void RebuildAssetMapping()
|
|
{
|
|
ProjectValidatorUtility.RebuildAssetMapping(_assetToSeverityMapping);
|
|
}
|
|
|
|
public void RebuildInstanceMapping()
|
|
{
|
|
ProjectValidatorUtility.RebuildSceneInstanceMapping(this, _instanceToSeverityMapping);
|
|
}
|
|
|
|
public bool TryGetSeverityFor(string guid, out MappingEntry mapping)
|
|
{
|
|
if (GUID.TryParse(guid, out var assetGuid) && _assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
|
return true;
|
|
|
|
mapping = new MappingEntry();
|
|
return false;
|
|
}
|
|
|
|
public bool TryGetSeverityFor(int instanceId, out MappingEntry mapping)
|
|
{
|
|
if (_instanceToSeverityMapping.TryGetValue(instanceId, out mapping))
|
|
return true;
|
|
|
|
mapping = new MappingEntry();
|
|
return false;
|
|
}
|
|
|
|
public bool TryGetSeverityFor(GUID assetGuid, string scenePath, out MappingEntry mapping)
|
|
{
|
|
if (!_assetToSeverityMapping.TryGetValue(assetGuid, out mapping))
|
|
return false;
|
|
|
|
mapping = new MappingEntry();
|
|
|
|
for (var i = 0; i < Entries.Count; i++)
|
|
{
|
|
if (Entries[i].AssetGuid != assetGuid || Entries[i].ScenePath != scenePath || Entries[i].Severity <= mapping.Severity)
|
|
continue;
|
|
|
|
mapping = new MappingEntry(Entries[i].Severity, false);
|
|
|
|
if (mapping.Severity == EValidatorSeverity.MaxSeverityLevel)
|
|
break;
|
|
}
|
|
|
|
return mapping.Severity != EValidatorSeverity.Valid;
|
|
}
|
|
|
|
public void SetAsActive()
|
|
{
|
|
Active = this;
|
|
}
|
|
|
|
public static void ClearActive()
|
|
{
|
|
Active = null;
|
|
}
|
|
|
|
public struct Entry
|
|
{
|
|
public GUID AssetGuid;
|
|
public string AssetName;
|
|
|
|
public string ScenePath;
|
|
public string FieldPath;
|
|
|
|
public string ScenePathRichText;
|
|
public string FieldPathRichText;
|
|
|
|
public string Type;
|
|
public EValidatorSeverity Severity;
|
|
public string SeverityStr;
|
|
public string SeverityResult;
|
|
|
|
public bool Filter(string filter)
|
|
{
|
|
return AssetName.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
|
ScenePath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
|
FieldPath.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
|
Type.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
|
SeverityResult.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ||
|
|
SeverityStr.Contains(filter, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
}
|
|
|
|
public struct MappingEntry
|
|
{
|
|
public readonly EValidatorSeverity Severity;
|
|
public readonly bool IsRedirect;
|
|
|
|
public MappingEntry(EValidatorSeverity severity, bool isRedirect)
|
|
{
|
|
Severity = severity;
|
|
IsRedirect = isRedirect;
|
|
}
|
|
}
|
|
}
|
|
} |