From 5acf9011ea0d2ea91f921637d6f835dc571fc446 Mon Sep 17 00:00:00 2001 From: Gabriel <34012267+HyperBE32@users.noreply.github.com> Date: Thu, 2 Nov 2023 00:00:03 +0000 Subject: [PATCH] Implemented category diff and object diff blocks --- .../HedgeModManager.CodeCompiler/CodeFile.cs | 4 ++-- Source/Libraries/HedgeModManager.Diagnostics/Diff.cs | 11 +++++++++++ .../HedgeModManager.Diagnostics/DiffBlock.cs | 11 +++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/Libraries/HedgeModManager.CodeCompiler/CodeFile.cs b/Source/Libraries/HedgeModManager.CodeCompiler/CodeFile.cs index 9403281..424c1d7 100644 --- a/Source/Libraries/HedgeModManager.CodeCompiler/CodeFile.cs +++ b/Source/Libraries/HedgeModManager.CodeCompiler/CodeFile.cs @@ -82,9 +82,9 @@ string GetCodeDiffName(CSharpCode code) // Renamed if (Codes.SingleOrDefault(x => x.Body == code.Body) is { } renamed) { - if (code.Name != renamed.Name) + if (code.Name != renamed.Name || code.Category != renamed.Category) { - diff.Renamed($"{GetCodeDiffName(code)} -> {GetCodeDiffName(renamed)}", code.Name, renamed.Name); + diff.Renamed($"{GetCodeDiffName(code)} -> {GetCodeDiffName(renamed)}", code, renamed); // Remove this code from the added list so we don't display it twice. if (addedCodes.SingleOrDefault(x => x.Name == renamed.Name) is { } duplicate) diff --git a/Source/Libraries/HedgeModManager.Diagnostics/Diff.cs b/Source/Libraries/HedgeModManager.Diagnostics/Diff.cs index 2aaa80b..55d9dec 100644 --- a/Source/Libraries/HedgeModManager.Diagnostics/Diff.cs +++ b/Source/Libraries/HedgeModManager.Diagnostics/Diff.cs @@ -25,6 +25,12 @@ public void MakeBlock(DiffType type, string? description, string dataKey, string mBlocks[(int)type].Add(new DiffBlock(type, description, dataKey, dataValue)); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void MakeBlock(DiffType type, string? description, object dataKey, object dataValue) + { + mBlocks[(int)type].Add(new DiffBlock(type, description, dataKey, dataValue)); + } + public void Add(DiffBlock block) { mBlocks[(int)block.Type].Add(block); @@ -50,6 +56,11 @@ public void Renamed(string? description, string oldName, string newName) MakeBlock(DiffType.Renamed, description, oldName, newName); } + public void Renamed(string? description, object oldData, object newData) + { + MakeBlock(DiffType.Renamed, description, oldData, newData); + } + public List ToList() { var list = new List(mBlocks.Sum(x => x.Count)); diff --git a/Source/Libraries/HedgeModManager.Diagnostics/DiffBlock.cs b/Source/Libraries/HedgeModManager.Diagnostics/DiffBlock.cs index b90afdc..9fffa4e 100644 --- a/Source/Libraries/HedgeModManager.Diagnostics/DiffBlock.cs +++ b/Source/Libraries/HedgeModManager.Diagnostics/DiffBlock.cs @@ -4,7 +4,7 @@ public class DiffBlock { public DiffType Type { get; set; } public string? Description { get; set; } - public KeyValuePair Data { get; set; } + public KeyValuePair Data { get; set; } public DiffBlock(DiffType type, string? description) { @@ -16,13 +16,16 @@ public DiffBlock(DiffType type, string? description, string dataKey) { Type = type; Description = description; - Data = new KeyValuePair(dataKey, string.Empty); + Data = new(dataKey, string.Empty); } - public DiffBlock(DiffType type, string? description, string dataKey, string dataValue) + public DiffBlock(DiffType type, string? description, object dataKey, object dataValue) { Type = type; Description = description; - Data = new KeyValuePair(dataKey, dataValue); + Data = new(dataKey, dataValue); } + + public DiffBlock(DiffType type, string? description, string dataKey, string dataValue) + : this(type, description, (object)dataKey, (object)dataValue) { } } \ No newline at end of file